Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this pageProducts used

Content API Public Endpoints


(information)

Info

While the Content API supports an unlimited number of templates, WhatsApp limits users to 6000 approved templates. Large parts of this page refer to v1 of the Content API. Template search only applies to v2.

Property nameTypePIIDescription
date_createdstring<date-time>
Not PII

date_updatedstring<date-time>

The date and time in GMT that the resource was last updated specified in RFC 2822(link takes you to an external page) format.


sidSID<HX>

The unique string that that we created to identify the Content resource.

Pattern: ^HX[0-9a-fA-F]{32}$Min length: 34Max length: 34

account_sidSID<AC>

The SID of the Account that created Content resource.

Pattern: ^AC[0-9a-fA-F]{32}$Min length: 34Max length: 34

friendly_namestring

A string name used to describe the Content resource. Not visible to the end recipient.


languagestring

Two-letter (ISO 639-1) language code (e.g., en) identifying the language the Content resource is in.


variablesobject

Defines the default placeholder values for variables included in the Content resource. e.g. {"1": "Customer_Name"}.


typesobject

The Content types (e.g. twilio/text) for this Content resource.


urlstring<uri>

The URL of the resource, relative to https://content.twilio.com.


linksobject<uri-map>

A list of links related to the Content resource, such as approval_fetch and approval_create


Creation of Templates

creation-of-templates page anchor

Create Templates

create-templates page anchor

_10
POST https://content.twilio.com/v1/Content

(information)

Info

We recommend that you save the Content SID that can be found in the API response to use for later. This SID is used during send time and in various other requests to identify the template.

Create a Content API Template

create-a-content-api-template page anchor
C#
Java
curl

_45
// Install the C# / .NET helper library from twilio.com/docs/csharp/install
_45
_45
using System;
_45
using Twilio;
_45
using Twilio.Rest.Content.V1;
_45
_45
TwilioClient.Init(accountSid, authToken);
_45
_45
// define the twilio/text type for less rich channels (e.g. SMS)
_45
var twilioText = new TwilioText.Builder();
_45
twilioText.WithBody("Hi {{1}}. Thanks for contacting Owl Air Support. How can we help?");
_45
_45
// define the twilio/quick-reply type for more rich channels
_45
var twilioQuickReply = new TwilioQuickReply.Builder();
_45
twilioQuickReply.WithBody("Owl Air Support");
_45
var quickreply1 = new QuickReplyAction.Builder()
_45
.WithTitle("Contact Us")
_45
.WithId("flightid1")
_45
.Build();
_45
var quickreply2 = new QuickReplyAction.Builder()
_45
.WithTitle("Check gate number")
_45
.WithId("gateid1")
_45
.Build();
_45
var quickreply3 = new QuickReplyAction.Builder()
_45
.WithTitle("Speak with an agent")
_45
.WithId("agentid1")
_45
.Build();
_45
twilioQuickReply.WithActions(new List<QuickReplyAction>() { quickreply1, quickreply2, quickreply3 });
_45
_45
// define all the content types to be part of the template
_45
var types = new Types.Builder();
_45
types.WithTwilioText(twilioText.Build());
_45
types.WithTwilioQuickReply(twilioQuickReply.Build());
_45
_45
// build the create request object
_45
var contentCreateRequest = new ContentCreateRequest.Builder();
_45
contentCreateRequest.WithTypes(types.Build());
_45
contentCreateRequest.WithLanguage("en");
_45
contentCreateRequest.WithFriendlyName("owl_air_qr");
_45
contentCreateRequest.WithVariables(new Dictionary<string, string>() { {"1", "John"} });
_45
_45
// create the twilio template
_45
var contentTemplate = await CreateAsync(contentCreateRequest.Build());
_45
_45
Console.WriteLine($"Created Twilio Content Template SID: {contentTemplate.Sid}");

Output

