Get Started

TwiML SMSTM: Twilio's Request

How Twilio Passes Data to Your Application

Twilio makes HTTP requests to your application just like a regular web browser. By including parameters and values in its requests, Twilio sends data to your application that you can act upon before responding. You can configure the URLs and HTTP Methods Twilio uses to make its requests via your account portal or using the REST API.

Creating a Twilio Application within your account will allow you to more-easily configure the URLs you want Twilio to request when someone sends an SMS to one of your phone numbers. Instead of assigning URLs directly to a phone number, you can assign them to an application and then assign that application to the phone number. This will allow you to pass around configuration between phone numbers without having to memorize or copy and paste URLs.

TwiML SMS Requests

When Twilio receives an SMS for one of your Twilio numbers it makes a synchronous HTTP request to the SMS URL configured for that number, and expects to receive TwiML in response. Twilio sends the following parameters with its request as POST parameters or URL query parameters, depending on which HTTP method you've configured:

Request Parameters

Parameter Description
SmsSid A 34 character unique identifier for the message. May be used to later retrieve this message from the REST API.
AccountSid The 34 character id of the Account this message is associated with.
From The phone number that sent this message.
To The phone number of the recipient.
Body The text body of the SMS message. Up to 160 characters long.

Twilio also attempts to look up geographic data based on the 'From' and 'To' phone numbers. Twilio sends the following parameters, if available:

Parameter Description
FromCity The city of the sender
FromState The state or province of the sender.
FromZip The postal code of the called sender.
FromCountry The country of the called sender.
ToCity The city of the recipient.
ToState The state or province of the recipient.
ToZip The postal code of the recipient.
ToCountry The country of the recipient.

Data Formats

Phone Numbers

All phone numbers in requests from Twilio are in E.164 format if possible. For example, (415) 555-4345 would come through as '+14155554345'. However, there are occasionally cases where Twilio cannot normalize an incoming caller ID to E.164. In these situations Twilio will report the raw caller ID string.

Dates & Times

All dates and times in requests from Twilio are GMT in RFC 2822 format. For example, 6:13 PM PDT on August 19th, 2010 would be 'Fri, 20 Aug 2010 01:13:42 +0000'