Send a message
A Message resource represents an inbound or outbound message.
Send a message
Path parameters
-
The SID of the Account creating the Message resource.
Minimum length is
34
, maximum length is34
. Format should match the following pattern:^AC[0-9a-fA-F]{32}$
.
Body
-
The recipient's phone number in E.164 format (for SMS/MMS) or channel address, e.g.
whatsapp:+15552229999
. -
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 thestatus_callback
parameter of a request takes priority over theapplication_sid
parameter; if both are includedapplication_sid
is ignored.Minimum length is
34
, maximum length is34
. Format should match the following pattern:^AP[0-9a-fA-F]{32}$
. -
[OBSOLETE] This parameter will no longer have any effect as of 2024-06-03.
-
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
. -
Total number of attempts made (including this request) to send the message regardless of the provider used
-
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 from1
to36000
. Default value is36000
. Avalidity_period
greater than5
is recommended. Learn more about the validity period -
Reserved
-
Values are
retain
ordiscard
. -
Values are
retain
orobfuscate
. -
Whether to detect Unicode characters that have a similar GSM-7 character and replace them. Can be:
true
orfalse
. -
Rich actions for non-SMS/MMS channels. Used for sending location in WhatsApp messages.
-
Value is
free
. -
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 isfalse
. Iftrue
, themessaging_service_sid
parameter must also be provided. -
Value is
fixed
. -
The time that Twilio will send the message. Must be in ISO 8601 format.
-
If set to
true
, Twilio delivers the message as a single MMS message, regardless of the presence of media. -
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 thecontent_variables
parameter, the Template's default placeholder values are used. -
Values are
enable
ordisable
. -
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 thefrom
parameter must be a sender that is hosted within Twilio and belongs to the Account creating the Message. If you are usingmessaging_service_sid
, this parameter can be empty (Twilio assigns afrom
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 afrom
parameter if you want to use a specific Sender from the Sender Pool.Minimum length is
34
, maximum length is34
. Format should match the following pattern:^MG[0-9a-fA-F]{32}$
. -
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 longbody
text, consider using the send_as_mms parameter. -
The URL of media to include in the Message content.
jpeg
,jpg
,gif
, andpng
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 multiplemedia_url
parameters in the POST request. You can include up to tenmedia_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.Minimum length is
34
, maximum length is34
. Format should match the following pattern:^HX[0-9a-fA-F]{32}$
.
curl \
--request POST 'https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Messages.json' \
--user "username:password" \
--header "Content-Type: application/x-www-form-urlencoded" \
--data 'To=%2B14155552345&Body=Hello%21+%F0%9F%91%8D&From=%2B14155552345&Tags=%7B%22campaign_name%22%3A+%22Spring+Sale+2022%22%2C%22message_type%22%3A+%22cart_abandoned%22%7D&MediaUrl=https%3A%2F%2Fc1.staticflickr.com%2F3%2F2899%2F14341091933_1e92e62d12_b.jpg&ApplicationSid=APaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&StatusCallback=https%3A%2F%2Fexample.com&PersistentAction=mailto%3Atest%40example.com'
{"To"=>"+14155552345", "Body"=>"Hello! 👍", "From"=>"+14155552345", "Tags"=>"{\"campaign_name\": \"Spring Sale 2022\",\"message_type\": \"cart_abandoned\"}", "MediaUrl"=>["https://c1.staticflickr.com/3/2899/14341091933_1e92e62d12_b.jpg"], "ApplicationSid"=>"APaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "StatusCallback"=>"https://example.com", "PersistentAction"=>["mailto:test@example.com"]}
{"To"=>"+14155552345", "Body"=>"Hello! 👍", "From"=>"+14155552345", "MediaUrl"=>["https://example.com"], "ApplicationSid"=>"APaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "StatusCallback"=>"https://example.com", "PersistentAction"=>["mailto:test@example.com"]}
{"To"=>"+14155552345", "Body"=>"Hello! 👍", "MediaUrl"=>["https://example.com"], "ContentSid"=>"HXaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "ApplicationSid"=>"APaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "StatusCallback"=>"https://example.com", "PersistentAction"=>["mailto:test@example.com"], "MessagingServiceSid"=>"MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}
{"To"=>"+14155552345", "Body"=>"Hello! 👍", "From"=>"+14155552345", "MediaUrl"=>["https://example.com"], "ApplicationSid"=>"APaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "StatusCallback"=>"https://example.com", "PersistentAction"=>["mailto:test@example.com"]}
{"To"=>"+15558675310", "Body"=>"Hello! 👍", "ScheduleType"=>"fixed", "StatusCallback"=>"https://example.com", "MessagingServiceSid"=>"MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}
{"To"=>"+15558675310", "Body"=>"Hello! 👍", "MediaUrl"=>["https://example.com"], "ScheduleType"=>"fixed", "StatusCallback"=>"https://example.com", "MessagingServiceSid"=>"MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}
{"To"=>"94287277+15558675310", "Body"=>"Hello! 👍", "ScheduleType"=>"fixed", "StatusCallback"=>"https://example.com", "MessagingServiceSid"=>"MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}
{
"to": "+14155552345",
"sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json",
"body": "Hello! 👍",
"from": "+14155552345",
"tags": {
"message_type": "cart_abandoned",
"campaign_name": "Spring Sale 2022"
},
"price": null,
"status": "queued",
"date_sent": "Thu, 24 Aug 2023 05:01:45 +0000",
"direction": "outbound-api",
"num_media": "0",
"error_code": null,
"price_unit": null,
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"api_version": "2010-04-01",
"date_created": "Thu, 24 Aug 2023 05:01:45 +0000",
"date_updated": "Thu, 24 Aug 2023 05:01:45 +0000",
"num_segments": "1",
"error_message": null,
"subresource_uris": {
"media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Media.json"
},
"messaging_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}
{
"to": "+14155552345",
"sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json",
"body": "Hello! 👍",
"from": "+14155552345",
"tags": null,
"price": null,
"status": "queued",
"date_sent": "Thu, 30 Jul 2015 20:12:33 +0000",
"direction": "outbound-api",
"num_media": "0",
"error_code": null,
"price_unit": null,
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"api_version": "2010-04-01",
"date_created": "Thu, 30 Jul 2015 20:12:31 +0000",
"date_updated": "Thu, 30 Jul 2015 20:12:33 +0000",
"num_segments": "1",
"error_message": null,
"subresource_uris": {
"media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Media.json"
},
"messaging_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}
{
"to": "+14155552345",
"sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json",
"body": "Hello! 👍",
"from": null,
"tags": null,
"price": null,
"status": "queued",
"date_sent": "Thu, 30 Jul 2015 20:12:33 +0000",
"direction": "outbound-api",
"num_media": "0",
"error_code": null,
"price_unit": null,
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"api_version": "2010-04-01",
"date_created": "Thu, 30 Jul 2015 20:12:31 +0000",
"date_updated": "Thu, 30 Jul 2015 20:12:33 +0000",
"num_segments": "1",
"error_message": null,
"subresource_uris": {
"media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Media.json"
},
"messaging_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}
{
"to": "+14155552345",
"sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json",
"body": "Hello! 👍",
"from": "+14155552345",
"tags": null,
"price": null,
"status": "queued",
"date_sent": "Thu, 30 Jul 2015 20:12:33 +0000",
"direction": "outbound-api",
"num_media": "0",
"error_code": null,
"price_unit": null,
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"api_version": "2010-04-01",
"date_created": "Thu, 30 Jul 2015 20:12:31 +0000",
"date_updated": "Thu, 30 Jul 2015 20:12:33 +0000",
"num_segments": "1",
"error_message": null,
"subresource_uris": {
"media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Media.json"
},
"messaging_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}
{
"to": "+15558675310",
"sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json",
"body": "Hello! 👍",
"from": null,
"tags": null,
"price": null,
"status": "queued",
"date_sent": null,
"direction": "outbound-api",
"num_media": "0",
"error_code": null,
"price_unit": null,
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"api_version": "2010-04-01",
"date_created": "Mon, 29 Nov 2021 22:40:10 +0000",
"date_updated": "Mon, 29 Nov 2021 22:40:10 +0000",
"num_segments": "0",
"error_message": null,
"subresource_uris": {
"media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Media.json"
},
"messaging_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}
{
"to": "+15558675310",
"sid": "MMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/MMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json",
"body": "Hello! 👍",
"from": null,
"tags": null,
"price": null,
"status": "accepted",
"date_sent": null,
"direction": "outbound-api",
"num_media": "1",
"error_code": null,
"price_unit": null,
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"api_version": "2010-04-01",
"date_created": "Mon, 29 Nov 2021 22:40:10 +0000",
"date_updated": "Mon, 29 Nov 2021 22:40:10 +0000",
"num_segments": "1",
"error_message": null,
"subresource_uris": {
"media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/MMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Media.json"
},
"messaging_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}
{
"to": "whatsapp:+15558675310",
"sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json",
"body": "Hello! 👍",
"from": null,
"tags": null,
"price": null,
"status": "scheduled",
"date_sent": null,
"direction": "outbound-api",
"num_media": "0",
"error_code": null,
"price_unit": null,
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"api_version": "2010-04-01",
"date_created": "Mon, 29 Nov 2021 22:40:10 +0000",
"date_updated": "Mon, 29 Nov 2021 22:40:10 +0000",
"num_segments": "0",
"error_message": null,
"subresource_uris": {
"media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Media.json"
},
"messaging_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}