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:
account_sid
type: SID<AC>The SID of the Account that created the Map Item 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
map_sid
type: SID<MP>The SID of the Sync Map that contains the Map Item.
^MP[0-9a-fA-F]{32}$
34
34
data
type: objectAn arbitrary, schema-less object that the Map Item stores. Can be up to 16 KiB in length.
date_expires
type: string<date-time>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.
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 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
MapSid
type: stringThe SID of the Sync Map to add the new Map Item to. Can be the Sync Map resource's sid
or its unique_name
.
Key
type: stringRequiredThe unique, user-defined key for the Map Item. Can be up to 320 characters long.
Data
type: objectRequiredA JSON string that represents an arbitrary, schema-less object that the Map Item stores. Can be up to 16 KiB in length.
Ttl
type: integerAn alias for item_ttl
. If both parameters are provided, this value is ignored.
ItemTtl
type: integerHow long, in seconds, before the Map Item expires (time-to-live) and is deleted.
CollectionTtl
type: integerHow 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}
ServiceSid
type: stringThe SID of the Sync Service with the Sync Map Item resource to fetch.
MapSid
type: stringThe 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
.
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.
ServiceSid
type: stringThe SID of the Sync Service with the Map Item resources to read.
MapSid
type: stringThe 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
.
Order
type: enum<string>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
From
type: stringThe key
of the first Sync Map Item resource to read. See also bounds
.
Bounds
type: enum<string>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
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
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-Match
type: stringIf 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.
ServiceSid
type: stringThe SID of the Sync Service with the Sync Map Item resource to update.
MapSid
type: stringThe 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
.
Data
type: objectA JSON string that represents an arbitrary, schema-less object that the Map Item stores. Can be up to 16 KiB in length.
Ttl
type: integerAn alias for item_ttl
. If both parameters are provided, this value is ignored.
ItemTtl
type: integerHow long, in seconds, before the Map Item expires (time-to-live) and is deleted.
CollectionTtl
type: integerHow 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-Match
type: stringIf 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.
ServiceSid
type: stringThe SID of the Sync Service with the Sync Map Item resource to delete.
MapSid
type: stringThe 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
.
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});