Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

Web api odata batch request

Posted on by Microsoft Employee

I'm trying to create a batch request to insert 2 records using POSTMAN but I got an error.

"Multiple requests within the same changeset are not supported by Microsoft Dynamics NAV OData web services"

here my request body

--batch_AAA123  
Content-Type: multipart/mixed;boundary=changeset_BBB456

--changeset_BBB456  
Content-Type:application/http
Content-Transfer-Encoding:binary
Content-ID:1

POST 192.200.10.73/.../Company('CRONUS%20International%20Ltd.')/OrderMaster HTTP/1.1
Content-Type:application/json;type=entry

{
	"order_num": "COIY5",
	"user_id": "yudi",
	"order_date": "2018-08-06T17:00:00Z",
	"tax_amt": 12,
	"total_amt": 120,
	"balance_amt": 132,
	"posted": false
}
--changeset_BBB456  
Content-Type:application/http
Content-Transfer-Encoding:binary
Content-ID:2

POST 192.200.10.73/.../Company('CRONUS%20International%20Ltd.')/OrderMaster HTTP/1.1
Content-Type:application/json;type=entry

{
	"order_num": "COIY4",
	"user_id": "yudi",
	"order_date": "2018-08-06T17:00:00Z",
	"tax_amt": 12,
	"total_amt": 120,
	"balance_amt": 132,
	"posted": false
}

--changeset_BBB456--
--batch_AAA123--


if I just create 1 record, the request is successful.

is it a bug or just NAV limitation?

*This post is locked for comments

  • Maya09 Profile Picture
    Maya09 5 on at
    RE: Web api odata batch request

    sorry, but can you give detailed instructions on how to get the path and post odata batch request. I'm looking to do it but don't know where to start and have no experience with the api, thank you very much.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Web api odata batch request

    hi Yudi,

    Maybe you could do something similar as using a "Journal"?

    First you write all your data via OData into the Journal table, and if everything goes well, you call a Page Action, which posts those Journal entries to the final table. If there is an error, delete the entries from the Journal table and try again..

    Another idea could be, that you pass your data to a page Action an do every insert in the page then, like

    docs.microsoft.com/.../walkthrough-creating-and-interacting-odata-v4-bound-action

    What Version are you using anyway? Nav2018 with API Pages?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Web api odata batch request

    hi Andreas,

    Thanks for your suggestion, I already try your solution but with your workaround, I lost 1 benefit, which is if one post request fails then the previous post request still saved.

    I want if one request fails then it must rollback all previous request.  as far as I know, this is can only achieve if we use one changeset.

    do you have any thought about this matter?

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Web api odata batch request

    Hi,

    maybe try using another changeset id for the second post request and it should work.oO(or at least it did so for me).


    Best regards,

    Andreas

    P.S.: I am working on Dynamics NAV 2018, API Pages and ODataV4

    --batch_ec2461be-c322-b0c3-d945-ea852ccf9bf4
    Content-Type: application/http Content-Transfer-Encoding:binary
    GET companies(815de58c-b098-40f5-8354-05c27b1e2190)/companyInformation HTTP/1.1 Content-Type: application/json; charset=utf-8 Accept: application/json --batch_ec2461be-c322-b0c3-d945-ea852ccf9bf4 Content-Type: multipart/mixed; boundary=changeset_04f0810b-7b0c-33c5-a210-02a6add6d029 --changeset_04f0810b-7b0c-33c5-a210-02a6add6d029 Content-Type: application/http Content-Transfer-Encoding:binary Content-ID: 0
    POST companies(815de58c-b098-40f5-8354-05c27b1e2190)/jobProcessFlows HTTP/1.1 Content-Type: application/json; charset=utf-8 Accept: application/json
    {"No":"AB1"} --changeset_04f0810b-7b0c-33c5-a210-02a6add6d029-- --batch_ec2461be-c322-b0c3-d945-ea852ccf9bf4 Content-Type: multipart/mixed; boundary=changeset_a0e0a09a-b4b2-fdb9-bbf9-a9b0ea0255d6
    --changeset_a0e0a09a-b4b2-fdb9-bbf9-a9b0ea0255d6 Content-Type: application/http Content-Transfer-Encoding:binary Content-ID: 0
    POST companies(815de58c-b098-40f5-8354-05c27b1e2190)/jobProcessFlows HTTP/1.1 Content-Type: application/json; charset=utf-8 Accept: application/json
    {"No":"AB2"} --changeset_a0e0a09a-b4b2-fdb9-bbf9-a9b0ea0255d6-- --batch_ec2461be-c322-b0c3-d945-ea852ccf9bf4--


    response was:

    18_2D00_03_2D00_2019-19_2D00_47_2D00_21.png
  • Stefano Demiliani Profile Picture
    Stefano Demiliani 37,162 Most Valuable Professional on at
    RE: Web api odata batch request

    Normally you need to pass an array of JSON objects in the body of your request, but it's something that must be supported by your API.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Web api odata batch request

    Hi Stefano, thanks for your reply, do you have any workaround to create multiple post request in one call. Since this is common things in odata Web api.

  • Suggested answer
    Stefano Demiliani Profile Picture
    Stefano Demiliani 37,162 Most Valuable Professional on at
    RE: Web api odata batch request

    Yes this is not supported.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans