Skip to content

Commit 1b0c1b7

Browse files
Added SyncApi feature
1 parent f913250 commit 1b0c1b7

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

README.md

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,16 @@ Following are Image Delivery API examples.
168168
'height': 100
169169
})
170170

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
174172

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.
175174
[Read Sync API documentation](https://docs.google.com/document/d/14IFRlmtOja5OPzlK1Q6DxW3auISEQNhX6opMYJcHVsI/).
176175

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.
178179

179-
// For initializing sync
180+
To start the Initial Sync process, use the syncStack method.
180181

181182
let data = Stack.sync({"init": true})
182183
data.then(function(sync_data, err) {
@@ -187,8 +188,15 @@ Following are Sync API examples.
187188
if (err) throw err
188189
})
189190

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.
190199

191-
// For fetching the next batch of entries using pagination token
192200
193201
let data = Stack.sync({"pagination_token" : "<pagination_token>"})
194202
data.then(function(result, err) {
@@ -199,7 +207,10 @@ Following are Sync API examples.
199207
if(err) throw err
200208
})
201209

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+
203214

204215
let data = Stack.sync({"sync_token" : “<sync_token>”})
205216
data.then(function(sync_data, err) {
@@ -210,6 +221,12 @@ Following are Sync API examples.
210221
if(err) throw err
211222
})
212223

224+
##### Advanced sync queries
225+
226+
You can use advanced sync queries to fetch custom results while performing initial sync.
227+
[Read advanced sync queries documentation](https://www.contentstack.com/docs/guide/synchronization/using-the-sync-api-with-javascript-sdk#advanced-sync-queries)
228+
229+
213230

214231
### Helpful Links
215232

0 commit comments

Comments
 (0)