REST API: Twilio's Response

Response Headers

Twilio will respond to every request with two HTTP headers that that give you a little more information about what happened.

Twilio-Request-Id: RQ5cedae4e7e7e4e70937a8198f5d2d1c0
Twilio-Request-Duration: 0.103

The Twilio-Request-Id header provides a unique identifier for your request. If you notice unexplained problems with your request you can provide this ID to Twilio for further investigation.

The Twilio-Request-Duration header specifies the amount of time (in seconds) Twilio spent processing this request. If you notice requests taking a long time, you can use this header to determine how long Twilio believes the request took.

These headers contain useful diagnostic information about every Twilio request. We recommend you log these headers to aid speedy resolution of any Twilio-related issues your application might encounter.

Response Formats

Twilio can respond to your requests with various formats. The most common are detailed below. For special cases and extra formats see the Tips & Tricks section.


By default, Twilio's REST API returns XML, with a root element of <TwilioResponse>. For example, here is the default XML representation of a SMS message:

GET /2010-04-01/Accounts/AC228b9.../SMS/Messages/SM1f0e8ae6ade43cb3c0ce4525424e404f

        <DateCreated>Fri, 13 Aug 2010 01:16:24 +0000</DateCreated>
        <DateUpdated>Fri, 13 Aug 2010 01:16:24 +0000</DateUpdated>
        <Body>A Test Message</Body>


Twilio also supports returning resource representations as JSON. Simply add the .json extension to any resource URI. Here is the above resource represented as JSON:

GET /2010-04-01/Accounts/AC228b9.../SMS/Messages/SM1f0e8ae6ade43cb3c0ce4525424e404f.json

    "sid": "SM1f0e8ae6ade43cb3c0ce4525424e404f",
    "date_created": "Fri, 13 Aug 2010 01:16:24 +0000",
    "date_updated": "Fri, 13 Aug 2010 01:16:24 +0000",
    "date_sent": null,
    "account_sid": "AC228b97a5fe4138be081eaff3c44180f3",
    "to": "+15305431221",
    "from": "+15104564545",
    "body": "A Test Message",
    "status": "queued",
    "api_version": "2010-04-01",
    "price": null,
    "uri": "\/2010-04-01\/Accounts\/AC228ba7a5fe4238be081ea6f3c44186f3\/SMS\/Messages\/SM1f0e8ae6ade43cb3c0ce4525424e404f.json"


Twilio can also return CSV, HTML and other response types. See the Tips & Tricks section for more information.


Twilio returns exceptions in the HTTP response body when something goes wrong. In XML, these appear as a <RestException> element within the <TwilioResponse>. An exception has up to four properties:

Property Description
Status The HTTP status code for the exception.
Message A more descriptive message regarding the exception.
Code (Conditional) An error code to find help for the exception.
MoreInfo (Conditional) The URL of Twilio's documentation for the error code.

If you receive an exception with status code 400 (invalid request), the 'Code' and 'MoreInfo' properties are useful for debugging what went wrong.


Example 1

Here is a simple 404:

  "status": 404,
  "message": "The requested resource was not found"
    <Message>The requested resource was not found</Message>
Example 2

An invalid POST to the Calls resource without a 'To' parameter would return:

  "status": 400,
  "message": "No to number is specified",
  "code": 21201,
  "more_info": "http:\/\/\/docs\/errors\/21201"
    <Message>No to number is specified</Message>

Hypermedia References

One of the core principles of REST is "Hypermedia As The Engine Of Application State." Basically this means that every resource representation obtained from a REST API request must include URIs that identify that resource and the resources related to it. Hence the Twilio REST API returns representations that include various URIs to help you navigate the API.

Every representation contains a self-referencing URI (i.e. the URI used to retrieve it). For example, when you GET an OutgoingCallerId instance resource, its URI is one of the properties returned:

  "sid": "PNe905d7e6b410746a0fb08c57e5a186f3",
  "friendly_name": "(510) 555-5555",
  "phone_number": "+15105555555",
  "date_created": "Tue, 27 Jul 2010 20:21:11 +0000",
  "date_updated": "Tue, 27 Jul 2010 20:21:11 +0000",
  "uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/OutgoingCallerIds\/PNe905d7e6b410746a0fb08c57e5a186f3.json"
    <FriendlyName>(510) 555-5555</FriendlyName>
    <DateCreated>Tue, 27 Jul 2010 20:21:11 +0000</DateCreated>
    <DateUpdated>Tue, 27 Jul 2010 20:21:11 +0000</DateUpdated>

Hypermedia in List Resources

