Efficient data caching/syncing can be a major challenge during application development, especially when you need to consider the balance between a Developer Key limits and data accuracy.
When you make a GET request to the AccountRight API, HTTP response headers get returned along with other information by the MYOB server.
This article offers some data syncing tips with aid for HTTP response headers in below major areas:
1. Account and Inventory
2. Individual Contact
1. Account and Inventory
Account and inventory are common areas or features consumed by the AccountRight API integrated applications and might need frequent data synchronisation for reasons. In order to cache account and/or inventory information you would perform a GET request to the below endpoint(s):
Account: /{cf_uri}/GeneralLedger/Account
Inventory: /{cf_uri}/Inventory/Item
Your application needs to re-fetch the same endpoints to check if any information had been updated based on the cached data. The simplest way to check this is to store the Etag response header.
ETag is returned across all our endpoints as a port of HTTP response headers that helps to identify the current version of the called endpoint/resource. In conjunction with If-None-Match, check if a collection list or individual resource has changed.
Example
During your first GET request to the domain/{guid}/GeneralLedger/Account endpoint, store the Etag response header.
< HTTP/1.1 200 OK
< Cache-Control: must-revalidate, private
< Content-Type: application/json; charset=utf-8
< Date: Tue, 30 Jun 2020 01:19:20 GMT
< ETag: "-1025683488"
< Expires: -1
< Server: Microsoft-IIS/10.0
< X-AspNet-Version: 4.0.30319
< X-Mashery-Message-ID: 6xxxxxx6-cxx1-4xxd-bxxf-0xxxxxxxxd
< X-Mashery-Responder: prod-j-worker-ap-southeast-2b-33.mashery.com
< x-myobapi-elapsed: 2070
< x-myobapi-requestid: 7xxxxx9-5xxa-4xx6-axxb-4xxxxxxx6
< X-Powered-By: ASP.NET
< Content-Length: 199205
< Connection: keep-alive
Upon scheduled synchronisation, call the same endpoint with an additional request header:
If-None-Match:"-1025683488"
304 Not Modified response code will be returned if the collection or individual resource hasn't been modified based on the request, 200 OK response code will be returned if the resource has been modified. This means you will only need to sync data if 200 OK response code is returned.
2. Individual Contact
Contact is another common area that may require a frequent synchronisation to reconcile balances due to creation of an invoice, a bill or even a payment against an invoice or a bill. In order to cache individual contact information you would perform a GET request to the below endpoint(s):
Customer: /{cf_uri}/Contact/Customer/{uid}
Supplier: /{cf_uri}/Contact/Supplier/{uid}
Employee: /{cf_uri}/Contact/Employee/{uid}
Your application needs to re-fetch the same endpoints to check if any information had been updated based on the cached data. In conjunction with If-Modified-Since, check if the request individual contact recourse has been modified since the time specified in the field.
(Note If-None-Match and Etag validation are also supported.)
Example
During your first GET request to the /{cf_uri}/Contact/Customer/{uid} endpoint, store the Date response header.
< HTTP/1.1 200 OK
< Cache-Control: must-revalidate, private
< Content-Type: application/json; charset=utf-8
< Date: Tue, 30 Jun 2020 22:00:00 GMT
< ETag: "1744497367"
< Expires: -1
< Last-Modified: Sun, 14 Jun 2020 23:56:06 GMT
< Server: Microsoft-IIS/10.0
< X-AspNet-Version: 4.0.30319
< X-Mashery-Message-ID: cxxxxxx1-1xxd-4xxe-9xx8-2xxxxxxxxxx0
< X-Mashery-Responder: prod-j-worker-ap-southeast-2a-34.mashery.com
< x-myobapi-elapsed: 1644
< x-myobapi-requestid: 7xxxxxf-4xx7-4xx1-8xx6-5xxxxxxxxxxa
< X-Powered-By: ASP.NET
< Content-Length: 2697
< Connection: keep-alive
Upon scheduled synchronisation, call the same endpoint with an additional request header:
If-Modified-Since: Wed, 01 Jul 2020 22:00:00 GMT
304 Not Modified response code will be returned if the individual resource hasn't been modified based on the request, 200 OK response code will be returned if the resource has been modified. This means you will only need to sync data if 200 OK response code is returned.
Comments
0 comments
Article is closed for comments.