Skip to contentSkip to navigationSkip to topbar
Page tools
Useful for sharing or LLM
Accelerate development with AI

On this page
Looking for more inspiration?Visit the

HTTP methods for API interactions


To build secure and reliable integrations, you must understand REST API methods. Each HTTP method has a specific purpose. Correct usage ensures predictable behavior and proper error handling for your app.


HTTP methods overview

http-methods-overview page anchor

Twilio's REST API uses standard HTTP methods to perform operations on resources. Each method maps to a specific action that determines how your request is processed:

PurposeHTTP methodActionNever use
Retrieve collectionGETRetrieves a collection of resources of a specific type.
Retrieve resourcesGETRetrieves a specific resource using its SID.
Create collectionPOSTCreates a new resource by sending data to a collection endpoint.
Update resourcesPOSTUpdates an existing resource using its SID.GET,PUT,PATCH
Remove resourcesDELETEDeletes an existing resource.

The following examples demonstrate each HTTP method. Select your method to see the request structure:

GET: List resourcesGET: Retrieve a resourcePOST: Create a resourcePOST: Update a resourceDELETE: Delete a resource
Retrieve a collection of resources of a specific typeLink to code sample: Retrieve a collection of resources of a specific type
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID at twilio.com/console
5
// Provision API Keys at twilio.com/console/runtime/api-keys
6
// and set the environment variables. See http://twil.io/secure
7
// For local testing, you can use your Account SID and Auth token
8
const accountSid = process.env.TWILIO_ACCOUNT_SID;
9
const apiKey = process.env.TWILIO_API_KEY;
10
const apiSecret = process.env.TWILIO_API_SECRET;
11
const client = twilio(apiKey, apiSecret, { accountSid: accountSid });
12
13
async function listMessage() {
14
const messages = await client.messages.list({ limit: 20 });
15
16
messages.forEach((m) => console.log(m.end));
17
}
18
19
listMessage();

Response

Note about this response
1
{
2
"end": 1,
3
"first_page_uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages.json?To=%2B123456789&From=%2B987654321&DateSent%3E=2008-01-02&PageSize=2&Page=0",
4
"next_page_uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages.json?To=%2B123456789&From=%2B987654321&DateSent%3E=2008-01-02&PageSize=2&Page=1&PageToken=PAMMc26223853f8c46b4ab7dfaa6abba0a26",
5
"page": 0,
6
"page_size": 2,
7
"previous_page_uri": null,
8
"messages": [
9
{
10
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
11
"api_version": "2010-04-01",
12
"body": "testing",
13
"date_created": "Fri, 24 May 2019 17:44:46 +0000",
14
"date_sent": "Fri, 24 May 2019 17:44:50 +0000",
15
"date_updated": "Fri, 24 May 2019 17:44:50 +0000",
16
"direction": "outbound-api",
17
"error_code": null,
18
"error_message": null,
19
"from": "+12019235161",
20
"messaging_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
21
"num_media": "0",
22
"num_segments": "1",
23
"price": "-0.00750",
24
"price_unit": "USD",
25
"sid": "SMded05904ccb347238880ca9264e8fe1c",
26
"status": "sent",
27
"subresource_uris": {
28
"media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMded05904ccb347238880ca9264e8fe1c/Media.json",
29
"feedback": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMded05904ccb347238880ca9264e8fe1c/Feedback.json"
30
},
31
"to": "+18182008801",
32
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMded05904ccb347238880ca9264e8fe1c.json"
33
},
34
{
35
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
36
"api_version": "2010-04-01",
37
"body": "look mom I have media!",
38
"date_created": "Fri, 24 May 2019 17:44:46 +0000",
39
"date_sent": "Fri, 24 May 2019 17:44:49 +0000",
40
"date_updated": "Fri, 24 May 2019 17:44:49 +0000",
41
"direction": "inbound",
42
"error_code": 30004,
43
"error_message": "Message blocked",
44
"from": "+12019235161",
45
"messaging_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
46
"num_media": "3",
47
"num_segments": "1",
48
"price": "-0.00750",
49
"price_unit": "USD",
50
"sid": "MMc26223853f8c46b4ab7dfaa6abba0a26",
51
"status": "received",
52
"subresource_uris": {
53
"media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/MMc26223853f8c46b4ab7dfaa6abba0a26/Media.json",
54
"feedback": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/MMc26223853f8c46b4ab7dfaa6abba0a26/Feedback.json"
55
},
56
"to": "+18182008801",
57
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/MMc26223853f8c46b4ab7dfaa6abba0a26.json"
58
}
59
],
60
"start": 0,
61
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages.json?To=%2B123456789&From=%2B987654321&DateSent%3E=2008-01-02&PageSize=2&Page=0"
62
}

