Skip to Content

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,


Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Jan 05, 2015 at 04:27 PM

    We also had issues posting batch in SPS07 (rev 74) on AWS.  We couldn't pinpoint the source of the error, but when we moved up to SPS08 - rev 80, the same code that failed in SPS07 worked in SPS08.  We lost over 3 weeks of multiple developers debugging on SPS07.  It seemed that there was some error in the server for the batch processing and odata in SPS07, 

    If possible, try to update your system if possible.  I don't know if there is a patch on Service Marketplace for the problem or not. 

    Jim Giffin

    Add comment
    10|10000 characters needed characters exceeded

    • Thank you for your answer Jim. I will do as you suggest and try to move up to SPS08, but dont know if this is possible yet as B1 Hana needs to support that;

      Coming from a different background (java developement/ web developement) I somehow don't really like some of the XSJS api's as they "fiddle too much in the dark" IMHO, meaning they aren't as exposed as e.g. the JDK is in terms of background processing. I especially dont see the reason why the $.net.http.Request.setBody() cant take RAW input and process it but instead seems to "work" with it...

      However, some statement from an SAP employee on the issue would be really nice.