Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

XSJS Batch Post for OData


I'm currently working with B1 Version for HANA and try to do a post to the OData Service Layer of Business One from XSJS of Hana. So far it works for regular, single entity Post e.g.:


* Logon to B1SL


var b1slDestination = $.net.http.readDestination("test.Connector.imex", "b1sl");

var client = new $.net.http.Client();

var request = new $.net.http.Request($.net.http.POST, "/Login");

request.setBody('{"CompanyDB": "SBODEMODE", "UserName": "manager", "Password": "1234"}');

var response = client.request(request, b1slDestination).getResponse();

var logonObject = JSON.parse(response.body.asString());

var sessionId = logonObject.SessionId;

So, above I issue a POST to the Login of the Business One Service Layer of a demo DB from 9.1; I can then do queries against it just fine, like doing a single insert.

When I however want to issue an Batch-Post I suddenly hit a wall. Code is similar to this (note: I stripped down this to just 1 operation till it works), e.g.:


* Batch Test


var batchId = "batch_36522ad7";

var changesetId = "changeset_1a5324";

var batchRequest = new $.net.http.Request($.net.http.POST, "/$batch");

batchRequest.contentType = "multipart/mixed; boundary="+ batchId  +" ";

batchRequest.cookies.set('B1SESSION', sessionId);

var b2 = "--batch_36522ad7 \r\n" +

    "Content-Type: multipart/mixed; boundary=changeset_1a53241  \r\n" +

    " \r\n" +

    "--changeset_1a53241  \r\n" +

    "Content-Type: application/http  \r\n" +

    "Content-Transfer-Encoding: binary  \r\n" +

    "POST /b1s/v1/Banks HTTP/1.1  \r\n" +

    "Content-Type: application/json  \r\n" +

    "Content-Length:22  \r\n" +

    " \r\n" +

    '{"BankCode": "900001"} ' + "\r\n" +

    " \r\n" +

    "--changeset_1a53241--  \r\n" +

    " \r\n" +

    "--batch_36522ad7-- ";


var response = client.request(batchRequest, b1slDestination).getResponse();

Instead of any useful things I allways get:


  "error" : {
  "code" : -1000,
  "message" : {
  "lang" : "en-us",
  "value" : "Incomplete Batch Request Body!"

The above code should instead insert a simple Banks - entity into Business One via the Odata Service Layer. The code it produces fits the OData spec and it works if I poste the exact same data via Chrome/ Postman e.g.:

POST: /b1s/v1/$batch

Header: Content-Type: multipart/mixed; boundary=batch_36522ad7


Content-Type: multipart/mixed; boundary=changeset_1a53241


Content-Type: application/http

Content-Transfer-Encoding: binary

POST /b1s/v1/Banks HTTP/1.1

Content-Type: application/json


{"BankCode": "9000010"}



the result then is:






HTTP/1.1 201 Created





   "odata.metadata" : "$metadata#Banks/@Element",

   "BankCode" : "9000010",

   "BankName" : null,

   "AccountforOutgoingChecks" : null,

   "BranchforOutgoingChecks" : null,

   "NextCheckNumber" : null,

   "SwiftNo" : null,

   "IBAN" : null,

   "CountryCode" : "DE",

   "PostOffice" : "tNO",

   "AbsoluteEntry" : "4315",

   "DefaultBankAccountKey" : null




Seeing a now successful insert;

So, I'm rather irritated what the difference in the above code is in comparision to the manual issued post. I tried to change the line carriages to different types, but there were no differences at all (so "\n" is as good as "\r\n"); Also I somehow suspect the XSJS  $.net.http.Request.setBody() method to maybe fiddle with the content, but I were unable to trace it any further as even the debugger held nearly no useful info for the Request object as it referes to 2 layers of proto's in the debug perspective;

Used Version of HANA is SPS07, B1 9.1 PL02;

Any help upon that matter would be reall appreciated.

Best Regards,



Helpful Answer

Not what you were looking for? View more on this topic or Ask a question