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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s