Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

MuleSoft Integration With Twilio

DZone's Guide to

MuleSoft Integration With Twilio

Learn how to integrate the cloud communication platform Twilio with MuleSoft, and configure and use it to create a demo app.

· Integration Zone ·
Free Resource

SnapLogic is the leading self-service enterprise-grade integration platform. Download the 2018 GartnerMagic Quadrant for Enterprise iPaaS or play around on the platform, risk free, for 30 days.

Twilio is a cloud communication platform which allows applications to send and receive text messages, make and receive phone calls by exposing the APIs. MuleSoft provides a Twilio connector which is available on Anypoint Exchange to integrate apps developed in Anypoint Studio. You can use the steps in this post to configure Twilio and develop a demo app.

To start the integration with Twilio, please download the Twilio connector from the exchange.

To connect with Twilio, you should have an active account with Twilio.com. For demo purposes, Twilio allows developers to create a free trial account. 

Once you create a trial account, you can login to your account and can find the details required to configure the Twilio connector. Go to Twilio Dashboard (twilio.com/console) to find the Account SID and Auth Token.

Image title

Go to the Phone Numbers page to create a phone number from which the SMS will be sent in this demo.

Image title

Verify your caller ID under Verified Called IDs. Twilio APIs will allow sending an SMS only to verified caller IDs.

Image title

To start, create a new Mule project. Please drag and drop the connectors as shown in the below flow:

Image title

Once you have all the pallettes, use the following configs-

HTTP: Port 8091, path:  /send/{toNumber} 

Transform message:

% dw 1.0
 % output application / java
 -- - {
  body: "Message from mulesoft via Twilio",
  from: "${fromNumber}",
  to: inboundProperties.
  'http.uri.params'.toNumber
 }
as: object {
 class: "org.mule.modules.twilio.pojo.sendmessagerequest.MessageInput"
}

Twilio connector:

Click the green plus sign to the right of "Connector Configuration" and set the fields as shown in the below example.

Provide the AccountSid and Authtoken which we got from the Twilio account. Use this URL to configure API URL:  https://api.twilio.com/2010-04-01. This was the latest URL when this blog was written, it may change.

Image title

Use Test Connection to test the connectivity, to see if the connector is able to connect to Twilio successfully.

The operation will be "Send Message" as this demo is for sending an SMS. 

Entity Reference: #[payload] 

Image title

As we have configured all components, our app is ready to be deployed and tested. Just run it and deploy it on your Mule Runtime env. 

Image titleNow your app is ready to send an SMS through Twilio. If you open your browser and hit http://localhost:8091/send/9726932341, you will see the following page: 

Image title

You will receive the SMS on your phone:

Image title

For new Mule learners, try this example to get started. Also, explore the Anypoint Exchange to see other resources you can leverage.

Please refer to this video for a live demo.

With SnapLogic’s integration platform you can save millions of dollars, increase integrator productivity by 5X, and reduce integration time to value by 90%. Sign up for our risk-free 30-day trial!

Topics:
twilio ,mulesoft ,anypoint studio ,integration

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}