Insert multiple records in a single transaction using Odata from Postman
Got inspired by this topic, I'd like to write this article to show you how to post multiple records in single request by using Postman.
Generally, batch requests are supported in the OData service, The easiest way is you can use the C# code approach from github and the excel add-ins in Dynamics 365 for finance and operations use Odata batch to communicate in a single request but how can we leverage it in Postman.
Using Excel add-in then add 2 customer groups records and submit to Dynamics 365 for finance and operations, while you are doing that using fiddler on the same box to see how the odata batch framework works. This can be done from POSTMAN too and you need to use header and body as you see in Fiddler.
For basic setting up Dynamics 365 for finance and operations and Postman please follow this offical document
1. Get Dynamics 365 for finance and operations authorization
This is a result
2. Create a new POST request in Postman with header
URL: {{resource}}/data/$batch*
Content-Type: multipart/mixed;boundary=batch_d63a-e9be-2927
3. Modify the Body in Postman
I will place 2 records for customer groups
Full text here
--batch_d63a-e9be-2927
Content-Type: multipart/mixed; boundary=changeset_2499-90ab-7b93
--changeset_2499-90ab-7b93
Content-Type: application/http
Content-Transfer-Encoding: binary
POST CustomerGroups?cross-company=true HTTP/1.1
Content-ID: 1
Accept: application/json;q=0.9, */*;q=0.1
OData-Version: 4.0
Content-Type: application/json
OData-MaxVersion: 4.0
{"CustomerGroupId":"1060","Description":"Wholesales customers","PaymentTermId":"Net30","IsSalesTaxIncludedInPrice":"No","dataAreaId":"usmf"}
--changeset_2499-90ab-7b93--
--batch_d63a-e9be-2927
Content-Type: multipart/mixed; boundary=changeset_b573-33b2-85ff
--changeset_b573-33b2-85ff
Content-Type: application/http
Content-Transfer-Encoding: binary
POST CustomerGroups?cross-company=true HTTP/1.1
Content-ID: 2
Accept: application/json;q=0.9, */*;q=0.1
OData-Version: 4.0
Content-Type: application/json
OData-MaxVersion: 4.0
{"CustomerGroupId":"1070","Description":"Wholesales customers1","PaymentTermId":"Net30","IsSalesTaxIncludedInPrice":"No","dataAreaId":"usmf"}
--changeset_b573-33b2-85ff--
Click send and this is what you got from response
Full Response
--batchresponse_45e87829-5a26-480e-8aaa-8a08c7a82c60
Content-Type: multipart/mixed; boundary=changesetresponse_27ed7621-d939-40b7-9f8b-be0421ff0cea
--changesetresponse_27ed7621-d939-40b7-9f8b-be0421ff0cea
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-ID: 1
HTTP/1.1 201 Created
ETag: W/"JzEsNjg3MTk0Nzk4MzUn"
Location: https: //fodevb2819a3b6966913ddevaos.cloudax.dynamics.com/data/CustomerGroups(dataAreaId='usmf',CustomerGroupId='1060')
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
{
"@odata.context": "https://fodevb2819a3b6966913ddevaos.cloudax.dynamics.com/data/$metadata#CustomerGroups/$entity",
"@odata.etag": "W/\"JzEsNjg3MTk0Nzk4MzUn\"",
"dataAreaId": "usmf",
"CustomerGroupId": "1060",
"ClearingPeriodPaymentTermName": "",
"DefaultDimensionDisplayValue": "",
"CustomerAccountNumberSequence": "",
"IsSalesTaxIncludedInPrice": "No",
"Description": "Wholesales customers",
"WriteOffReason": "",
"PaymentTermId": "Net30",
"TaxGroupId": ""
}
--changesetresponse_27ed7621-d939-40b7-9f8b-be0421ff0cea--
--batchresponse_45e87829-5a26-480e-8aaa-8a08c7a82c60
Content-Type: multipart/mixed; boundary=changesetresponse_541a7d21-af21-4d66-b410-fb4165599b54
--changesetresponse_541a7d21-af21-4d66-b410-fb4165599b54
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-ID: 2
HTTP/1.1 201 Created
ETag: W/"JzEsNjg3MTk0Nzk4MzYn"
Location: https: //fodevb2819a3b6966913ddevaos.cloudax.dynamics.com/data/CustomerGroups(dataAreaId='usmf',CustomerGroupId='1070')
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
{
"@odata.context": "https://fodevb2819a3b6966913ddevaos.cloudax.dynamics.com/data/$metadata#CustomerGroups/$entity",
"@odata.etag": "W/\"JzEsNjg3MTk0Nzk4MzYn\"",
"dataAreaId": "usmf",
"CustomerGroupId": "1070",
"ClearingPeriodPaymentTermName": "",
"DefaultDimensionDisplayValue": "",
"CustomerAccountNumberSequence": "",
"IsSalesTaxIncludedInPrice": "No",
"Description": "Wholesales customers1",
"WriteOffReason": "",
"PaymentTermId": "Net30",
"TaxGroupId": ""
}
--changesetresponse_541a7d21-af21-4d66-b410-fb4165599b54--
--batchresponse_45e87829-5a26-480e-8aaa-8a08c7a82c60--
Check the data in Dynamics 365 for finance and operations
Note: refer this article for an C# example: https://learn.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/data-entities/odata#run-multiple-requests-in-a-single-transaction
Thank you for reading.