The Sync API allows you to keep a local copy of all content of a space up-to-date via delta updates.
Synchronizing content greatly improves the user experience of applications. Mobile data connections can be slow and have a very high latency compared to broadband internet connections. When apps sync content to the device and access it from a local database (e.g. Core Data, LocalStorage, SQLite) data access is much faster and apps can provide a much better user experience.
Without a Sync API, applications require an ongoing internet connection and constantly download all data in each synchronization, including content they already knew about. This wastes a lot of mobile data and time, especially when syncing on cellular data.
Instead, using the Sync API, applications sync periodically. Depending on the use case, they may sync every few hours when opened or pending user interaction. To do so, it performs delta updates:
To enable delta updates, Contentful provides a special synchronization endpoint. This endpoint delivers only new and changed content and notifies about deleted content (deletions). It will never transfer duplicate content the client has already received before.
Compared to the other strategies, syncing with delta updates has many advantages:
Keep in mind that the synchronization endpoint will always give you all the content of a space or a specific content type, so it may not make sense to use it for every use case:
1 2 3
curl -X GET \ -H 'Authorization: Bearer b4c0n73n7fu1' \ 'https://cdn.contentful.com/spaces/cfexampleapi/sync?initial=true'
nextPageUrlin case your request returned more results than what fits into a single page. Eventually, when retrieving the last page, the response will contain a
nextSyncUrlwhich contains an opaque sync token which can be used to receive delta updates of changes performed after your last request.
In addition to the regular
Asset item types, there can also be
DeletedAsset items in the synchronization response, these indicate that a specific resource has been deleted. The delta updates work at the resource level, if a resource has been changed, its whole content will be part of the synchronization response.
When syncing entries or assets they come in all available localizations instead of just a single one. Usually resources coming from the delivery API only come with a single value per field - the value of the locale you requested or the default one. The sync endpoint returns all locales per field.