A Sync MapItem is an individual item that belongs to one or more of your Sync Maps. See the full API reference documentation for the Sync Map resource here.
You need to create a Map first before you can use this resource to create, read, update, and delete items.
Sync MapItems:
The SID of the Account that created the Map Item resource.
^AC[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the Sync Service the resource is associated with.
^IS[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the Sync Map that contains the Map Item.
^MP[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
An arbitrary, schema-less object that the Map Item stores. Can be up to 16 KiB in length.
The date and time in GMT when the Map Item expires and will be deleted, specified in ISO 8601 format. If the Map Item does not expire, this value is null
. The Map Item might not be deleted immediately after it expires.
The date and time in GMT when the resource was created specified in ISO 8601 format.
The date and time in GMT when the resource was last updated specified in ISO 8601 format.
The identity of the Map Item's creator. If the Map Item is created from the client SDK, the value matches the Access Token's identity
field. If the Map Item was created from the REST API, the value is system
.
POST https://sync.twilio.com/v1/Services/{ServiceSid}/Maps/{MapSid}/Items
The SID of the Sync Map to add the new Map Item to. Can be the Sync Map resource's sid
or its unique_name
.
The unique, user-defined key for the Map Item. Can be up to 320 characters long.
A JSON string that represents an arbitrary, schema-less object that the Map Item stores. Can be up to 16 KiB in length.
An alias for item_ttl
. If both parameters are provided, this value is ignored.
How long, in seconds, before the Map Item expires (time-to-live) and is deleted.
How long, in seconds, before the Map Item's parent Sync Map expires (time-to-live) and is deleted.
Use the set method
_10syncClient.map('users').then(function(map) {_10 map.set('Taylor', {_10 phone_number: 12345678,_10 country: 'UK'_10 }).then(function(item) {_10 console.log('Added: ', item.key);_10 }).catch(function(err) {_10 console.error(err);_10 });_10});
Please note: You can also use the set
method to update data in existing JSON data in a Map. However, using set
will overwrite any existing data in a MapItem.
Note that there are two separate events for map item adds and map item updates:
_12syncClient.map('users').then(function (map) {_12 map.on('itemAdded', function(item) {_12 console.log('key', item.key);_12 console.log('JSON data', item.value);_12 });_12_12//Note that there are two separate events for map item adds and map item updates:_12 map.on('itemUpdated', function(item) {_12 console.log('key', item.key);_12 console.log('JSON data', item.value);_12 });_12});
GET https://sync.twilio.com/v1/Services/{ServiceSid}/Maps/{MapSid}/Items/{Key}
The SID of the Sync Service with the Sync Map Item resource to fetch.
The SID of the Sync Map with the Sync Map Item resource to fetch. Can be the Sync Map resource's sid
or its unique_name
.
The key
value of the Sync Map Item resource to fetch.
Request a MapItem by the key you defined when you created the item
Fetches by a specific key
_10syncClient.map('users').then(function(map) {_10 map.get('Taylor').then(function(item) {_10 console.log(item.value);_10 });_10});
GET https://sync.twilio.com/v1/Services/{ServiceSid}/Maps/{MapSid}/Items
MapItem read access is performed using the key
that provided as an arbitrary string to identify the item.
By default, this will return the first 50 MapItems. Supply a PageSize parameter to fetch up to 100 items at once. See paging for more information.
The SID of the Sync Map with the Sync Map Item resource to fetch. Can be the Sync Map resource's sid
or its unique_name
.
How to order the Map Items returned by their key
value. Can be: asc
(ascending) or desc
(descending) and the default is ascending. Map Items are ordered lexicographically by Item key.
asc
desc
Whether to include the Map Item referenced by the from
parameter. Can be: inclusive
to include the Map Item referenced by the from
parameter or exclusive
to start with the next Map Item. The default value is inclusive
.
inclusive
exclusive
How many resources to return in each list page. The default is 50, and the maximum is 1000.
1
Maximum: 1000
The page token. This is provided by the API.
This code sample displays the first item.
_10syncClient.map('users').then(function(map) {_10 map.getItems().then(function(page) {_10 console.log('show first item', page.items[0].key,_10 page.items[0].value);_10 });_10});
POST https://sync.twilio.com/v1/Services/{ServiceSid}/Maps/{MapSid}/Items/{Key}
MapItem update access is performed using the key
that provided as an arbitrary string to identify the item.
If provided, applies this mutation if (and only if) the “revision” field of this [map item] matches the provided value. This matches the semantics of (and is implemented with) the HTTP If-Match header.
The SID of the Sync Service with the Sync Map Item resource to update.
The SID of the Sync Map with the Sync Map Item resource to update. Can be the Sync Map resource's sid
or its unique_name
.
The key
value of the Sync Map Item resource to update.
A JSON string that represents an arbitrary, schema-less object that the Map Item stores. Can be up to 16 KiB in length.
An alias for item_ttl
. If both parameters are provided, this value is ignored.
How long, in seconds, before the Map Item expires (time-to-live) and is deleted.
How long, in seconds, before the Map Item's parent Sync Map expires (time-to-live) and is deleted. This parameter can only be used when the Map Item's data
or ttl
is updated in the same request.
Use the update method to change the data in a Map Item
_10syncClient.map('users').then(function(map) {_10 map.update('Taylor',{country: "IRL"});_10});
Use mutate for more fine-grained control over updates.
_10syncClient.map('users').then(function (map) {_10 map.mutate('david',function(remoteData) {_10 remoteData.country = "USA";_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.
Note that there are two separate events for map item adds and map item updates:
_12syncClient.map('users').then(function (map) {_12 map.on('itemAdded', function(item) {_12 console.log('key', item.key);_12 console.log('JSON data', item.value);_12 });_12_12//Note that there are two separate events for map item adds and map item updates:_12 map.on('itemUpdated', function(item) {_12 console.log('key', item.key);_12 console.log('JSON data', item.value);_12 });_12});
DELETE https://sync.twilio.com/v1/Services/{ServiceSid}/Maps/{MapSid}/Items/{Key}
Permanently delete a specific item from an existing Map.
If provided, applies this mutation if (and only if) the “revision” field of this [map item] matches the provided value. This matches the semantics of (and is implemented with) the HTTP If-Match header.
The SID of the Sync Service with the Sync Map Item resource to delete.
The SID of the Sync Map with the Sync Map Item resource to delete. Can be the Sync Map resource's sid
or its unique_name
.
The key
value of the Sync Map Item resource to delete.
Deletes the item with key 'Taylor'
_10syncClient.map('users').then(function(map) {_10 map.remove('Taylor').then(function() {_10 console.log('item deleted');_10 });_10});