SMS API: Send, Receive and Reply to Texts

Twilio's SMS API lets you simply add two-way text messaging capabilities to your application. Whether you're adding appointment reminders, tracking text message conversations, building out your SMS marketing capabilities, or creating something completely new we have tutorials, sample applications, and full reference documentation to help.

By sending outgoing messages and responding to your users' incoming text messages, your application can deliver the interactivity your users want. Here we've gathered guides, walkthroughs, and other documents and posts to help your application with both paths as well as the higher level use cases.

Want more information on Twilio and SMS? See a Programmable SMS overview or see the SMS API pricing

Send, Receive, and Reply to Text Messages

For 6 common web languages, using our Helper Libraries is the easiest way to integrate SMS sending and receiving in your application. Our Quickstarts for these languages get you from a blinking cursor to a buzzing phone (or a text reply) in just minutes.

Send an SMS with the SMS API

With the SMS API, you can use any language that can make HTTP requests to send an SMS. Most of these code samples only show one-way SMS (sending) but if you expose an endpoint in your app you can use a webhook from Twilio to receive (and reply to) incoming messages.

Missing a language you like? If you follow the conventions in our curl code snippet, you can translate the API call to your programming language choice.

Loading Code Samples...
Language
Response Format:
  • json
Format:
  • JSON
  • XML
curl -X POST 'https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages.json' \
--data-urlencode 'To=+15558675310'  \
--data-urlencode 'From=+15017122661'  \
--data-urlencode 'Body=This is the ship that made the Kessel Run in fourteen parsecs?'  \
-u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token
{
  "sid": "MMc781610ec0b3400c9e0cab8e757da937",
  "date_created": "Mon, 19 Oct 2015 07:07:03 +0000",
  "date_updated": "Mon, 19 Oct 2015 07:07:03 +0000",
  "date_sent": null,
  "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "to": "+15558675310",
  "from": "+15017122661",
  "body": "This is the ship that made the Kessel Run in fourteen parsecs?",
  "status": "queued",
  "num_segments": "1",
  "num_media": "0",
  "direction": "outbound-api",
  "api_version": "2010-04-01",
  "price": null,
  "price_unit": "USD",
  "error_code": null,
  "error_message": null,
  "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMc781610ec0b3400c9e0cab8e757da937.json",
}
<?xml version='1.0' encoding='UTF-8'?>
<TwilioResponse>
<Message>
  <Sid>MMc781610ec0b3400c9e0cab8e757da937</Sid>
  <DateCreated>Mon, 19 Oct 2015 07:09:09 +0000</DateCreated>
  <DateUpdated>Mon, 19 Oct 2015 07:09:09 +0000</DateUpdated>
  <DateSent/>
  <AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
  <To>+15558675310</To>
  <From>+15017122661</From>
  <Body>This is the ship that made the Kessel Run in fourteen parsecs?</Body>
  <Status>queued</Status>
  <NumSegments>1</NumSegments>
  <NumMedia>0</NumMedia>
  <Direction>outbound-api</Direction>
  <ApiVersion>2010-04-01</ApiVersion>
  <Price/>
  <PriceUnit>USD</PriceUnit>
  <ErrorCode/>
  <ErrorMessage/>
  <Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMf1150fe5baf04104a39c3f311a053e4e.xml</Uri>
  <SubresourceUris/>
</Message>
</TwilioResponse>
Send an SMS using the Programmable SMS API

Send an SMS or MMS from the Command Line

Prefer to test out the SMS API directly from your shell? If you've got a (mostly) POSIX compliant OS, cURL, and a command line we can help you out. Our API Reference documentation includes cURL commands, and we've written special guides for some shells.

Advanced Applications on the Twilio SMS API

Many applications built on our SMS API go beyond simply sending or receiving SMS. Whether you'd like to add appointment reminders, ETA notifications, lead alerts, automated surveys, text message marketing, or something else to your application we have short tutorials and sample applications for you to try.

Scaling and Moving Beyond the API

Twilio has a number of products and messaging features which help you scale your application or assist you in building out more advanced functionality. Masking people in an SMS conversation, geo-matching SMS reply numbers, and even building SMS communication flows in a visual editor are all possible.

  • Twilio Studio - build SMS and MMS communications with a drag & drop editor
  • Twilio Proxy - masked communications for text messaging, voice, and other conversations
  • Twilio Copilot - match numbers by geographic location, spread outgoing messages over multiple numbers, and more

Help Integrating the SMS API

Twilio's SMS API is a flexible building block which can take you from sending your first text message all the way to sending and receiving millions (or more!) SMS and MMS. While we hope this page gives a good overview of what you can do with the API, we're only just scratching the surface: see, for example, our shortcode capabilities and our debugging tools.

If you need any help integrating the SMS API or want to talk best practices, please get in touch. You can give us feedback using the survey on this page, talking to support, talking to sales, or reaching out on Twitter.

We can't wait to see what you build with our API - and we'd love to help you realize your vision.

 

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.

Loading Code Samples...
Response Format:
  • json
Format:
  • JSON
  • XML
curl -X POST 'https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages.json' \
--data-urlencode 'To=+15558675310'  \
--data-urlencode 'From=+15017122661'  \
--data-urlencode 'Body=This is the ship that made the Kessel Run in fourteen parsecs?'  \
-u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token
{
  "sid": "MMc781610ec0b3400c9e0cab8e757da937",
  "date_created": "Mon, 19 Oct 2015 07:07:03 +0000",
  "date_updated": "Mon, 19 Oct 2015 07:07:03 +0000",
  "date_sent": null,
  "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "to": "+15558675310",
  "from": "+15017122661",
  "body": "This is the ship that made the Kessel Run in fourteen parsecs?",
  "status": "queued",
  "num_segments": "1",
  "num_media": "0",
  "direction": "outbound-api",
  "api_version": "2010-04-01",
  "price": null,
  "price_unit": "USD",
  "error_code": null,
  "error_message": null,
  "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMc781610ec0b3400c9e0cab8e757da937.json",
}
<?xml version='1.0' encoding='UTF-8'?>
<TwilioResponse>
<Message>
  <Sid>MMc781610ec0b3400c9e0cab8e757da937</Sid>
  <DateCreated>Mon, 19 Oct 2015 07:09:09 +0000</DateCreated>
  <DateUpdated>Mon, 19 Oct 2015 07:09:09 +0000</DateUpdated>
  <DateSent/>
  <AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
  <To>+15558675310</To>
  <From>+15017122661</From>
  <Body>This is the ship that made the Kessel Run in fourteen parsecs?</Body>
  <Status>queued</Status>
  <NumSegments>1</NumSegments>
  <NumMedia>0</NumMedia>
  <Direction>outbound-api</Direction>
  <ApiVersion>2010-04-01</ApiVersion>
  <Price/>
  <PriceUnit>USD</PriceUnit>
  <ErrorCode/>
  <ErrorMessage/>
  <Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMf1150fe5baf04104a39c3f311a053e4e.xml</Uri>
  <SubresourceUris/>
</Message>
</TwilioResponse>