What is a String Identifier (SID)?
A String Identifier (SID) is a unique key that is used to identify specific resources.
Every Twilio resource has a 34 digit SID. You can use the first two characters of the SID to identify its type. Many of our API calls will return a JSON object containing another resource's SID. Using this SID, you can retrieve more information about the specific resource.
For example, the following code creates an SMS message:
_20// Download the helper library from https://www.twilio.com/docs/node/install
_20const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_20// Find your Account SID and Auth Token at twilio.com/console
_20// and set the environment variables. See http://twil.io/secure
_20const accountSid = process.env.TWILIO_ACCOUNT_SID;
_20const authToken = process.env.TWILIO_AUTH_TOKEN;
_20const client = twilio(accountSid, authToken);
_20async function createMessage() {
_20 const message = await client.messages.create({
_20 body: "This will be the body of the new message!",
_20 from: "+14155552344",
_20 console.log(message.sid);
_28 "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_28 "api_version": "2010-04-01",
_28 "body": "This will be the body of the new message!",
_28 "date_created": "Thu, 24 Aug 2023 05:01:45 +0000",
_28 "date_sent": "Thu, 24 Aug 2023 05:01:45 +0000",
_28 "date_updated": "Thu, 24 Aug 2023 05:01:45 +0000",
_28 "direction": "outbound-api",
_28 "error_message": null,
_28 "from": "+14155552344",
_28 "messaging_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_28 "sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_28 "subresource_uris": {
_28 "media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Media.json"
_28 "campaign_name": "Spring Sale 2022",
_28 "message_type": "cart_abandoned"
_28 "to": "+14155552345",
_28 "uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
Note how the newly created message has a property named sid
. Using this value we can later fetch this specific message.
_18// Download the helper library from https://www.twilio.com/docs/node/install
_18const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_18// Find your Account SID and Auth Token at twilio.com/console
_18// and set the environment variables. See http://twil.io/secure
_18const accountSid = process.env.TWILIO_ACCOUNT_SID;
_18const authToken = process.env.TWILIO_AUTH_TOKEN;
_18const client = twilio(accountSid, authToken);
_18async function fetchMessage() {
_18 const message = await client
_18 .messages("SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_18 console.log(message.status);
_29 "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_29 "api_version": "2010-04-01",
_29 "date_created": "Fri, 24 May 2019 17:18:27 +0000",
_29 "date_sent": "Fri, 24 May 2019 17:18:28 +0000",
_29 "date_updated": "Fri, 24 May 2019 17:18:28 +0000",
_29 "direction": "outbound-api",
_29 "error_message": "Carrier violation",
_29 "from": "+12019235161",
_29 "messaging_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_29 "sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_29 "subresource_uris": {
_29 "media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMb7c0a2ce80504485a6f653a7110836f5/Media.json",
_29 "feedback": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMb7c0a2ce80504485a6f653a7110836f5/Feedback.json"
_29 "campaign_name": "Spring Sale 2022",
_29 "message_type": "cart_abandoned"
_29 "to": "+18182008801",
_29 "uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMb7c0a2ce80504485a6f653a7110836f5.json"
Using the message SID, which is prefixed with MM
, we were able to get more information about that specific resource.