Integrating RingCentral Using MuleSoft
If you’re using an integration tool such as MuleSoft’s Anypoint Platform — you might not want to have to code your application from scratch. Thankfully, using RingCentral with MuleSoft’s Anypoint Platform is pretty easy.
Note: this tutorial is based on Anypoint Studio 7.1.2 and Mule 4.1.1 EE
For this quick tutorial, we’re going to create a simple web-based MuleSoft application to send SMS messages via the RingCentral API.
To do this, we first pull in the HTTP:Listener connector to build our flow:
Now we need to set the Connector Configuration (bottom center of the screen). We do this by clicking on the green “+” symbol and setting the Protocol, Host, and Port:
Click ok, and set a path for your application to listen to. In this case we’re simply going to use the path “/push” as this app will simply push a SMS message when visited.
The next step is for us to implement the password flow for our RingCentral app.
Note — this tutorial assumes you’ve setup your RingCentral app with the proper SMS permissions and password flow enabled. To learn more, visit our SMS API Tutorial.
To request an auth token that we can use to send the SMS message, we first need to make a HTTP call to the /oauth/token resource using the HTTP:Request connector.
Like with the HTTP:Listener connector, for our initial request we’ll also click on the green “+” symbol to setup the listener’s configuration.
Name: PasswordAuth
Base Path: /restapi
Protocol: HTTPS
Host: platform.devtest.ringcentral.com (our sandbox)
Port: 443 (standard SSL)
Finally, scroll down to Authentication and choose “Basic.” Enter your client_id as your username and your client_secret as your password and click “Ok”.
With the configuration setup, we can finish entering the details necessary to get our auth token via the Request connector:
Method: POST
Path: /oauth/token
Body: grant_type=password&username={USERNAME}&extension={EXTENSION}&password={PASSWORD}
Then, click on the “Headers” tab and enter the following:
"Content Type" | "application/x-www-form-urlencoded"
To validate that our credentials and setup so far is correct, now would be a good time to run the app locally. If successful you should see a response that includes an access_token. If you do not see an access token, ensure that your application has been setup to utilize the password flow, and that your credentials are correct.
Finally, to make our SMS request, grab another HTTP:Request connector and add it to our flow.
For this connector, we’ll need to create a different configuration. So next to configuration under the Request properties click the green “+” once again, and enter the following:
Name: RequestFlow
Base Path: /restapi
Protocol: HTTPS
Host: platform.devtest.ringcentral.com (our sandbox)
Port: 443 (standard SSL)
Finally, finish setting up the properties for this connector -
Method: POST
Path: /v1.0/account/~/extension/~/sms
Body:
{
"from": {
"phoneNumber": "YOUR_PHONE_NUMBER"
},
"to": [{
"phoneNumber": "TO_PHONE_NUMBER"
}],
"text": "Hello World"
}
Now click on the “Headers” tab and create the following headers:
"Authorization" | "Bearer "++ payload.access_token
"Content-Type" | "application/json"
And viola, you’re ready to run your program, visit http://localhost:8081/push and send your text message.
Of course, this is just a very basic overview of how to setup and use the RingCentral API inside of MuleSoft’s Anypoint Studio. For example, you’ll probably want to store your access_token as a variable to use across flows, as well as store your credentials as environmental globals (to keep them outside of the application’s XML).
But the good news is as you further build out your MuleSoft application using RingCentral’s APIs you’ll find a lot of help from both the RingCentral and MuleSoft forums.
Be sure to tweet @RingCentralDevs and let us know what Integrator you’d like to see next!
And may the Mule be with you.