SUPPORT.TWILIO.COM END OF LIFE NOTICE: This site, support.twilio.com, is scheduled to go End of Life on February 27, 2024. All Twilio Support content has been migrated to help.twilio.com, where you can continue to find helpful Support articles, API docs, and Twilio blog content, and escalate your issues to our Support team. We encourage you to update your bookmarks and begin using the new site today for all your Twilio Support needs.

How to Update the Value of MapItem Sync Object

Objective

To guide you in updating the value of a MapItem Sync object, ensuring data persistence without expiration. This article provides step-by-step instructions to configure the Sync object correctly, explains the impact of setting the value to null, and highlights best practices for maintaining long-term data synchronization in Twilio Sync.

 

Product

REST API and TwiML

 

Environment

legacy Twilio Console

 

Procedure 

If you are creating a new MapItem Sync object you can ignore the ttl value and this will create an object without expiration. Below is an example in Node.js

const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken);

async function createSyncMapItem() {
  const syncMapItem = await client.sync.v1
    .services("ServiceSid")
    .syncMaps("MapSid")
    .syncMapItems.create({
      data: {
        name: "Foo Bar",
        level: 30,
        username: "foo_bar",
      },
      key: "foo",
    });

  console.log(syncMapItem.key);
}

createSyncMapItem();

 

If you have already created an object specifying the ttl and want to set the value of an already existing object so that it does not expire, then updating the tts object to null or ignoring the value of the ttl while updating the object will not update the value of ttl to be endless.

We should rather update the value of ttl to 0 and this will update the value of ttl to null. Below is an example in Node.js

const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken);

async function updateSyncMapItem() {
  const syncMapItem = await client.sync.v1
    .services("ServiceSid")
    .syncMaps("MapSid")
    .syncMapItems("Venu")
    .update({
      data: {
        name: "FooBaz",
        level: 31,
        username: "foo_baz",
      },
      ttl: 0,
    });

  console.log(syncMapItem);
}

updateSyncMapItem();

 

Additional Information 

For more detailed information, you can refer to:

Have more questions? Submit a request
Powered by Zendesk