Twilio returns standardized HTTP status codes that indicate the success or failure of your request. Understanding these codes helps you implement proper error handling and detect security issues:

Success status codes (2xx)

success-status-codes-2xx page anchor
CodeErrorReason
200(link takes you to an external page)OKRequest succeeded; response body contains the resource.
201(link takes you to an external page)CreatedResource creation succeeded. The response body contains the new resource.
204(link takes you to an external page)No ContentRequest succeeded (typically for DELETE) and it doesn't return a response body.

Client error status codes (4xx)

client-error-status-codes-4xx page anchor
CodeErrorReason
400(link takes you to an external page)Bad RequestMalformed request syntax or invalid parameters
401(link takes you to an external page)UnauthorizedMissing, invalid, or expired credentials
403(link takes you to an external page)ForbiddenCredentials are valid but lack permission for this action
404(link takes you to an external page)Not FoundResource does not exist or belongs to a different account
429(link takes you to an external page)Too Many RequestsRate limit or concurrency limit exceeded

Server error status codes (5xx)

server-error-status-codes-5xx page anchor
CodeErrorReason
500(link takes you to an external page)Internal Server ErrorServer error; retry with exponential backoff
503(link takes you to an external page)Service UnavailableTemporary service disruption; retry with exponential backoff

Understanding status codes for security

understanding-status-codes-for-security page anchor

HTTP status codes provide critical information for detecting security issues and API problems.

4xx errors and credential security

4xx-errors-and-credential-security page anchor

Certain responses indicate authentication or authorization problems: 401 (Unauthorized) and 403 (Forbidden).

CodeErrorReasonSecurity implicationRemedy
401(link takes you to an external page)UnauthorizedMissing, invalid, or expired credentialsSudden spikes in 401 errors may indicate credential compromise or token expiration issues.Verify credentials remain correct and haven't expired; rotate if suspicious.
403(link takes you to an external page)ForbiddenCredentials lack permission for the requested actionAccess to endpoints your integration doesn't normally use may indicate unauthorized changes to access policies.Verify API key scopes and permissions; investigate unusual access patterns.

Rate limiting and abuse detection

rate-limiting-and-abuse-detection page anchor

429 Too Many Requests(link takes you to an external page) indicates you've exceeded rate limits or concurrency limits. This may indicate legitimate spike in usage or an unauthorized user making rapid requests.

  • Implement exponential backoff to retry after the rate limit resets.
  • Monitor for sudden 429 spikes that could indicate compromise or abuse.

5xx errors and service issues

5xx-errors-and-service-issues page anchor

500 and 503 errors indicate server-side issues.

  • Implement retry logic with exponential backoff. Don't retry indefinitely.
  • 5xx errors should be rare; frequent 5xx responses may indicate a systemic problem.
  • Distinguish between transient failures, where you would retry, and systemic problems, where you escalate to Twilio Support.

Monitoring and alerting strategy

monitoring-and-alerting-strategy page anchor

Set up monitoring and alerts for these security-relevant patterns:


Best practices for API interactions

best-practices-for-api-interactions page anchor

Implement these practices when making HTTP requests to Twilio APIs:

To perform certain actions, use the following HTTP methods with the Twilio REST API:

PurposeHTTP methodNever use
Retrieve resourcesGET
Create resourcesPOST
Update resourcesPOSTGET, PUT, PATCH
Remove resourcesDELETE

Error handling and retries

error-handling-and-retries page anchor

Security-specific practices

security-specific-practices page anchor

Secure your API interactions and error handling: