Twilio Connector for Sending Messages

DZone 's Guide to

Twilio Connector for Sending Messages

See how you can integrate Twilio into your project so you can more easily reach out to your users in a variety of ways, including SMS and MMS.

· Integration Zone ·
Free Resource

Mulesoft provides a Twilio Connector, which allows your OutSystems Applications to use the Twilio API to send messages and make voice calls to end users. In Anypoint Studio, the Twilio connector offers instant Twilio API connectivity, providing users a simple way to interface with the Twilio API. 

Here, we're going to send an SMS to users using Mulesoft Anypoint Studio. Before that, we need to register with Twilio. Go here and register under "Try TwilioFree."

Sending an SMS or MMS is one of the most common tasks performed on the Twilio Platform. Sending a message is as simple as POST-ing to the Messages resource.

I tried working on sending messages based on the request we received from the third-party user (suppose Flipkart/Amazon is sending the product delivery status to the customers). To send messages via Twilio, you'll need to enter a few fields in Anypoint:

  • AccountSid
  • Auth Token
  • From
  • To
  • Body

Note: You can find those fields in your Twilio account.

Check the below steps to create the Twilio connector. Here, I'm trying to take the request I received from the source and, with help of Twilio, sending messages to different users.

Image title

Below, we can see how to configure the Twilio connector:

Image title

In the operation tab, select the send SMS message operation:

Image title

Twilio provides various other options, too. Some operations include:


  • Make a call.

  • Call a SIP-enabled endpoint.

  • Retrieve call logs.

  • Modify live calls.

  • Verify caller ID.

  • View call transcripts.

  • View call recordings.

  • Manage conferences.

  • View conference participants.


  • Send an SMS or MMS.

  • Send a message from a Short Code.

  • Retrieve message logs.

Phone Numbers

  • Search for phone numbers.

  • Purchase phone numbers.

  • Update phone number properties.

  • Addresses.

A sample Twilio SMS request could look like:

    "To": "+91949*****",
    "From": "+17********",
    "Body" :"Welcome to Mulesoft"

Note: We can send only 160 characters with Twilio.

Below is the sample success response:

    "sid": "SM1f0e8*****************",
    "date_created": "Fri, 26 Aug 2016 07:26:00 +0000",
    "date_updated": "Fri, 26 Aug 2016 07:26:00 +0000",
    "date_sent": null,
    "account_sid": "AC228b9**************",
    "to": "+91949*********",
    "from": "+17********",
    "body": "Welcome to Mulesoft",
    "status": "queued",
    "api_version": "2016-04-01",
    "price": null,
    "uri": "\/2016-04-01\/Accounts\/AC228b************\/SMS\/Messages\/SM1f0e8*************.json"

We receive any exceptions in the response body and they are as below

Status The HTTP status code for exceptions.
Message A more descriptive message regarding the exception.
Code  An error code to find help for the exception.
More info The URL of the Twilio Documentation for the error code.

Sample error response from Twilio:

    "status": 400,
    "message": "No to number is specified",
    "code": 21201,
    "more_info": "http:\/\/www.twilio.com\/docs\/errors\/21201"

Note:Twilio will return response with CSV, JSON, HTML, XML, other different formats.

And that's it! I hope it's useful.

twilio ,mulesoft ,integration ,sms

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}