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=+12685551234" \ --data-urlencode "From=+12685555555" \
--data-urlencode "Body=Hello from my phone number" \
To make this script work, update line 1 with your Twilio Account SID, lines 2 and 3 with valid phone numbers, and line 5 with your Account SID and Auth Token. Once your script is updated, paste it into a terminal window.
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.