_38
{
_38
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_38
"date_created": "2022-08-29T10:43:20Z",
_38
"date_updated": "2022-08-29T10:43:20Z",
_38
"friendly_name": "owl_air_qr",
_38
"language": "en",
_38
"links": {
_38
"approval_create": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/ApprovalRequests/whatsapp",
_38
"approval_fetch": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/ApprovalRequests"
_38
},
_38
"sid": "HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_38
"types": {
_38
"twilio/text": {
_38
"body": "Hi, {{ 1 }}. \n Thanks for contacting Owl Air Support. How can I help?."
_38
},
_38
"twilio/quick-reply": {
_38
"body": "Hi, {{ 1 }}. \n Thanks for contacting Owl Air Support. How can I help?",
_38
"actions": [
_38
{
_38
"id": "flightid1",
_38
"title": "Check flight status"
_38
},
_38
{
_38
"id": "gateid1",
_38
"title": "Check gate number"
_38
},
_38
{
_38
"id": "agentid1",
_38
"title": "Speak with an agent"
_38
}
_38
]
_38
}
_38
},
_38
"url": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_38
"variables": {
_38
"1": "Owl Air Customer"
_38
}
_38
}


Fetch Information About Templates

fetch-information-about-templates page anchor

Fetch a Content Resource

fetch-a-content-resource page anchor

_10
GET https://content.twilio.com/v1/Content/{ContentSid}

Retrieve information about a single Content API template.

Property nameTypeRequiredPIIDescription
SidSID<HX>required

The Twilio-provided string that uniquely identifies the Content resource to fetch.

Pattern: ^HX[0-9a-fA-F]{32}$Min length: 34Max length: 34

Fetch a Content API Resource

fetch-a-content-api-resource page anchor

Review an individual template created using Content API

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_18
// Download the helper library from https://www.twilio.com/docs/node/install
_18
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_18
_18
// Find your Account SID and Auth Token at twilio.com/console
_18
// and set the environment variables. See http://twil.io/secure
_18
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_18
const authToken = process.env.TWILIO_AUTH_TOKEN;
_18
const client = twilio(accountSid, authToken);
_18
_18
async function fetchContent() {
_18
const content = await client.content.v1
_18
.contents("HXaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_18
.fetch();
_18
_18
console.log(content.dateCreated);
_18
}
_18
_18
fetchContent();

Output

_26
{
_26
"sid": "HXaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_26
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_26
"friendly_name": "Some content",
_26
"language": "en",
_26
"variables": {
_26
"name": "foo"
_26
},
_26
"types": {
_26
"twilio/text": {
_26
"body": "Foo Bar Co is located at 39.7392, 104.9903"
_26
},
_26
"twilio/location": {
_26
"longitude": 104.9903,
_26
"latitude": 39.7392,
_26
"label": "Foo Bar Co"
_26
}
_26
},
_26
"url": "https://content.twilio.com/v1/Content/HXaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_26
"date_created": "2015-07-30T19:00:00Z",
_26
"date_updated": "2015-07-30T19:00:00Z",
_26
"links": {
_26
"approval_create": "https://content.twilio.com/v1/Content/HXaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/ApprovalRequests/whatsapp",
_26
"approval_fetch": "https://content.twilio.com/v1/Content/HXaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/ApprovalRequests"
_26
}
_26
}

Search Parameters
FiltersNumber of FiltersBehavior
LanguageMultiplePick multiple options of supported languages that matches the template's language field.
ContentTypeMultiplePick multiple options of supported content types. This checks for the existence of contenttype fields e.g. twilio/text
ChannelEligibilityMultiplePick multiple options of the supported {channel}:{template_status} format which refers to the approval_content.channel.status field
ContentSingleCase-insensitive search pattern in the body, title, sub_title, friendly_name, approval_content.channel.name fields. Max character length: 1024. Max number of words: 100. Document will return with 100% match. Matches the order of words in friendly_name, approval_content.whatsapp.name.
ContentNameSinglePattern to search for in the friendly_name (content template name) and approval_content.channel.name fields. Max character length: 450. Max number of words allowed: 100.
DateCreatedBeforeSingleDate and time value before template creation to be used in your content templates search. Format example: DateCreatedBefore=YYYY-MM-DDThh:mm:ssZ
DateCreatedAfterSingleDate and time value after template creation to be used in your content templates search. Format example: DateCreatedAfter=YYYY-MM-DDThh:mm:ssZ
DateCreatedBefore, DateCreatedAfterSingleSpecify a datetime range for your content templates search. Format example: DateCreatedBefore=YYYY-MM-DDThh:mm:ssZ&DateCreatedAfter=YYYY-MM-DDThh:mm:ssZ

_10
GET "https://content.twilio.com/v2/Content?PageSize=100&Content=hello"


_10
GET "https://content.twilio.com/v2/ContentAndApprovals?ChannelEligibility=whatsapp:unsubmitted&Language=en"

Fetch all Content Resources

fetch-all-content-resources page anchor

_10
GET "https://content.twilio.com/v1/Content"

Retrieve information about a single Content API template.

  • Pagination is supported in this endpoint.
curl

_10
curl -X GET "https://content.twilio.com/v1/Content"
_10
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN

Output

_84
{
_84
"meta": {
_84
"page": 0,
_84
"page_size": 50,
_84
"first_page_url": "https://content.twilio.com/v1/Content?PageSize=50&Page=0",
_84
"previous_page_url": null,
_84
"url": "https://content.twilio.com/v1/Content?PageSize=50&Page=0",
_84
"next_page_url": "https://content.twilio.com/v1/Content?PageSize=50&Page=1&PageToken=DNHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-1678723520",
_84
"key": "contents"
_84
},
_84
"contents": [
_84
{
_84
"language": "en",
_84
"date_updated": "2023-03-31T16:06:50Z",
_84
"variables": {
_84
"1": "07:00",
_84
"3": "owl.jpg",
_84
"2": "03/01/2023"
_84
},
_84
"friendly_name": "whatsappcard2",
_84
"account_sid": "ACXXXXXXXXXXXXXXX",
_84
"url": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_84
"sid": "HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_84
"date_created": "2023-03-31T16:06:50Z",
_84
"types": {
_84
"twilio/card": {
_84
"body": null,
_84
"media": [
_84
"https://twilio.example.com/{{3}}"
_84
],
_84
"subtitle": null,
_84
"actions": [
_84
{
_84
"index": 0,
_84
"type": "QUICK_REPLY",
_84
"id": "Stop",
_84
"title": "Stop Updates"
_84
}
_84
],
_84
"title": "See you at {{1}} on {{2}}. Thank you."
_84
}
_84
},
_84
"links": {
_84
"approval_fetch": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/ApprovalRequests",
_84
"approval_create": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/ApprovalRequests/whatsapp"
_84
}
_84
},
_84
{
_84
"language": "en",
_84
"date_updated": "2023-03-31T15:50:24Z",
_84
"variables": {
_84
"1": "07:00",
_84
"2": "03/01/2023"
_84
},
_84
"friendly_name": "whatswppward_01234",
_84
"account_sid": "ACXXXXXXXXXXXXXXX",
_84
"url": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_84
"sid": "HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_84
"date_created": "2023-03-31T15:50:24Z",
_84
"types": {
_84
"twilio/card": {
_84
"body": null,
_84
"media": [
_84
"https://twilio.example.com/owl.jpg"
_84
],
_84
"subtitle": null,
_84
"actions": [
_84
{
_84
"index": 0,
_84
"type": "QUICK_REPLY",
_84
"id": "Stop",
_84
"title": "Stop Updates"
_84
}
_84
],
_84
"title": "See you at {{1}} on {{2}}. Thank you."
_84
}
_84
},
_84
"links": {
_84
"approval_fetch": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/ApprovalRequests",
_84
"approval_create": "https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/ApprovalRequests/whatsapp"
_84
}
_84
}
_84
]
_84
}

Fetch Content and Approvals

fetch-content-and-approvals page anchor

_10
GET https://content.twilio.com/v1/ContentAndApprovals

Retrieve information about templates and their approval status.

  • Pagination is supported in this endpoint.

All WA approval statuses can be found here.

Retrieve information about templates and their approval status

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_18
// Download the helper library from https://www.twilio.com/docs/node/install
_18
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_18
_18
// Find your Account SID and Auth Token at twilio.com/console
_18
// and set the environment variables. See http://twil.io/secure
_18
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_18
const authToken = process.env.TWILIO_AUTH_TOKEN;
_18
const client = twilio(accountSid, authToken);
_18
_18
async function listContentAndApprovals() {
_18
const contentAndApprovals = await client.content.v1.contentAndApprovals.list({
_18
limit: 20,
_18
});
_18
_18
contentAndApprovals.forEach((c) => console.log(c.dateCreated));
_18
}
_18
_18
listContentAndApprovals();

Output

_12
{
_12
"contents": [],
_12
"meta": {
_12
"page": 0,
_12
"page_size": 10,
_12
"first_page_url": "https://content.twilio.com/v1/ContentAndApprovals?PageSize=10&Page=0",
_12
"previous_page_url": null,
_12
"next_page_url": null,
_12
"url": "https://content.twilio.com/v1/ContentAndApprovals?PageSize=10&Page=0",
_12
"key": "contents"
_12
}
_12
}

Fetch Mapping between Legacy WA and Content Templates

fetch-mapping-between-legacy-wa-and-content-templates page anchor

_10
GET https://content.twilio.com/v1/LegacyContent

For customers that have had their templates synced over from WA templates you can retrieve a mapping between all the templates, their language and body text and their new Content Sids.

  • Pagination is supported in this endpoint.

Fetch Legacy WA Content Mapping

fetch-legacy-wa-content-mapping page anchor

Fetch mapping between legacy WA templates and Content API templates

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_18
// Download the helper library from https://www.twilio.com/docs/node/install
_18
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_18
_18
// Find your Account SID and Auth Token at twilio.com/console
_18
// and set the environment variables. See http://twil.io/secure
_18
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_18
const authToken = process.env.TWILIO_AUTH_TOKEN;
_18
const client = twilio(accountSid, authToken);
_18
_18
async function listLegacyContent() {
_18
const legacyContents = await client.content.v1.legacyContents.list({
_18
limit: 20,
_18
});
_18
_18
legacyContents.forEach((l) => console.log(l.dateCreated));
_18
}
_18
_18
listLegacyContent();

Output

_12
{
_12
"contents": [],
_12
"meta": {
_12
"page": 0,
_12
"page_size": 10,
_12
"first_page_url": "https://content.twilio.com/v1/LegacyContent?PageSize=10&Page=0",
_12
"previous_page_url": null,
_12
"url": "https://content.twilio.com/v1/LegacyContent?PageSize=10&Page=0",
_12
"next_page_url": null,
_12
"key": "contents"
_12
}
_12
}

For endpoints where pagination is supported you can append the following parameters to the request URL to paginate the results.

  • PageSize: Limit 1000
  • PageToken: Equivalent to page number starting with page=0

Delete a Content Resource

delete-a-content-resource page anchor

_10
DELETE https://content.twilio.com/v1/Content/{ContentSid}

Property nameTypeRequiredPIIDescription
SidSID<HX>required

The Twilio-provided string that uniquely identifies the Content resource to fetch.

Pattern: ^HX[0-9a-fA-F]{32}$Min length: 34Max length: 34

Delete a template using Content API

delete-a-template-using-content-api page anchor

Delete an individual template using the Content API

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_14
// Download the helper library from https://www.twilio.com/docs/node/install
_14
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_14
_14
// Find your Account SID and Auth Token at twilio.com/console
_14
// and set the environment variables. See http://twil.io/secure
_14
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_14
const authToken = process.env.TWILIO_AUTH_TOKEN;
_14
const client = twilio(accountSid, authToken);
_14
_14
async function deleteContent() {
_14
await client.content.v1.contents("HXXXXXXXX").remove();
_14
}
_14
_14
deleteContent();


Submit Templates for Approval

submit-templates-for-approval page anchor

Submit Template Approval for WhatsApp

submit-template-approval-for-whatsapp page anchor
(information)

Info

By default, to send outbound messages to WhatsApp users, a template approval by WhatsApp is required. However, if a WhatsApp user sends an inbound message, then a 24-hour messaging session is initiated and certain outbound rich content types can be sent without a template during the 24-hour session.

For details regarding which content types require approval and 24-hour session limitations, please refer to the following chart.

To use your content template on WhatsApp, you can request approval by submitting a request along with additional information required by WhatsApp. To ensure your WhatsApp templates are approved please see our guide WhatsApp Notification Messages with Templates. Approval by WhatsApp typically takes 1 business day.


_10
POST https://content.twilio.com/v1/Content/{ContentSid}/ApprovalRequests/WhatsApp

content_sid:

  • Type: String
  • Required: Yes
  • Description: content_sid corresponding to the Content resource you want to submit for approval.

Additional parameters required by WhatsApp

additional-parameters-required-by-whatsapp page anchor

name:

  • Type: String
  • Required: Yes
  • Description: Name that uniquely identifies the Content.

    • Only lowercase alphanumeric characters or underscores.

category:

allow_category_change:

  • Type: Boolean
  • Required: No - Defaults to True
  • Description: If you wish to force the category not to be updated and possibly have the template rejected you may set this to false. The template may require an appeal to be approved with the set category.

Submit a Template for WhatsApp Approval

submit-a-template-for-whatsapp-approval page anchor
curl

_10
curl -X POST 'https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/ApprovalRequests/whatsapp' \
_10
-H 'Content-Type: application/json' \
_10
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN \
_10
-d '{
_10
"name": "flight_replies",
_10
"category": "UTILITY"
_10
}'

Output

_10
{
_10
"category": "TRANSPORTATION_UPDATE",
_10
"status": "received",
_10
"rejection_reason": "",
_10
"name": "flight_replies",
_10
"content_type": "twilio/quick-reply"
_10
}

Fetch an Approval Status Request

fetch-an-approval-status-request page anchor

_10
GET https://content.twilio.com/v1/Content/{ContentSid}/ApprovalRequests

All WA approval statuses can be found here.

Property nameTypeRequiredPIIDescription
SidSID<HX>required

The Twilio-provided string that uniquely identifies the Content resource whose approval information to fetch.

Pattern: ^HX[0-9a-fA-F]{32}$Min length: 34Max length: 34

Fetch an Approval Status Request

fetch-an-approval-status-request-1 page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_19
// Download the helper library from https://www.twilio.com/docs/node/install
_19
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_19
_19
// Find your Account SID and Auth Token at twilio.com/console
_19
// and set the environment variables. See http://twil.io/secure
_19
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_19
const authToken = process.env.TWILIO_AUTH_TOKEN;
_19
const client = twilio(accountSid, authToken);
_19
_19
async function fetchApprovalFetch() {
_19
const approvalFetch = await client.content.v1
_19
.contents("HXaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_19
.approvalFetch()
_19
.fetch();
_19
_19
console.log(approvalFetch.sid);
_19
}
_19
_19
fetchApprovalFetch();

Output

_14
{
_14
"sid": "HXaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_14
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_14
"whatsapp": {
_14
"type": "whatsapp",
_14
"name": "tree_fiddy",
_14
"category": "ACCOUNT_UPDATE",
_14
"content_type": "twilio/location",
_14
"status": "approved",
_14
"rejection_reason": "",
_14
"allow_category_change": true
_14
},
_14
"url": "https://content.twilio.com/v1/Content/HXaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/ApprovalRequests"
_14
}


Template Status Change Alerts

template-status-change-alerts page anchor

Twilio now supports new error codes for "Alarms", "Rejected", and "Paused" WhatsApp Templates. With Twilio Alarms, you can now get notified via webhook or email when these and other errors occur. Approved alarms are also available as a Beta feature.

Learn more here(link takes you to an external page).


Send a Message with Preconfigured Content

send-a-message-with-preconfigured-content page anchor

_10
POST https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Messages

New parameters in the Programmable Messaging API

Data Parameters

To send messages you will use the content SID message body and your Twilio account SID in the POST request URL. For templates that use variables, please specify these variables in the POST request to send messages.

Key Info

  • To
  • From
  • MessagingServiceSid
  • Body
Property nameTypeRequiredPIIDescription
AccountSidSID<AC>required

The SID of the Account creating the Message resource.

Pattern: ^AC[0-9a-fA-F]{32}$Min length: 34Max length: 34
Property nameTypeRequiredPIIDescription
Tostring<phone-number>required
PII MTL: 120 days

The recipient's phone number in E.164 format (for SMS/MMS) or channel address, e.g. whatsapp:+15552229999.


StatusCallbackstring<uri>Optional

The URL of the endpoint to which Twilio sends Message status callback requests. URL must contain a valid hostname and underscores are not allowed. If you include this parameter with the messaging_service_sid, Twilio uses this URL instead of the Status Callback URL of the Messaging Service.


ApplicationSidSID<AP>Optional

The SID of the associated TwiML Application. Message status callback requests are sent to the TwiML App's message_status_callback URL. Note that the status_callback parameter of a request takes priority over the application_sid parameter; if both are included application_sid is ignored.

Pattern: ^AP[0-9a-fA-F]{32}$Min length: 34Max length: 34

MaxPricenumberOptional

[OBSOLETE] This parameter will no longer have any effect as of 2024-06-03.


ProvideFeedbackbooleanOptional

Boolean indicating whether or not you intend to provide delivery confirmation feedback to Twilio (used in conjunction with the Message Feedback subresource). Default value is false.


AttemptintegerOptional

Total number of attempts made (including this request) to send the message regardless of the provider used


ValidityPeriodintegerOptional

The maximum length in seconds that the Message can remain in Twilio's outgoing message queue. If a queued Message exceeds the validity_period, the Message is not sent. Accepted values are integers from 1 to 36000. Default value is 36000. A validity_period greater than 5 is recommended. Learn more about the validity period(link takes you to an external page)


ForceDeliverybooleanOptional

Reserved


ContentRetentionenum<string>Optional

Determines if the message content can be stored or redacted based on privacy settings

Possible values:
retaindiscard

AddressRetentionenum<string>Optional

Determines if the address can be stored or obfuscated based on privacy settings

Possible values:
retainobfuscate

SmartEncodedbooleanOptional

Whether to detect Unicode characters that have a similar GSM-7 character and replace them. Can be: true or false.


PersistentActionarray[string]Optional

Rich actions for non-SMS/MMS channels. Used for sending location in WhatsApp messages.


ShortenUrlsbooleanOptional

For Messaging Services with Link Shortening configured only: A Boolean indicating whether or not Twilio should shorten links in the body of the Message. Default value is false. If true, the messaging_service_sid parameter must also be provided.


ScheduleTypeenum<string>Optional

For Messaging Services only: Include this parameter with a value of fixed in conjuction with the send_time parameter in order to schedule a Message.

Possible values:
fixed

SendAtstring<date-time>Optional

The time that Twilio will send the message. Must be in ISO 8601 format.


SendAsMmsbooleanOptional

If set to true, Twilio delivers the message as a single MMS message, regardless of the presence of media.


ContentVariablesstringOptional

For Content Editor/API only: Key-value pairs of Template variables and their substitution values. content_sid parameter must also be provided. If values are not defined in the content_variables parameter, the Template's default placeholder values are used.


RiskCheckenum<string>Optional

Include this parameter with a value of disable to skip any kind of risk check on the respective message request.

Possible values:
enabledisable

Fromstring<phone-number>required if MessagingServiceSid is not passed

The sender's Twilio phone number (in E.164(link takes you to an external page) format), alphanumeric sender ID, Wireless SIM, short code(link takes you to an external page), or channel address (e.g., whatsapp:+15554449999). The value of the from parameter must be a sender that is hosted within Twilio and belongs to the Account creating the Message. If you are using messaging_service_sid, this parameter can be empty (Twilio assigns a from value from the Messaging Service's Sender Pool) or you can provide a specific sender from your Sender Pool.


MessagingServiceSidSID<MG>required if From is not passed

The SID of the Messaging Service you want to associate with the Message. When this parameter is provided and the from parameter is omitted, Twilio selects the optimal sender from the Messaging Service's Sender Pool. You may also provide a from parameter if you want to use a specific Sender from the Sender Pool.

Pattern: ^MG[0-9a-fA-F]{32}$Min length: 34Max length: 34

Bodystringrequired if MediaUrl or ContentSid is not passed

The text content of the outgoing message. Can be up to 1,600 characters in length. SMS only: If the body contains more than 160 GSM-7 characters (or 70 UCS-2 characters), the message is segmented and charged accordingly. For long body text, consider using the send_as_mms parameter(link takes you to an external page).


MediaUrlarray[string<uri>]required if Body or ContentSid is not passed

The URL of media to include in the Message content. jpeg, jpg, gif, and png file types are fully supported by Twilio and content is formatted for delivery on destination devices. The media size limit is 5 MB for supported file types (jpeg, jpg, png, gif) and 500 KB for other types of accepted media. To send more than one image in the message, provide multiple media_url parameters in the POST request. You can include up to ten media_url parameters per message. International(link takes you to an external page) and carrier(link takes you to an external page) limits apply.


ContentSidSID<HX>required if Body or MediaUrl is not passed

For Content Editor/API only: The SID of the Content Template to be used with the Message, e.g., HXXXXXXXXXXXXXXXXXXXXXXXXXXXXX. If this parameter is not provided, a Content Template is not used. Find the SID in the Console on the Content Editor page. For Content API users, the SID is found in Twilio's response when creating the Template or by fetching your Templates.

Pattern: ^HX[0-9a-fA-F]{32}$Min length: 34Max length: 34

Send a Message with Preconfigured Content

send-a-message-with-preconfigured-content-1 page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_24
// Download the helper library from https://www.twilio.com/docs/node/install
_24
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_24
_24
// Find your Account SID and Auth Token at twilio.com/console
_24
// and set the environment variables. See http://twil.io/secure
_24
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_24
const authToken = process.env.TWILIO_AUTH_TOKEN;
_24
const client = twilio(accountSid, authToken);
_24
_24
async function createMessage() {
_24
const message = await client.messages.create({
_24
contentSid: "HXXXXXXXX",
_24
contentVariables: JSON.stringify({
_24
1: "YOUR_VARIABLE1",
_24
2: "YOURVARIABLE2",
_24
}),
_24
from: "MGXXXXXXXXX",
_24
to: "whatsapp:+18005551234",
_24
});
_24
_24
console.log(message.sid);
_24
}
_24
_24
createMessage();

Output

_28
{
_28
"account_sid": "ACXXXXXXXXX",
_28
"api_version": "2010-04-01",
_28
"body": "Hello! 👍",
_28
"date_created": "Thu, 24 Aug 2023 05:01:45 +0000",
_28
"date_sent": "Thu, 24 Aug 2023 05:01:45 +0000",
_28
"date_updated": "Thu, 24 Aug 2023 05:01:45 +0000",
_28
"direction": "outbound-api",
_28
"error_code": null,
_28
"error_message": null,
_28
"from": "MGXXXXXXXXX",
_28
"num_media": "0",
_28
"num_segments": "1",
_28
"price": null,
_28
"price_unit": null,
_28
"messaging_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_28
"sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_28
"status": "queued",
_28
"subresource_uris": {
_28
"media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Media.json"
_28
},
_28
"tags": {
_28
"campaign_name": "Spring Sale 2022",
_28
"message_type": "cart_abandoned"
_28
},
_28
"to": "whatsapp:+18005551234",
_28
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
_28
}

(warning)

Warning

The From field in the POST request to the Programmable Messaging API must include a Messaging Service that includes a WhatsApp or Facebook Messenger sender.

Send Templates Using Status Callbacks

send-templates-using-status-callbacks page anchor

Status Callback URLs can be set for all messages in a Messaging Service(link takes you to an external page) (under the Integration settings for a specific Messaging Service) or when you send an individual outbound message, by including the StatusCallback parameter. For more information about Status Callback URLs see Monitor the Status of your WhatsApp Outbound Message section.


_10
-d "StatusCallback=http://postb.in/1234abcd" \

Send Messages Scheduled ahead of Time

send-messages-scheduled-ahead-of-time page anchor

With Templates, you can schedule SMS, MMS, and WhatsApp messages to be sent at a fixed time in the future.

Scheduling a message is free; you'll only pay for a message once it is sent.

To learn more about Message Scheduling, see this page.


_10
--data-urlencode "SendAt=2021-11-30T20:36:27Z" \
_10
--data-urlencode "ScheduleType=fixed" \

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_26
// Download the helper library from https://www.twilio.com/docs/node/install
_26
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_26
_26
// Find your Account SID and Auth Token at twilio.com/console
_26
// and set the environment variables. See http://twil.io/secure
_26
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_26
const authToken = process.env.TWILIO_AUTH_TOKEN;
_26
const client = twilio(accountSid, authToken);
_26
_26
async function createMessage() {
_26
const message = await client.messages.create({
_26
contentSid: "HXXXXXXXXXXXXXXX",
_26
contentVariables: JSON.stringify({
_26
1: "YOUR_VARIABLE1",
_26
2: "YOURVARIABLE2",
_26
}),
_26
messagingServiceSid: "MGXXXXXXXXXXX",
_26
scheduleType: "fixed",
_26
sendAt: new Date("2023-11-30 20:36:27"),
_26
to: "whatsapp:+18005551234",
_26
});
_26
_26
console.log(message.body);
_26
}
_26
_26
createMessage();

Output

_28
{
_28
"account_sid": "ACXXXXXXXXXX",
_28
"api_version": "2010-04-01",
_28
"body": "Hello! 👍",
_28
"date_created": "Thu, 24 Aug 2023 05:01:45 +0000",
_28
"date_sent": "Thu, 24 Aug 2023 05:01:45 +0000",
_28
"date_updated": "Thu, 24 Aug 2023 05:01:45 +0000",
_28
"direction": "outbound-api",
_28
"error_code": null,
_28
"error_message": null,
_28
"from": "+14155552345",
_28
"num_media": "0",
_28
"num_segments": "1",
_28
"price": null,
_28
"price_unit": null,
_28
"messaging_service_sid": "MGXXXXXXXXXXX",
_28
"sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_28
"status": "queued",
_28
"subresource_uris": {
_28
"media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Media.json"
_28
},
_28
"tags": {
_28
"campaign_name": "Spring Sale 2022",
_28
"message_type": "cart_abandoned"
_28
},
_28
"to": "whatsapp:+18005551234",
_28
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
_28
}


Rate this page: