Potential Support Response Time Delays Due to Surge in Toll-Free Queries: We’re experiencing a surge in inquiries due to the November 8, 2023 Toll-Free Restricted Traffic Shutdown Deadline. We’re committed to helping you; please bear with us as there might be some delays. For more details, see Toll-Free Message Verification for US/Canada.

Simple Example for Sending Programmable SMS Text or Picture Messages

To send a message, your application needs to make an HTTP POST request to Twilio’s Messages API resource with three required pieces of information; A recipient, a sender, and some content.

  • Recipient: The To parameter consisting of the desired destination phone number (using E.164 formatting) for receiving this message.
  • Sender: One of the following to indicate the sending party -
  • Content: One or both of the following to indicate the make-up for this message -
    • The Body parameter consisting of the message text you want to send.
    • The MediaUrl parameter consisting of the URL of the media you wish to send out with the message.

Notice: Media files must be accessible by Twilio's proxy servers. Local files on your desktop are likely unaccessible via these methods, but may be uploaded to Twilio Assets for sending. For more information on supported file types, please see Twilio Programmable SMS Supported File Types and Size Limits for MMS Media Messages.

Sample Code

Here’s an example cURL script:

curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages.json \
--data-urlencode "To=+13105555555" \
--data-urlencode "From=+12125551234" \
--data-urlencode "MediaUrl=https://demo.twilio.com/owl.png" \
--data-urlencode "Body=Hello from my Twilio line!" \

This example sends an outbound message from the sender (212) 555-1234 (+12125551234) to the recipient at (310) 555-5555 (+13105555555), and includes the image owl.png, and the following message:

Hello from my Twilio line!

To make this script work for you, make the following updates, and then paste it into a terminal window:

  • Line 1 update with your Account SID
  • Line 2 update with a valid destination
  • Line 3 update with a valid sender number
  • Line 4 update with a valid image file url
  • Line 5 update with the desired message text
  • Line 6 update with your Account SID and Auth Token

Additional optional parameters can be added in your request for requesting requesting status change updates, adding a price limit, and more. For full details on each of the available options, and code samples from our Helper Libraries, please see Message Parameters (Twilio Docs).

API Explorer

Another convenient tool for sending messages is the API Explorer in Console. From here, you can send a message using easy to update fields and drop-down menus. You can even see the code change in real-time as your adjust the parameters. Click here to try it yourself: API Explorer - Create a Message.

Notice: The API Explorer will reach its End of Life on December 15th, 2023, and will no longer be accessible after this date. For alternatives, please visit our API Reference docs.

Additional Resources

Have more questions? Submit a request
Powered by Zendesk