A Sync Document is an object with these characteristics:
ttl
parameter. By default, it is persisted permanently.
A Sync Document is best suited for basic use cases, such as rudimentary publish/subscribe flows, or situations where history synchronization is not a requirement.
Documents can be created, updated, subscribed to, and removed via the client JavaScript SDK. See the latest JavaScript SDK documentation for full details. Servers wishing to manage these objects can do so via the REST API.
sid
type: SID<ET>The unique string that we created to identify the Document resource.
^ET[0-9a-fA-F]{32}$
34
34
unique_name
type: stringAn application-defined string that uniquely identifies the resource. It can be used in place of the resource's sid
in the URL to address the resource and can be up to 320 characters long.
account_sid
type: SID<AC>The SID of the Account that created the Document resource.
^AC[0-9a-fA-F]{32}$
34
34
service_sid
type: SID<IS>The SID of the Sync Service the resource is associated with.
^IS[0-9a-fA-F]{32}$
34
34
revision
type: stringThe current revision of the Sync Document, represented as a string. The revision
property is used with conditional updates to ensure data consistency.
data
type: objectAn arbitrary, schema-less object that the Sync Document stores. Can be up to 16 KiB in length.
date_expires
type: string<date-time>The date and time in GMT when the Sync Document expires and will be deleted, specified in ISO 8601 format. If the Sync Document does not expire, this value is null
. The Document resource might not be deleted immediately after it expires.
date_created
type: string<date-time>The date and time in GMT when the resource was created specified in ISO 8601 format.
date_updated
type: string<date-time>The date and time in GMT when the resource was last updated specified in ISO 8601 format.
created_by
type: stringThe identity of the Sync Document's creator. If the Sync Document is created from the client SDK, the value matches the Access Token's identity
field. If the Sync Document was created from the REST API, the value is system
.
POST https://sync.twilio.com/v1/Services/{ServiceSid}/Documents
ServiceSid
type: stringThe SID of the Sync Service to create the new Document resource in.
UniqueName
type: stringAn application-defined string that uniquely identifies the Sync Document
Data
type: objectA JSON string that represents an arbitrary, schema-less object that the Sync Document stores. Can be up to 16 KiB in length.
Ttl
type: integerHow long, in seconds, before the Sync Document expires and is deleted (the Sync Document's time-to-live).
_10client.document('user_prefs').then(function(doc) {_10 doc.set({_10 foregroundColor: "#ffff00",_10 backgroundColor: "#ff0000"_10 });_10});
Using set will overwrite any existing data in a document.
GET https://sync.twilio.com/v1/Services/{ServiceSid}/Documents/{Sid}
ServiceSid
type: stringThe SID of the Sync Service with the Document resource to fetch.
Sid
type: stringThe SID of the Document resource to fetch. Can be the Document resource's sid
or its unique_name
.
_10client.document('user_prefs').then(function(doc) {_10 console.log(doc.value);_10});
_10syncClient.document("user_prefs").then(function(doc) {_10 doc.on("updated",function(data) {_10 console.log(data);_10 });_10});
GET https://sync.twilio.com/v1/Services/{ServiceSid}/Documents
By default, this will return the first 50 Documents. Specify a PageSize
value to fetch up to 100 items at once. See paging for more information.
ServiceSid
type: stringThe SID of the Sync Service with the Document resources to read.
PageSize
type: integerHow many resources to return in each list page. The default is 50, and the maximum is 1000.
1
Page
type: integerThe page index. This value is simply for client state.
0
POST https://sync.twilio.com/v1/Services/{ServiceSid}/Documents/{Sid}
ServiceSid
type: stringThe SID of the Sync Service with the Document resource to update.
Sid
type: stringThe SID of the Document resource to update. Can be the Document resource's sid
or its unique_name
.
Data
type: objectA JSON string that represents an arbitrary, schema-less object that the Sync Document stores. Can be up to 16 KiB in length.
Ttl
type: integerHow long, in seconds, before the Sync Document expires and is deleted (time-to-live).
This will modify the foregroundColor key in the Document
_10client.document('user_prefs').then(function(doc) {_10 doc.update({foregroundColor: "#ff0000"});_10});
Use mutate for more fine grained control over updates.
_10client.document('user_prefs').then(function(doc) {_10 doc.mutate(function(remoteData) {_10 remoteData.foregroundColor = "#e2e2e2";_10 return remoteData;_10 });_10});
The mutate
function helps your Javascript code respond to concurrent updates with versioned control. See the corresponding JavaScript SDK documentation for details.
DELETE https://sync.twilio.com/v1/Services/{ServiceSid}/Documents/{Sid}
ServiceSid
type: stringThe SID of the Sync Service with the Document resource to delete.
Sid
type: stringThe SID of the Document resource to delete. Can be the Document resource's sid
or its unique_name
.
_10syncClient.document("user_prefs").then(function(doc) {_10 doc.removeDocument().then(function() {_10 console.log('Document removed.');_10 });_10});