Here's What Different SIDs mean in a Programmable Messaging Response

January 29, 2021
Written by
Liz Moy
Twilion

Here's What Different SIDs mean in a Programmable Messaging Response

If you’ve used the Twilio Programmable Messaging API, you may be wondering what all of the different SID values mean.

You also may have seen different names in a JSON response that share the same values similar to this (and wondered why there were duplicates):

{ "SmsMessageSid": "SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "SmsSid": "SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "MessageSid": "SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"," }

This post will go over what the different Programmable Messaging SIDs mean, and how you can use them. It will also demonstrate how you can set up a Status Callback URL in a POST request to the Programmable Messaging API to see an instance where two different SIDs contain the same value.

Prerequisites

  • A Twilio account - sign up for a free one here

What even is a SID?

SID stands for String Identifier. It’s a unique key that is used to identify specific resources. At Twilio, each SID has 34 digits and you can identify the type of SID and the product it’s associated with by the first two characters.

Which SIDs are associated with Programmable Messaging?

These are the SIDs you are likely to encounter when sending SMS, MMS, Channels (Facebook Messenger) and WhatsApp messages. They are sent as parameters in a POST request or as URL query parameters depending on the way you’d like to set it up.

Message SID: This type of SID will start with “SM” for SMS messages and “MM” for MMS messages. It’s the unique ID for any message successfully created by Twilio’s API. This applies to both outbound messages, and inbound messages to one of your Twilio numbers. The easiest place to find a MessageSid in the Twilio Console is by going to the Programmable Messaging logs, where you can click on a specific message to find the MessageSid, or if you already know it and want to use it to find a message you can search by MessageSid. You can use the MessageSid to:

SMS SID and SMS Message SID: These are the same as Message SID, which is why the value will be the same in a response. This parameter has been deprecated and it’s included for backward compatibility. It was named this previously when SMS was the focus, but now that messaging encompasses WhatsApp and Facebook Messenger, it would be confusing to limit the naming to SMS.

Messaging Service SID: This type of SID starts with “MG” and is used as an identifier to group together a common set of senders to share functionality and configuration. “Senders” in this context means Twilio long code numbers, short codes, and toll-free numbers. This is helpful for those who are using Twilio to build complex messaging applications and want to be able to set up a service that will apply to multiple senders. You can use MessagingServiceSid to:

Account SID: This SID starts with “AC” and is a credential that acts as a username. It’s important to keep your Account SID hidden. Do not commit it anywhere, as someone can access your full project if they have your Account SID and your Auth Token (which acts as a password). This SID can be used to:

SID: If you are using short codes, the SID will start with “SC”. You can use this type of SID to:

Where would I see the instance of multiple SIDs with the same value?

If you add a Status Callback Url for message updates when you send a POST request through the API, you will see the deprecated SMS SID show up in the response. If you want to see it for yourself, you can try out the following steps:

  • Log in to Twilio and buy a Twilio phone number following these steps.
  • Click on “All Products and Services” and go to Runtime > Functions > Services.
  • Click “Create Service” and name it status-callback-service.
  • Add a Function and name it status-callback. Set it to “Public”.

Delete any boilerplate code inside your new Function, and replace it with the following code:.

exports.handler = function(context, event, callback) {
  console.log(JSON.stringify(event));
  return callback(null, event);
};

Save your Function, hit “Deploy All” and refresh the page. Toggle “Enable live logs” to be on.

Then, copy the Function’s URL by clicking on the three dots and choosing “Copy URL” from the dropdown.

A screenshot of the three dots in Twilio Serverless where you can choose "Copy URL" from the dropdown next to a Function

Now open up a terminal or command prompt window and enter the below cURL request:

Make sure that you replace the Account SID and Auth Token with your own values, which you can find on the homepage of your Twilio Console. You will also need to replace the `From` value with your Twilio number, the `StatusCallback` value with the Function URL you copied, and the `To` value with the number you want to message.
curl -X POST https://api.twilio.com/2010-04-01/Accounts/YOUR-ACCOUNT-SID/Messages.json \
--data-urlencode "From=+1-Your-Twilio-Number" \
--data-urlencode "StatusCallback=YOUR-FUNCTION-URL" \
--data-urlencode "Body=hello" \
--data-urlencode "To=+1-YOUR-PERSONAL-NUMBER" \
-u YOUR-ACCOUNT-SID:YOUR-AUTH-TOKEN

After you run the cURL command, you can check the logs in your Service and see where the response was logged. You’ll notice that there is both SMS SID and Message SID, and the value is the same.

A screenshot of the live logs in Twilio Functions where you can see the various SIDs coming through in the response.

Conclusion: Use Message SID

Moving forward be sure to use Message SID for any actions you might take on a single message. Any other SID with “SMS” in the title is outdated and may not work if you are using the most up to date version.

I hope you found this post helpful and that it will be of use to you as you build exciting new messaging experiences. Send me a tweet or an email to let me know what you’re building!

Liz Moy is a Developer Evangelist on the Enterprise Evangelism team. She loves to talk to developers and does so frequently on Build and Deploy with Liz Moy, a podcast powered by Twilio. You can find her at lmoy [at] twilio.com or on Twitter @ecmoy.