Sync APIBeta
Synchronize application state across mobile apps and websites in real-time.
Create a document
A document is the simplest Sync primitive. Use it for basic pub/sub use cases or storing state where history isn't important.
View docs- JavaScript
client.document('myDocument').then(function(doc) { doc.set({ number: 12345 }); });
Subscribe to the document
Subscribe to a Sync object to receive events whenever the object is updated by other clients or servers.
View docs- JavaScript
client.document('myDocument').then(function(doc) { doc.on('updated', function(data) { console.log('Document updated!', data); }); });
Create a list
Store JSON in individual items in an ordered list. Use it when history and stepping through state is important.
View docs- JavaScript
client.list('myList').then(function(list) { list.push({ state: 'busy', lastSeen: 1467788923 }); });
Subscribe to the list
Subscribe to the list and receive new items and updates to existing list items.
View docs- JavaScript
client.list('myList').then(function(list) { list.on('itemAdded', function(item) { console.log('List item added!', item); }); });
Get existing list items
Get the contents of an existing list so you can track changes in state over time.
View docs- JavaScript
client.list('myList').then(function(list) { list.getItems({ limit: 20 }).then(function(page) { console.log('Items retrieved!', page.items); }); });
Create a map
A map lets you store JSON items by developer defined keys in an unordered collection.
View docs- JavaScript
client.map('myMap').then(function(map) { map.set('alice', { number: 1234567, mealChoice: 'vegan' }); });
Subscribe to the map
Subscribe to the map and receive new items added and updates to existing map items.
View docs- JavaScript
client.map('myMap').then(function(map) { map.on('itemAdded', function(item) { console.log('Map item added!', item); }); });
- Curl
- Ruby
- Python
- PHP
curl -X GET https://sync.twilio.com/v1/Services/ISxx/Documents/ -u 'your_account_sid:your_auth_token'
require 'twilio-ruby' client = Twilio::REST::Client.new("your_account_sid", "your_auth_token") sync_service = client.sync.services("your_sync_service_sid") sync_doc = sync_service.documents("sync_doc")
from twilio.rest import TwilioRestClient client = TwilioRestClient("your_account_sid", "your_auth_token") sync_service = client.sync.services("your_sync_service_sid") sync_doc = sync_service.documents("gamescore")
$client = new Twilio\Rest\Client("your_account_sid", "your_auth_token"); $sync = $client->sync; $service = $sync->services->getContext("your_sync_service_sid"); $state = $service->documents("gamescore");
Create a map
Create a map via the REST API so it's ready and available for clients ahead of time.
View docs- Curl
- Ruby
- Python
- PHP
curl -X POST https://sync.twilio.com/v1/Services/ISxx/Maps \ -d 'UniqueName=MyFirstMap' \ -u 'your_account_sid:your_auth_token'
require 'twilio-ruby' client = Twilio::REST::Client.new("your_account_sid", "your_auth_token") sync_service = client.sync.services("your_sync_service_sid") sync_map = sync_service.sync_maps.create("sync_map")
from twilio.rest import TwilioRestClient client = TwilioRestClient("your_account_sid", "your_auth_token") sync_service = client.sync.services("your_sync_service_sid") sync_map = sync_service.sync_maps.create("sync_map")
$client = new Twilio\Rest\Client("your_account_sid", "your_auth_token"); $sync = $client->sync; $ervice = $sync->services->getContext("your_sync_service_sid"); $syncMap = $service->syncMaps->create(['uniqueName' => "syncMap"]);
Get a list
Get the contents of an existing list so you can track changes in state over time.
View docs- Curl
- Ruby
- Python
- PHP
curl -X GET https://sync.twilio.com/v1/Services/ISxx/Lists/ESxx/Items/0 \ -u 'your_account_sid:your_auth_token'
require 'twilio-ruby' client = Twilio::REST::Client.new("your_account_sid", "your_auth_token") sync_service = client.sync.services("your_sync_service_sid") players = sync_service.sync_lists("players").sync_list_items.stream() names = players.collect { |person| person.data['first_name'] }
from twilio.rest import TwilioRestClient client = TwilioRestClient("your_account_sid", "your_auth_token") sync_service = client.sync.services("your_sync_service_sid") players = sync_service.sync_lists("players").sync_list_items.stream() names = [person.data['first_name'] for person in players]
$client = new Twilio\Rest\Client("your_account_sid", "your_auth_token"); $sync = $client->sync; $service = $sync->services->getContext("your_sync_service_sid"); $players = $service->syncLists->getContext("players")->syncListItems->stream(); $names = array(); foreach($players as $person) { $names[] = $person->data['firstName']; }
Communicate reliably
Experience a 99.95% uptime SLA made possible with automated failover and zero maintenance windows.
Operate at scale
Extend the same app you write once to new markets with configurable features for localization and compliance.
Many channels
Use the same platform you know for voice, SMS, video, chat, two-factor authentication, and more.
No shenanigans
Get to market faster with pay-as-you-go pricing, free support, and the freedom to scale up or down without contracts.