A number of Erply API calls have an input parameter “changedSince”.
You can use this parameter to synchronize data to another application – by only fetching data that has been added, changed or deleted.
Here is an example walkthrough for products. Other kinds of items (customers, sales documents, gift cards, etc.) can be synchronized in a similar manner.
Download the full product list with getProducts. This can take time, and usually requires multiple calls, since API returns a fixed number of items at a time.
recordsOnPage=1000
and download the data in “pages”: pageNo=1
for the first call, pageNo=2
for the second, and so on.orderBy=productID
. This ensures that the order stays consistent for the duration of the sync, and if new products are created meanwhile, they will appear at the end of the list.API has an hourly request limit of 3000 calls. If you have a lot of products (hundreds of thousands), you might not be able to download the whole list in one hour. API will start returning error code 1002 once the limit has been reached. Your script should be able to detect that case, inform the operator, and save its progress so that work could be resumed next hour.
For an advanced optimization, you may utilize bulk calls, which allows to download data at 10x regular rate.
"requestUnixTime"
— a timestamp. Take note of the value that server returned when you issued your FIRST getProducts call. If synchronization completes successfully, keep that value. This is the time when last successful synchronization was started.To bring your local database up to date, you need to retrieve items that have been added, changed, and deleted meanwhile. These are the steps; you can set the script to run at regular intervals.
To retrieve added and changed items, call getProducts and send the last synchronization timestamp as input parameter "changedSince"
. API returns items that have been added or changed since that moment of time. Number of returned items may exceed 1000, so be ready to use paging if necessary (see step 1 in previous section).
When issuing the FIRST getProducts call, take again note of the "requestUnixTime"
timestamp in response header, and set it aside.
For each item that getProducts returns, check if you already have an item with that ID in your local database. If yes, update it. If not, add it as a new item.
To retrieve DELETED products, use API call getUserOperationsLog, with the following parameters:
tableName=products
addedFrom=<last synchronization timestamp>
API returns a list of product IDs (field "itemID"
). Delete all these items from your local database.
Use only server’s timestamps — the ones returned in every response header (field "requestUnixTime"
). Your clock may be different from server clock, so if you stamp the synchronization with a locally generated timestamp, you’ll risk missing some updates.