There is extra hypermedia reference information related to the paging information included in list resource representations. Details are in the Paging Information section below.

Hypermedia in Instance Resources

If an instance resource has subresources, its representation will include the URIs for those resources within a subresource URIs property. For example, notice the subresources returned when GETting a Call instance resource:

  "sid": "CAe1644a7eed5088b159577c5802d8be38",
  "date_created": "Tue, 10 Aug 2010 08:02:17 +0000",
  "date_updated": "Tue, 10 Aug 2010 08:02:47 +0000",
  "parent_call_sid": null,
  "to": "+14153855708",
  "from": "+14158141819",
  "phone_number_sid": null,
  "status": "completed",
  "start_time": "Tue, 10 Aug 2010 08:02:31 +0000",
  "end_time": "Tue, 10 Aug 2010 08:02:47 +0000",
  "duration": "16",
  "price": "-0.03000",
  "api_version": "2008-08-01",
  "annotation": null,
  "forwarded_from": null,
  "caller_name": null,
  "uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAe1644a7eed5088b159577c5802d8be38.json",
    "notifications": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAe1644a7eed5088b159577c5802d8be38\/Notifications.json",
    "recordings": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAe1644a7eed5088b159577c5802d8be38\/Recordings.json"
    <DateCreated>Tue, 10 Aug 2010 08:02:17 +0000</DateCreated>
    <DateUpdated>Tue, 10 Aug 2010 08:02:47 +0000</DateUpdated>
    <StartTime>Tue, 10 Aug 2010 08:02:31 +0000</StartTime>
    <EndTime>Tue, 10 Aug 2010 08:02:47 +0000</EndTime>

List Resources

Some resources are lists of other resources. For example, the Calls list resource returns a list of calls. There are several important things to know about using and manipulating these lists.

Paging Information

If lists are long, the API returns partial results in a single "page". The representation includes the following information:

Property Description
uri The URI of the current page.
firstpageuri The URI for the first page of this list.
nextpageuri The URI for the next page of this list.
previouspageuri The URI for the previous page of this list.
page The current page number. Zero-indexed, so the first page is 0.
pagesize How many items are in each page

For example:

  "page": 0,
  "page_size": 50,
  "uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls.json",
  "first_page_uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls.json?Page=0&PageSize=50",
  "previous_page_uri": null,
  "next_page_uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls.json?Page=1&PageSize=50&AfterSid=CA228399228abecca920de212121",
  "calls": [
      "sid": "CA92d4405c9237c4ea04b56cbda88e128c",
      "date_created": "Fri, 13 Aug 2010 01:16:22 +0000",
      "date_updated": "Fri, 13 Aug 2010 01:16:22 +0000",
      "parent_call_sid": null,
      "to": "+15305431221",
      "from": "+15145623443",
      "phone_number_sid": "PNe2d8e63b37f46f2adb16f228afdb9058",
      "status": "queued",
      "start_time": null,
      "end_time": null,
      "duration": null,
      "price": null,
      "api_version": "2010-04-01",
      "forwarded_from": null,
      "caller_name": null,
      "uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CA92d4405c9237c4ea04b56cbda88e128c.json",
      "subresource_uris": {
        "notifications": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CA92d4405c9237c4ea04b56cbda88e128c\/Notifications.json",
        "recordings": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CA92d4405c9237c4ea04b56cbda88e128c\/Recordings.json"
  <Calls page="0" pagesize="50"
      <DateCreated>Fri, 13 Aug 2010 01:16:22 +0000</DateCreated>
      <DateUpdated>Fri, 13 Aug 2010 01:16:22 +0000</DateUpdated>
      <ApiVersion>2010-04-01</ApiVersion> <ForwardedFrom/> <CallerName/>

Paging Through API Resources

When fetching multiple pages of API results, use the provided nextpageuri parameter to retrieve the next page of results. All of the Twilio Helper Libraries use the nextpageuri to page through resources.

The Page parameter (without an AfterSid or PageToken), along with numpages, total, start, end, and lastpageuri properties have been deprecated and will be removed on 8/31/2015. Furthermore, accounts created after 6/16/2015 will no longer have access to these properties by default. You should use the Twilio Helper Libraries or nextpageuri and previouspageuri to navigate through the resources.

You can control the size of pages with the PageSize parameter:

Parameter Description
PageSize How many resources to return in each list page. The default is 50, and the maximum is 1000.

For example, to limit the number of calls returned to five per page:

GET /2010-04-01/Accounts/{AccountSid}/Calls?PageSize=5

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'