bgmulinari / B1SLayer

A lightweight SAP Business One Service Layer client for .NET
MIT License
136 stars 47 forks source link

I am having problems with PostBatchAsync batch updates: should be two '\r\n' between sub-request #68

Closed ByYogi closed 3 months ago

ByYogi commented 5 months ago

"Incomplete request, Please check if the sub-request has complete request content and there should be two '\r\n' between sub-request header and content!"

using B1SLayer;
var serviceLayer = new SLConnection("https://***:10000/b1s/v2", "***", "***", "***");

List<SLBatchRequest> batchReq = new List<SLBatchRequest>();

batchReq.Add(new SLBatchRequest(new HttpMethod("Patch"), $"Items('{"$creation"}')", new
{
    ItemCode = "$creation",
    ItemName = "Test Item1"
})); batchReq.Add(new SLBatchRequest(new HttpMethod("Patch"), $"Items('{"$creation2"}')", new
{
    ItemCode = "$creation2",
    ItemName = "Test Item2"
}));
HttpResponseMessage[] batchResult = await serviceLayer.PostBatchAsync(batchReq);
ByYogi commented 5 months ago

I also get an error when I use the README example.

B1SLayer.SLException: 'Content ID should be specified in each change set request.'

image image

bgmulinari commented 5 months ago

Hi, @ByYogi.

When using OData V4 protocol (indicated by the 'v2' in your Service Layer URL), you are required to specify the content ID in all requests within a batch, even if you don't use it. Check the Service Layer User Manual regarding this topic.

Try changing your URL to 'v1' or specify the content ID in each request object (optional constructor parameter for the SLBatchRequest class).