Synchronization
The Sync API allows you to keep a local copy of all content in a space up-to-date via delta updates, or only the content that has changed.
Syncing specific content
By default a sync request response includes all resource types including assets, entries of all content types and deleted resources.
To sync specific content you can specify a type parameter for the initial sync:
Initial synchronization
A client syncs content by using the sync endpoint. A single sync consists of one or more pages, each a separate request and response.
The first time a client synchronizes content it sends a request to the sync endpoint with the URI query parameter initial set to true.
You should only sync with initial=true for the initial sync when a client has no existing content. This transfers all content from a space, but does not contain content deleted from fields or deleted assets and content entries.
The limit parameter sets the page size for the number of retrieved entries. The limit is useful when you have very large content entries and reach the maximum response size limit. This limit is then encoded in the synchronization token and used for all following synchronizations.
Sync contains content from all environments.
Use the Get synced content endpoint, see example:
Initial synchronization of entries of a specific content type
For entries, you can also specify a content_type parameter. When specifying content_type you must specify type as Entry (meaning there will be no deletions). You can only specify the type and content_type parameter at the initial sync along with the initial parameter. Any subsequent syncs will only include the types you have specified. If you want to sync entries by content type you should separately subscribe to a Deletion or DeletedEntry sync to be notified when entries are deleted.
Use the Get synced content endpoint, see example:
Pagination and subsequent syncs
Synchronization responses contain either a nextPageUrl or nextSyncUrl attribute. If there is more content for the current sync, nextPageUrl will contain an URL with a sync_token which will retrieve the next page. This continues until you have retrieved all content.
At this point, the response will contain a nextSyncUrl which you use to make requests in the future and retrieve delta updates between the current content on Contentful and what you retrieved with your last sync request. Upon completion, you will receive a new nextSyncUrl which you can again use for future updates.
If a client loses the nextSyncUrl, the client should delete its local content and perform an initial synchronization again.
NOTE: The initial query with sync_token will persist across subsequent syncs.
Use the Get synced content endpoint, see example:
sync_token is an opaque token which is used to identify your previous sync.
Structure of deleted entities
For deletions, objects of the types DeletedAsset and DeletedEntry are sent. Those do not contain full assets or entries.
Query deleted entries
Use the Get synced content endpoint, see example:
The response will look like:
Query deleted assets
Use the Get synced content endpoint, see example:
The response will look like: