A list of links related to the Content resource, such as approval_fetch and approval_create
Creation of Templates
Create Templates
_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 Content API Templates
Code sample for creating a template using content API
curl
_30
curl -X POST 'https://content.twilio.com/v1/Content' \
_30
-H 'Content-Type: application/json' \
_30
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN \
_30
-d '{
_30
"friendly_name": "flight_replies",
_30
"language": "en",
_30
"variables": {"1":"Owl Air Customer"},
_30
"types": {
_30
"twilio/quick-reply": {
_30
"body": "Hi, {{1}} 👋 \nThanks for contacting Owl Air Support. How can I help?",
_30
"actions": [
_30
{
_30
"title": "Check flight status",
_30
"id": "flightid1"
_30
},
_30
{
_30
"title": "Check gate number",
_30
"id": "gateid1"
_30
},
_30
{
_30
"title": "Speak with an agent",
_30
"id": "agentid1"
_30
}
_30
]
_30
},
_30
"twilio/text": {
_30
"body": "Hi, {{1}}. \n Thanks for contacting Owl Air Support. How can I help?."
"body": "Hi there, {{1}}, we have received your request to upload {{2}}, and should be uploaded shortly.",
_99
"media": [
_99
"http://example.com/highlights/{{3}}"
_99
]
_99
}
_99
},
_99
"approval_requests": {
_99
"category": "TRANSACTIONAL",
_99
"status": "rejected",
_99
"rejection_reason": "INVALID_FORMAT. Facebook is not able to create template with templateName=Video Highlights_hx15c711fcc6d9ea5268d7ab77938a20ff due to the following error: Invalid parameter. More Details: Message template 'components' param is missing expected field(s). component of type HEADER is missing expected field(s) (example)",
Fetch Mapping between Legacy WA and Content Templates
_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 mapping between legacy WA templates and Content API templates
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl
_10
// Download the helper library from https://www.twilio.com/docs/node/install
_10
// Find your Account SID and Auth Token at twilio.com/console
_10
// and set the environment variables. See http://twil.io/secure
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
Path Parameters
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
name:
Type: String
Required: Yes
Description: Name that uniquely identifies the Content.
Only lowercase alphanumeric characters or underscores.
category:
Type: String (enum)
Required - Yes
Description - Use case category the Content corresponds to, as defined by WhatsApp
WhatsApp Categories:
UTILITY
MARKETING
AUTHENTICATION
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 Content API Template for WhatsApp Approval
curl
_10
curl -X POST 'https://content.twilio.com/v1/Content/HXXXXXXXXXXXXXXXXXXX/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
_10
GET https://content.twilio.com/v1/Content/{ContentSid}/ApprovalRequests
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.
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.
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.
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.
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.
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 14400. Default value is 14400. A validity_period greater than 5 is recommended. Learn more about the validity period
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.
The sender's Twilio phone number (in E.164 format), alphanumeric sender ID, Wireless SIM, short code, 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.
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.
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.
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 and carrier limits apply.
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.
Send a Message with Preconfigured Content
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
// Find your Account SID and Auth Token at twilio.com/console
_18
// and set the environment variables. See http://twil.io/secure
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
Status Callback URLs can be set for all messages in a Messaging Service (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
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.