Got inspired by this topic , I’d like to write this article to show you how to post multiple records in single transaction 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 transaction 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
2019-10-15-Insert-multiple-records-in-single-request-using-Odata-from-Postman_1.png
2019-10-15-Insert-multiple-records-in-single-request-using-Odata-from-Postman_2.png
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
2019-10-15-Insert-multiple-records-in-single-request-using-Odata-from-Postman_3.png
Full text here
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
--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
2019-10-15-Insert-multiple-records-in-single-request-using-Odata-from-Postman_4.png
Full Response
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
--batchresponse_ 45e87829 -5 a 26 -480e-8 aaa -8 a 08 c 7 a 82 c 60
Content-Type: multipart/mixed; boundary=changesetresponse_ 27 ed 7621 -d 939-40 b 7-9 f 8 b-be 0421 ff 0 cea
--changesetresponse_ 27 ed 7621 -d 939-40 b 7-9 f 8 b-be 0421 ff 0 cea
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_ 27 ed 7621 -d 939-40 b 7-9 f 8 b-be 0421 ff 0 cea--
--batchresponse_ 45e87829 -5 a 26 -480e-8 aaa -8 a 08 c 7 a 82 c 60
Content-Type: multipart/mixed; boundary=changesetresponse_ 541 a 7 d 21 -af 21-4 d 66 -b 410 -fb 4165599 b 54
--changesetresponse_ 541 a 7 d 21 -af 21-4 d 66 -b 410 -fb 4165599 b 54
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_ 541 a 7 d 21 -af 21-4 d 66 -b 410 -fb 4165599 b 54 --
--batchresponse_ 45e87829 -5 a 26 -480e-8 aaa -8 a 08 c 7 a 82 c 60 --
Check the data in Dynamics 365 for finance and operations
2019-10-15-Insert-multiple-records-in-single-request-using-Odata-from-Postman_5.png
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.