Options

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

daansdaans Member Posts: 21

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":""
      }
   ]
}

Sign In or Register to comment.