D365FO: OData requests in batch
People who are familiar with performing D365FO OData requests, must be know about that you need to make a single web service call for one operation. The number of calls increases as the business process goes complex.
There are generally three factors which requires these web services to be called in batch mode
1. Reduce the chatter between source and D365FO. There is a threshold of these web-service call.
2. Logical merging of calls - It is logical for maintenance purpose to have all web services call related to one process inside single code/script
3. Transactional control - It may be required in some cases that the calls works as an atomic transactional unit (like ttsbegin/ttscommit in X++)
The batch related calling rules and syntax is defined in open.org OData protocol and implemented by D365FO.
There are three important concepts to consider - batch, changeset and content-id.
Batch is a specific string (generally including GUID to avoid conflict) that is defined at the header level where we tell the service the start and end of multi-part web request.
Similar to batch, Changeset is another string which is used within a batch to represent an atomic transaction. A batch may contain multiple changesets.
Content-ID is a string which defines a single web service call within a changeset.
Batch and Changeset starts are marked with double hyphen (--) mark in start and ends are marked with double hyphen (--) in the start and end both.
Postman is an excellent tool to create and test these requests. Here is one example in which I have created a new product, released it to company and created sales order in one single batch and changeset.
--batch1_03012025T134609
Content-Type: multipart/mixed; boundary=changeset1_03012025T134609
--changeset1_03012025T134609
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-ID: 1
POST /data/ReleasedProductCreationsV2 HTTP/1.1
OData-Version: 4.0
OData-MaxVersion: 4.0
Content-Type: application/json;odata.metadata=minimal
Accept: application/json;odata.metadata=minimal
Accept-Charset: UTF-8
User-Agent: Microsoft.OData.Client/7.5.4
Authorization: Bearer <Paste token here>
{
"dataAreaId": "USMF",
"ProductNumber":"USMF_104",
"ItemNumber":"USMF_104",
"ProductDescription":null,
"ProductName":"ECU COO test",
"ProductSearchName":null,
"ProductType": "Service"
}
--changeset1_03012025T134609
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-ID: 2
POST /data/SCASalesOrderHeadersV2 HTTP/1.1
OData-Version: 4.0
OData-MaxVersion: 4.0
Content-Type: application/json;odata.metadata=minimal
Accept: application/json;odata.metadata=minimal
Accept-Charset: UTF-8
User-Agent: Microsoft.OData.Client/7.5.4
Authorization: Bearer <Paste token here>
{
"dataAreaId": "USMF",
"CurrencyCode":"USD",
"LanguageId":"dn-US",
...bla bla bla...
}
--changeset1_03012025T134609--
--batch1_03012025T134609--
Comments
Post a Comment