Send a message from the account used to make the request
A Message resource represents an inbound or outbound message.
Send a message from the account used to make the request
Path parameters
-
The SID of the Account that will create the resource.
Body
-
AddressRetention string
Determines if the address can be stored or obfuscated based on privacy settings
Value is
retain
. -
ApplicationSid string
The SID of the application that should receive message status. We POST a
message_sid
parameter and amessage_status
parameter with a value ofsent
orfailed
to the application'smessage_status_callback
. If astatus_callback
parameter is also passed, it will be ignored and the application'smessage_status_callback
parameter will be used.Minimum length is
34
, maximum length is34
. Format should match the following pattern:^AP[0-9a-fA-F]{32}$
. -
Attempt integer
Total number of attempts made ( including this ) to send out the message regardless of the provider used
-
Body string
The text of the message you want to send. Can be up to 1,600 characters in length.
-
ContentRetention string
Determines if the message content can be stored or redacted based on privacy settings
Value is
retain
. -
ForceDelivery boolean
Reserved
-
From string(phone-number)
A Twilio phone number in E.164 format, an alphanumeric sender ID, or a Channel Endpoint address that is enabled for the type of message you want to send. Phone numbers or short codes purchased from Twilio also work here. You cannot, for example, spoof messages from a private cell phone number. If you are using
messaging_service_sid
, this parameter must be empty. -
MaxPrice number
The maximum total price in US dollars that you will pay for the message to be delivered. Can be a decimal value that has up to 4 decimal places. All messages are queued for delivery and the message cost is checked before the message is sent. If the cost exceeds
max_price
, the message will fail and a status ofFailed
is sent to the status callback. IfMaxPrice
is not set, the message cost is not checked. -
MediaUrl array[string(uri)]
The URL of the media to send with the message. The media can be of type
gif
,png
, andjpeg
and will be formatted correctly on the recipient's device. The media size limit is 5MB for supported file types (JPEG, PNG, GIF) and 500KB for other types of accepted media. To send more than one image in the message body, provide multiplemedia_url
parameters in the POST request. You can include up to 10media_url
parameters per message. You can send images in an SMS message in only the US and Canada. -
MessagingServiceSid string
The SID of the Messaging Service you want to associate with the Message. Set this parameter to use the Messaging Service Settings and Copilot Features you have configured and leave the
from
parameter empty. When only this parameter is set, Twilio will use your enabled Copilot Features to select thefrom
phone number for delivery.Minimum length is
34
, maximum length is34
. Format should match the following pattern:^MG[0-9a-fA-F]{32}$
. -
PersistentAction array[string]
Rich actions for Channels Messages.
-
ProvideFeedback boolean
Whether to confirm delivery of the message. Set this value to
true
if you are sending messages that have a trackable user action and you intend to confirm delivery of the message using the Message Feedback API. This parameter isfalse
by default. -
ScheduleType string
Indicates your intent to schedule a message. Pass the value
fixed
to schedule a message at a fixed time.Value is
fixed
. -
SendAsMms boolean
If set to True, Twilio will deliver the message as a single MMS message, regardless of the presence of media.
-
SendAt string(date-time)
The time that Twilio will send the message. Must be in ISO 8601 format.
-
SmartEncoded boolean
Whether to detect Unicode characters that have a similar GSM-7 character and replace them. Can be:
true
orfalse
. -
StatusCallback string(uri)
The URL we should call using the
status_callback_method
to send status information to your application. If specified, we POST these message status changes to the URL:queued
,failed
,sent
,delivered
, orundelivered
. Twilio will POST its standard request parameters as well as some additional parameters includingMessageSid
,MessageStatus
, andErrorCode
. If you include this parameter with themessaging_service_sid
, we use this URL instead of the Status Callback URL of the Messaging Service. URLs must contain a valid hostname and underscores are not allowed. -
The destination phone number in E.164 format for SMS/MMS or Channel user address for other 3rd-party channels.
-
ValidityPeriod integer
How long in seconds the message can remain in our outgoing message queue. After this period elapses, the message fails and we call your status callback. Can be between 1 and the default value of 14,400 seconds. After a message has been accepted by a carrier, however, we cannot guarantee that the message will not be queued after this period. We recommend that this value be at least 5 seconds.
curl \
-X POST https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Messages.json \
--user "username:password" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'AddressRetention=retain&ApplicationSid=string&Attempt=42&Body=string&ContentRetention=retain&ForceDelivery=true&From=string&MaxPrice=42.0&MediaUrl=https%3A%2F%2Fexample.com&MessagingServiceSid=string&PersistentAction=string&ProvideFeedback=true&ScheduleType=fixed&SendAsMms=true&SendAt=2023-05-04T09%3A42%3A00%2B00%3A00&SmartEncoded=true&StatusCallback=https%3A%2F%2Fexample.com&To=string&ValidityPeriod=42'
{
"AddressRetention": "retain",
"ApplicationSid": "string",
"Attempt": 42,
"Body": "string",
"ContentRetention": "retain",
"ForceDelivery": true,
"From": "string",
"MaxPrice": 42.0,
"MediaUrl": [
"https://example.com"
],
"MessagingServiceSid": "string",
"PersistentAction": [
"string"
],
"ProvideFeedback": true,
"ScheduleType": "fixed",
"SendAsMms": true,
"SendAt": "2023-05-04T09:42:00+00:00",
"SmartEncoded": true,
"StatusCallback": "https://example.com",
"To": "string",
"ValidityPeriod": 42
}
{
"AddressRetention": "retain",
"ApplicationSid": "string",
"Attempt": 42,
"Body": "string",
"ContentRetention": "retain",
"ForceDelivery": true,
"From": "string",
"MaxPrice": 42.0,
"MediaUrl": [
"https://example.com"
],
"MessagingServiceSid": "string",
"PersistentAction": [
"string"
],
"ProvideFeedback": true,
"ScheduleType": "fixed",
"SendAsMms": true,
"SendAt": "2024-05-04T09:42:00+00:00",
"SmartEncoded": true,
"StatusCallback": "https://example.com",
"To": "string",
"ValidityPeriod": 42
}
{
"account_sid": "string",
"api_version": "string",
"body": "string",
"date_created": "string",
"date_sent": "string",
"date_updated": "string",
"direction": "inbound",
"error_code": 42,
"error_message": "string",
"from": "string",
"messaging_service_sid": "string",
"num_media": "string",
"num_segments": "string",
"price": "string",
"price_unit": "string",
"sid": "string",
"status": "queued",
"subresource_uris": {},
"to": "string",
"uri": "string"
}
{
"account_sid": "string",
"api_version": "string",
"body": "string",
"date_created": "string",
"date_sent": "string",
"date_updated": "string",
"direction": "inbound",
"error_code": 42,
"error_message": "string",
"from": "string",
"messaging_service_sid": "string",
"num_media": "string",
"num_segments": "string",
"price": "string",
"price_unit": "string",
"sid": "string",
"status": "queued",
"subresource_uris": {},
"to": "string",
"uri": "string"
}