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
+24-7Lines changed: 24 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -168,15 +168,16 @@ Following are Image Delivery API examples.
168
168
'height': 100
169
169
})
170
170
171
-
### Working with Sync API
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 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. It lets you perform other actions also such as pagination, start_date, locale, content.
171
+
### Using the Sync API with JavaScript SDK
174
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.
175
174
[Read Sync API documentation](https://docs.google.com/document/d/14IFRlmtOja5OPzlK1Q6DxW3auISEQNhX6opMYJcHVsI/).
176
175
177
-
Following are Sync API examples.
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.
178
179
179
-
// For initializing sync
180
+
To start the Initial Sync process, use the syncStack method.
180
181
181
182
let data = Stack.sync({"init": true})
182
183
data.then(function(sync_data, err) {
@@ -187,8 +188,15 @@ Following are Sync API examples.
187
188
if (err) throw err
188
189
})
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.
190
199
191
-
// For fetching the next batch of entries using pagination token
192
200
193
201
let data = Stack.sync({"pagination_token" : "<pagination_token>"})
194
202
data.then(function(result, err) {
@@ -199,7 +207,10 @@ Following are Sync API examples.
199
207
if(err) throw err
200
208
})
201
209
202
-
// For performing subsequent sync after initial sync
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
+
203
214
204
215
let data = Stack.sync({"sync_token" : “<sync_token>”})
205
216
data.then(function(sync_data, err) {
@@ -210,6 +221,12 @@ Following are Sync API examples.
210
221
if(err) throw err
211
222
})
212
223
224
+
##### Advanced sync queries
225
+
226
+
You can use advanced sync queries to fetch custom results while performing initial sync.
0 commit comments