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
Toparameter 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 -
Bodyparameter consisting of the message text you want to send.
MediaUrlparameter consisting of the URL of the media you wish to send out with the message.
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 caller 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, please see Message Parameters (Twilio Docs).
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.
Another convenient tool for sending messages is the API Explorer in Console. Just login to your Twilio account, and then select Runtime > API Explorer. From here, you can send a message using the 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.