Menu

Expand
Rate this page:

Make an HTTP Request to Twilio

There are a lot of ways you can make an HTTP request to the Twilio API. You can make a raw HTTP request in your code (for example, using a module like got in NodeJS) or by using a tool like Postman. You might find it easier to use the Twilio Helper Library or SDK for your preferred programming language - even if that's $bash, and you need to use the Twilio CLI.

Credentials

All requests to Twilio's REST API need to be authenticated. Twilio supports two forms of authentication, both using HTTP basic auth, which use the following username/password schemes:

Account SID and Auth Token

The account SID and auth token are the master keys to your account. They can be found on your Account Dashboard in the Twilio Console.

Username Password
AccountSid AuthToken

API Keys

API Keys are credentials you can create and revoke in the Console or using the API using your AccountSid and AuthToken. API Keys are typically safer to work with in your Twilio projects. You can quickly delete them to revoke access if they become compromised and create a fresh API Key for different use cases - so, if you need to turn off a specific use case for some reason, you can just delete the API Key!

Username Password
API Key SID API Key Secret

The examples below will demonstrate how to use both username/password schemes with cURL, Twilio's SDKs, and the Twilio CLI.

HTTP Methods

Twilio mostly uses the GET, POST, and DELETE HTTP methods on various resources. Here's how all of these methods might be used for one of Twilio's most common resources: the SMS Message Resource.

Creating or Updating Resources with the POST Method

You can create or update a resource using the HTTP POST method on a resource URI. All you need to provide is the description of what it is that you want to make! The Twilio helper libraries are useful for making these requests simpler, but you can see the parameters for any post request in the documentation for a resource. Here's a POST request that will create and send an SMS using the Twilio API.

Loading Code Sample...
        
        
        Using Account SID and Auth Token for Authentication

        POST a New Message via SMS

        Using Account SID and Auth Token for Authentication
        Loading Code Sample...
              
              
              Using API Key SID and Secret for Authentication

              POST a New Message via SMS

              Using API Key SID and Secret for Authentication

              Retrieving Resources with the GET Method

              Congrats on sending a message! You can see in the output that you'll receive a Message SID that looks something like MM followed by a long string of letters and numbers. In the sample output, it's just a long string of X's. You can use that SID to retrieve information about the message using the GET method.

              Loading Code Sample...
                    
                    
                    Using Account SID and Auth Token for Authentication

                    GET the sent SMS

                    Using Account SID and Auth Token for Authentication
                    Loading Code Sample...
                          
                          
                          Using API Key SID and Secret for Authentication

                          GET the sent SMS

                          Using API Key SID and Secret for Authentication

                          Deleting a Resource with the DELETE Method

                          Finally, there are times where you might want to delete the message. You can use the same Message SID to make an HTTP DELETE request. Note that not all Twilio REST API resources support DELETE.

                          Loading Code Sample...
                                
                                
                                Using Account SID and Auth Token for Authentication

                                DELETE the Message

                                Using Account SID and Auth Token for Authentication
                                Loading Code Sample...
                                      
                                      
                                      Using API Key SID and Secret for Authentication

                                      DELETE the Message

                                      Using API Key SID and Secret for Authentication

                                      Status Codes

                                      As you make these requests, you'll see responses indicating what's happening on the other side of the server. The following is a list of common status codes you'll see in response from the Twilio API, and what they mean.

                                      Status Code Meaning Description
                                      200 OK The request was successful and the response body contains the representation requested.
                                      201 CREATED The request was successful, we created a new resource and the response body contains the representation. This should only appear for POST requests.
                                      202 ACCEPTED The request has been accepted for processing, but the processing has not been completed.
                                      204 OK Used with the DELETE method. The request was successful; the resource was deleted.
                                      302 FOUND A common redirect response; you can GET the representation at the URI in the Location response header.
                                      304 NOT MODIFIED Your client's cached version of the representation is still up to date.
                                      401 UNAUTHORIZED The supplied credentials, if any, are not sufficient to access the resource.
                                      404 NOT FOUND The request resource wasn't found.
                                      405 NOT ALLOWED Typically means you can't DELETE the resource.
                                      429 TOO MANY REQUESTS Your application is sending too many requests too quickly, and you are reaching the concurrency limit of the Twilio API.
                                      500 SERVER ERROR We couldn't return the representation due to an internal server error - this one is Twilio's fault!
                                      503 SERVICE UNAVAILABLE We are temporarily unable to return the representation. Please wait for a bit and try again.
                                      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 Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.

                                      Loading Code Sample...
                                            
                                            
                                            

                                            Thank you for your feedback!

                                            Please select the reason(s) for your feedback. The additional information you provide helps us improve our documentation:

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

                                            Thanks for your feedback!

                                            thanks-feedback-gif