Simple example for sending SMS or MMS 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.

Here’s an example cURL script:

curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages.json \
-d "To=+12685551234" \
-d "From=+12685555555" \
-d "Body=Hello from my phone number" \
-u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'

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.

API Explorer

Another easy to use example 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.

Additional Resources

Have more questions? Submit a request
Powered by Zendesk