Delta Tokens and Deep Inserts: a smart way to use API/ODATA … A real case with Shopify and Business Central (part 1)

SCENARIO

  • I have to implement a bi-directional sync between Business Central ERP and Shopify.
  • The sync has to be a scheduled one, not a real time one, and I have to optimise as much as I can to save API requests. The solution has to work on SaaS and I expect to have many requests to handle from both sides.

CREDITS 🙂

Just while I was getting depressed because I was finding no solutions, an online API course from Arend Jan Kauffmann showed as the icing on the cake and made me discover an unbelievable feature of API: the deltaLink and the deep inserts.

WHAT ARE ODATA DELTA LINKS AND WHY I USED THEM

The annoying thing about Business Central API is the current API usage limit.

When working in production environment the Http Error “429 Too Many Requests” was starting to be my nightmare. When dealing with synchronisation procedures this limit is a persistent problem.

Delta Links is a way to get deltas from a specific table. Basically when you get records you need to save a “delta link”, this delta link allows to retrieve only records that have been modified since previous requests.

First of all I created my custom API and I enable delta : ChangeTrackingAllowed = true;

This allows me to make a request with odata.track-changes http parameters.

All the magic is in the “@odata.deltaLink” URL.

Let’s supposed, after this initial request, I insert an item, update another one and delete the third. When calling again the provided odata.deltaLink I am going to get only the deltas as in picture:

Something really important is the delta links are “one time links”, it means that they allow one single requests and, after the request is served, they expire and you get a “410 Error Gone”. This means that sync mechanist must be implemented as “state of art” because if miss a request then the procedure has to reset from the initial request.

This is the way a deleted record is returned:

I just had to take to care about the way the insert action is managed in business central: it generates two events: an initial insert event and followed by an update event. This is by design.

GITHUB SOURCES

https://github.com/avalonit/ExBcCloudFiles

DELTA LINKS

https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-connect-apps-delta

https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/properties/devenv-changetrackingallowed-property

DEEP INSERTS IN BUSINESS CENTRAL

https://www.kauffmann.nl/2020/05/05/deep-insert-with-business-central-apis/

https://www.olisterr.tech/2019/05/creating-apis-in-business-central-1.html

COMING SOON

In next article I will cover how to manage deep inserts and save API requests for SaaS.

LAST UPDATED

1st of June, 2020

4 thoughts on “Delta Tokens and Deep Inserts: a smart way to use API/ODATA … A real case with Shopify and Business Central (part 1)

  1. Hello,
    first of all – great article. It’s really hard to find any information about delta links.

    I tried to work with delta links with your guide and faced some problem (error below). Got same result even when copied code from attached git link. Is there any additional setting required to work with Delta links? On service side i turned on everything that is under “OData Sevices” tab.
    Thanks for any answers.

    {
    “error”: {
    “code”: “BadRequest”,
    “message”: “Entity {0}({1}) does not support delta requests. CorrelationId: 79f8a952-99dc-42c5-bc71-faa6de52bfa0.”
    }
    }

    Like

  2. Hi,
    I have followed all steps and finally, I am able to generate deltalink but when I do insert , delete and modify then on next subsequent request ,I am not able to get delete and modify entries as /$deletedEntity

    So , is there any additional setting and configuration needs to be done and how can I fix this? Could you please help here

    Like

Leave a comment