You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+60Lines changed: 60 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -168,6 +168,66 @@ Following are Image Delivery API examples.
168
168
'height': 100
169
169
})
170
170
171
+
### Using the Sync API with JavaScript SDK
172
+
173
+
The Sync API takes care of syncing your Contentstack data with your app and ensures that the data is always up-to-date by providing delta updates. Contentstack’s JavaScript SDK supports Sync API, which you can use to build powerful apps. Read through to understand how to use the Sync API with Contentstack JavaScript SDK.
174
+
[Read Sync API documentation](https://docs.google.com/document/d/14IFRlmtOja5OPzlK1Q6DxW3auISEQNhX6opMYJcHVsI/).
175
+
176
+
##### Initial sync
177
+
178
+
The Initial Sync process performs a complete sync of your app data. It returns all the published entries and assets of the specified stack in response.
179
+
180
+
To start the Initial Sync process, use the syncStack method.
181
+
182
+
let data = Stack.sync({"init": true})
183
+
data.then(function(sync_data, err) {
184
+
//error for any error description
185
+
//sync_data.items: contains sync data
186
+
//sync_data.paginationToken: for fetching the next batch of entries using pagination token
187
+
//sync_token.syncToken: for performing subsequent sync after initial sync
188
+
if (err) throw err
189
+
})
190
+
191
+
The response also contains a sync token, which you need to store, since this token is used to get subsequent delta updates later, as shown in the Subsequent Sync section below.
192
+
193
+
You can also fetch custom results in initial sync by using advanced sync queries.
194
+
195
+
196
+
##### Sync pagination
197
+
198
+
If the result of the initial sync (or subsequent sync) contains more than 100 records, the response would be paginated. It provides pagination token in the response. You will need to use this token to get the next batch of data.
199
+
200
+
201
+
let data = Stack.sync({"pagination_token" : "<pagination_token>"})
202
+
data.then(function(result, err) {
203
+
//error for any error description
204
+
//result.items: contains sync data
205
+
//result.paginationToken: For fetching the next batch of entries using pagination token
206
+
//result.syncToken: For performing subsequent sync after initial sync
207
+
if(err) throw err
208
+
})
209
+
210
+
##### Subsequent sync
211
+
212
+
You can use the sync token (that you receive after initial sync) to get the updated content next time. The sync token fetches only the content that was added after your last sync, and the details of the content that was deleted or updated.
213
+
214
+
215
+
let data = Stack.sync({"sync_token" : “<sync_token>”})
216
+
data.then(function(sync_data, err) {
217
+
//error for any error description
218
+
//sync_data.items: contains sync data
219
+
//sync_data.paginationToken: for fetching the next batch of entries using pagination token
220
+
//sync_token.syncToken: for performing subsequent sync after initial sync
221
+
if(err) throw err
222
+
})
223
+
224
+
##### Advanced sync queries
225
+
226
+
You can use advanced sync queries to fetch custom results while performing initial sync.
* @description The Sync API takes care of syncing your Contentstack data with your app and ensures that the data is always up-to-date by providing delta updates. Contentstack’s iOS SDK supports Sync API, which you can use to build powerful apps. Read through to understand how to use the Sync API with Contentstack JavaScript SDK.
858
+
* @param {object} params - params is an object which Supports locale, start_date, content_type_id queries.
859
+
* @example
860
+
* Stack.sync({'init': true}) // For initializing sync
861
+
* @example
862
+
* Stack.sync({'init': true, 'locale': 'en-us'}) //For initializing sync with entries of a specific locale
863
+
* @example
864
+
* Stack.sync({'init': true, 'start_date': '2018-10-22'}) //For initializing sync with entries published after a specific date
865
+
* @example
866
+
* Stack.sync({'init': true, 'content_type_id': 'session'}) //For initializing sync with entries of a specific content type
867
+
* @example
868
+
* Stack.sync({'init': true, 'type': 'entry_published'}) //Use the type parameter to get a specific type of content.Supports 'asset_published', 'entry_published', 'asset_unpublished', 'entry_unpublished', 'asset_deleted', 'entry_deleted', 'content_type_deleted'.
869
+
* @example
870
+
* Stack.sync({'pagination_token': '<btlsomething>'}) // For fetching the next batch of entries using pagination token
871
+
* @example
872
+
* Stack.sync({'sync_token': '<btlsomething>'}) // For performing subsequent sync after initial sync
0 commit comments