API Mechanics
API Versions
The Communications API is versioned.
The version is specified in the URL path, immediately after the hostname. Thus, all API endpoints are versioned together.
For example, in the URL https://comms.twilio.com/v1/Messages, the version is v1.
Mainline Versions (v1, v2, etc.)
Communications API versions are released periodically with monotonically increasing integers with โvโ prefix, e.g. v1.
https://comms.twilio.com/v1.
Try It Now
For previous versions, see the API Changelog.
Operations & HTTP 202 Responses
The Communications API exposes several โfactoryโ API endpoints that create and start asynchronous jobs.
These API endpoints return an HTTP 202 (Accepted) success response which indicates that the workload has been accepted for processing.
- To track the progress of your workload, the API provides an HTTP response header
operation-id. - This header contains a unique identifier for the
Operationthat represents the async job. - You can use the
operation-idandoperation-locationheaders to query the status of your job by fetching the correspondingOperationresource. - Once the job is complete, the
Operationwill have statuscompleted.
The resource-location header from the 202 response points to where the resultant resources of the โfactoryโ endpoint can be retrieved.
Operation Example: Send Messages
Related Resources
The Communications API provides a field on many API resources with the name related.
This field contains an array of related resources,
making it easier to navigate to associated data and understand relationships.
For example, when retrieving a Message resource, t
he response contains a related field with the associated Session resource:
Tags
Many resources in the Communications API have a tags field. This field contains up to 10 simple key-value pairs that the API user may write and read to associate custom metadata with their API resources.
For example, here is an Audience with tags:
Events & Webhooks
To handle asynchronous events, Twilio provides Event Streams API.
Event Streams API provides access to a unified stream of every interaction sent or received on Twilio.
Event Streams supports streaming events to multiple sinks (destinations) and different types of delivery mechanisms, including:
- Webhooks
- Amazon Kinesis
- Twilio Segment
To see a list of all events generated by the Communications API, visit Communications API Events.
Pagination
The Communications API uses cursor-based pagination for list endpoints.
When listing resources, the response includes a pagination field with the pagination information.
The pagination fields in a list Response are:
For example, when fetching a page of Messages, the response will contain:
The pagination query parameters are:
Supply with a valid page token (acquired from previous request) to set your cursor.
Number of resources to retrieve [1-1000], default: 50
To retrieve the โnextโ page of Messages get the value in the response body pagination.next field and issue:
The number of items to retrieve can be controlled with the page_size query parameter.
Errors
The Communications API uses standard HTTP status codes to indicate the success or failure of an API request.
Error HTTP Responses (400s and 500s)
When the Communications API returns an error (HTTP status code 4xx or 5xx), the response body contains the following field:
Each element of the errors array has the following fields:
For example when supplying an invalid value to the query parameter channel when listing Messages: