web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Dynamics 365 Business Central API's - PUT/PATCH Header with Detail Lines

(0) ShareShare
ReportReport
Posted on by 5

Hi,

We're currently writing an integration to synchronize Orders and Order Lines between 2 Business Central databases using API's. (Note: we're talking about a custom Order/Order Line implementation, but it's quite similar to a standard Sales Order)

At this point I'm able to create a new Order with Lines using a single http POST call.

In some cases our integration requires an update of the Order and its lines. These are the steps we're trying to perform to achieve this

  • STEP 1:Delete the existing Order Lines using a Bound Action of the Order Entity API
  • STEP 2: Update the Order and the Lines using a PUT (or PATCH) http call using the eTag of the Order (See request below)

We're noticing that only the Order is updated in STEP 2, the Order Lines remain untouched (even if STEP 1 is skipped). This seems somewhat logic since Order and Order Lines have a different eTag and the eTag is used to determine if the record was already updated or not.

Is there a way to update an Order and add Order Lines in a single API call? In our case, an Order can contain quite some Order Lines. This will result - in case of an update - in a huge amount of API calls.

PUT http://mydomain.com/orders('myorderno') HTTP/1.1
Authorization: Basic eW91bmdwYXJ0bmVyc1xkc2FuOkF6ZXJ0eTEyMzQh
Accept: */*
Cache-Control: no-cache
If-Match: W/"JzQ0OzRHU3plSVV0V2p0Y2pBeW1nUnJFeDFiaUtPQUZXR0Z6cEYvZHNPWDl0cTA9MTswMDsn"
Content-Type: application/json
Host: mydomain:7058
Content-Length: 553
Expect: 100-continue

{ 
"externalOrderType":"",
"externalOrderCode":"TTR-9001136|10000|30000",
"orderType":"Out",
"orderDate":"2019-11-01",
"terminal":"ADR-0005862",
"principalCode":"",
"principalReference":"TTR-9001136",
"vehicleCode":"",
"trailerCode":"",
"driverCode":"",
"subcontractorCode":"",
"subcontractorName":"",
"enforceLoadSequence":false,
"orderLines":[ 
{ 
orderNo:"myorderno",
orderLineNo:0,
"orderDate":"2019-11-01",
"externalParcelCode":"14575-0001",
"externalReference":"test parcels",
"agentCode":""
},
{ 
orderNo:"myorderno",
orderLineNo:0,
"orderDate":"2019-11-01",
"externalParcelCode":"14575-0002",
"externalReference":"test parcels",
"agentCode":""
}
]
}

I have the same question (0)
  • Suggested answer
    Olister Rumao Profile Picture
    3,967 on at

    Hi,

    AFAIK, Patch method is not allowed for API is BC.

    Although BC supports PUT method to update the lines provided you filter the record correctly and then update them.

    And I don't think BC supports passing Header and Lines in a single call. You will need to put appropriate  in the URL for parent child relation.

    Refer my blog 

    https://www.olisterr.tech/2019/09/understanding-apis-in-business-central.html

    For Delete operation, you can just use the DELETE method on header and BC will take care of deleting the lines.

  • Suggested answer
    Daan S Profile Picture
    5 on at

    This was indeed the answer I was expecting. There's no other way than to update each line seperately. Thank you very much for the answer!

  • Marc G. Profile Picture
    895 on at

    Hi Daan,

    In your question you mention: "At this point I'm able to create a new Order with Lines using a single http POST call.". Can you let me know how you've handled this? I keep having the BC saying I need to provide the Document Type and Document No with the Sales Line.

  • Daan S Profile Picture
    5 on at

    Hi,

    I had the exact same problem.

    I have an API page Orders containing a subpage for the Lines

    What I did was use the OnInsertRecord trigger on the Order page to manually trigger an insert(true) followed by an exit(false).

    I wrote this a while ago and I'm not 100% sure I did anything else to get it working. I'll try to create a sample.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,468

#2
YUN ZHU Profile Picture

YUN ZHU 923 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 607

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans