Menu

Expand
Rate this page:

Twilio's REST APIs

Twilio’s APIs (Application Programming Interfaces) power its platform for communications. Behind these APIs is a software layer connecting and optimizing communications networks around the world to allow your users to call and message anyone, globally.

Twilio has a whole host of APIs, from SMS to Voice to Wireless! You can find Twilio's API reference documentation throughout our product documentation. You can browse the various Twilio APIs here, or jump straight to the API reference for Programmable SMS or Programmable Voice.

What’s a REST API, anyway?

An API is an application programming interface - in short, it’s a set of rules that lets programs talk to each other, exposing data and functionality across the internet in a consistent format.

REST stands for Representational State Transfer. This is an architectural pattern that describes how distributed systems can expose a consistent interface. When people use the term ‘REST API,’ they are generally referring to an API accessed via HTTP protocol at a predefined set of URLs.

These URLs represent various resources - any information or content accessed at that location, which can be returned as JSON, HTML, audio files, or images. Often, resources have one or more methods that can be performed on them over HTTP, like GET, POST, PUT and DELETE.

Twilio, for example, provides many separate REST APIs for sending text messages, making phone calls, looking up phone numbers, managing your accounts, and a whole lot more. In Twilio’s ecosystem, each product is its own API, but you will work with each of them in roughly the same way, whether over HTTP or using Twilio’s helper libraries for several different programming languages.

Working with Twilio’s APIs

Authenticate with HTTP

Twilio supports HTTP Basic authentication. This allows you to protect the URLs on your web server so that only you and Twilio can access them. In order to authenticate with HTTP, you may provide a username and password with the following URL format:

https://username:password@api.twilio.com/2010-04-01/your_desired_path

For HTTP Basic authentication, you will use your Twilio account SID as your username and your auth token as your password:

curl -G https://api.twilio.com/2010-04-01/Accounts \
    -u '{YOUR ACCOUNT SID}:{YOUR AUTH TOKEN}'

You can find both your account SID and auth token in the Twilio Console after signing up for a free Twilio trial account.

Reveal Your Auth Token

If you want to use API Keys to authenticate instead of your Twilio account SID and auth token, then use the API Key as your username and your API Key's Secret as your password:

curl -G https://api.twilio.com/2010-04-01/Accounts \
    -u '{YOUR API KEY}:{YOUR API KEY SECRET}'

Twilio will authenticate to your web server using the provided username and password and will remain logged in for the duration of the action.

You can learn more about how Twilio handles authentication in our security documentation.

Authenticate using the Twilio SDKs

At this time, Twilio offers six officially supported server-side libraries:

All of these helper libraries come with a Utilities class that facilitates request validation: you simply need to pass your account SID and auth token (found in the Twilio Console) to Twilio’s Client.

Please note: you should always use environment variables to keep your account sid and auth token secret before sharing any code or deploying to production. Check out our guidance for setting environment variables to learn more.

How Twilio’s API uses webhooks

Webhooks are user-defined HTTP callbacks triggered by an event in a web application. Twilio uses webhooks to asynchronously let your application know when events happen, like getting an incoming call or receiving an SMS message.

When the webhook event occurs, Twilio makes an HTTP request (usually POST or GET) to the URL you have configured for your webhook. Twilio’s request to your application includes details of the event like the body of an incoming message or the incoming phone number. Your application can then perform whatever logic is necessary, then reply to Twilio with a response containing the instructions you’d like Twilio to perform.

To handle a webhook when you use Twilio, you need to build a small web application that can accept HTTP requests. Check out our officially supported helper libraries to get up and running quickly.

Explore the APIs

Send an SMS with Twilio’s API

Twilio’s Programmable SMS API helps you send and receive SMS messages. You’ll need to sign up for a free Twilio account to get started.

        
        
        
        This code creates a new instance of the Message resource and sends an HTTP POST to the Messages resource URI.

        Send a simple SMS using the Programmable SMS API

        This code creates a new instance of the Message resource and sends an HTTP POST to the Messages resource URI.

        For a complete step-by-step guide to sending and receiving messages with Twilio, check out our Quickstarts for Programmable SMS. Just select your server-side programming language of choice and dive in:

        Explore Twilio’s other APIs

        Twilio has a number of REST APIs that can help you build powerful communications into your applications, including Programmable Voice, Programmable Video, Wireless, and Authy for two-factor authentication and passwordless login.

        We can’t wait to see what you build!

        Rate this page:

        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 by visiting Twilio's Community Forums or browsing the Twilio tag on Stack Overflow.

              
              
              

              Thank you for your feedback!

              We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

              Sending your feedback...
              🎉 Thank you for your feedback!
              Something went wrong. Please try again.

              Thanks for your feedback!

              Refer us and get $10 in 3 simple steps!

              Step 1

              Get link

              Get a free personal referral link here

              Step 2

              Give $10

              Your user signs up and upgrade using link

              Step 3

              Get $10

              1,250 free SMSes
              OR 1,000 free voice mins
              OR 12,000 chats
              OR more