Document Resource
A Sync Document is an object with these characteristics:
- It’s a single JSON object, up to 16KiB in size.
- Its modification history is not maintained; however, documents are assigned a new revision number after each modification.
- Its concurrency control is based on an ‘eventual’ model and it uses revision numbers for conditional updates.
- It expires and is deleted automatically if its eviction is configured by setting the
ttl
parameter. By default, it is persisted permanently.
Working with Sync Documents
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.
Document properties
Resource Properties in REST API format | |
---|---|
sid
|
The unique string that we created to identify the Document resource. |
unique_name
|
An application-defined string that uniquely identifies the resource. It can be used in place of the resource's |
account_sid
|
The SID of the Account that created the Document resource. |
service_sid
|
The SID of the Sync Service the resource is associated with. |
url
|
The absolute URL of the Document resource. |
links
|
The URLs of resources related to the Sync Document. |
revision
|
The current revision of the Sync Document, represented as a string. The |
data
|
An arbitrary, schema-less object that the Sync Document stores. Can be up to 16 KiB in length. |
date_expires
|
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 |
date_created
|
The date and time in GMT when the resource was created specified in ISO 8601 format. |
date_updated
|
The date and time in GMT when the resource was last updated specified in ISO 8601 format. |
created_by
|
The identity of the Sync Document's creator. If the Sync Document is created from the client SDK, the value matches the Access Token's |
Create a Document resource
https://sync.twilio.com/v1/Services/{ServiceSid}/Documents
Parameters
Parameters in REST API format | |
---|---|
service_sid
Path
|
The SID of the Sync Service to create the new Document resource in. |
unique_name
Optional
|
An application-defined string that uniquely identifies the Sync Document |
data
Optional
|
A JSON string that represents an arbitrary, schema-less object that the Sync Document stores. Can be up to 16 KiB in length. |
ttl
Optional
|
How long, in seconds, before the Sync Document expires and is deleted (the Sync Document's time-to-live). |
Example 1
Example 2
Using set will overwrite any existing data in a document.
Fetch a Document resource
https://sync.twilio.com/v1/Services/{ServiceSid}/Documents/{Sid}
Parameters
Parameters in REST API format | |
---|---|
service_sid
Path
|
The SID of the Sync Service with the Document resource to fetch. |
sid
Path
|
The SID of the Document resource to fetch. Can be the Document resource's |
Example 1
Example 2
Example 3
Read multiple Document resources
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.
Parameters
Parameters in REST API format | |
---|---|
service_sid
Path
|
The SID of the Sync Service with the Document resources to read. |
Example 1
Update a Document resource
https://sync.twilio.com/v1/Services/{ServiceSid}/Documents/{Sid}
Parameters
Parameters in REST API format | |
---|---|
service_sid
Path
|
The SID of the Sync Service with the Document resource to update. |
sid
Path
|
The SID of the Document resource to update. Can be the Document resource's |
data
Optional
|
A JSON string that represents an arbitrary, schema-less object that the Sync Document stores. Can be up to 16 KiB in length. |
ttl
Optional
|
How long, in seconds, before the Sync Document expires and is deleted (time-to-live). |
if_match
Header
|
The If-Match HTTP request header |
Example 1
Example 2
Example 3
The mutate
function helps your Javascript code respond to concurrent updates with versioned control. See the corresponding JavaScript SDK documentation for details.
Delete a Document resource
https://sync.twilio.com/v1/Services/{ServiceSid}/Documents/{Sid}
Parameters
Parameters in REST API format | |
---|---|
service_sid
Path
|
The SID of the Sync Service with the Document resource to delete. |
sid
Path
|
The SID of the Document resource to delete. Can be the Document resource's |
Example 1
Example 2
Need some help?
We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.