Rocking Twilio SMS with StackMob

Posted By Sid on Thursday, August 2nd, 2012

StackMob custom-code allows developers to write business logic and go beyond what is possible with the datastore API.   Recently, we introduced HTTPService support in custom code, which opens up the ability to call third-party APIs over HTTP from StackMob’s servers.  This article walks through how to setup and call Twilio’s API from custom-code to send text messages.

Create your StackMob App 

You’ll need a StackMob account, so if you haven’t already go ahead and sign up now.  You’ll be prompted to create your first application during the sign up process.

Download StackMob Example Code

You can download the StackMob custom-code examples from Github.  You’ll find the Twilio sample code in

Get Twilio Credentials

You’ll need a Twilio account to make the API call, so if you haven’t already signup for your free Twilio account.

In the Twilio dashboard you’ll see your Accountsid and AccessToken

Copy and paste those into the file In the Twilio dashboard, go under Numbers > Twilio Numbers and click on Get it now link.   Now, you’ll need to verify your own mobile number to receive the text message. Copy and Paste your Twilio number into  The toPhoneNumber  is your mobile number and we’ll pass it to the custom code method as a parameter along with the message.   That’s all you need to do to test out this example.  Now, it’s time to build our JAR file.

  1. In your Terminal app, cd into the stackmob-customcode-example/java directory.
  2. Type mvn clean package and hit enter.
  3. Your JAR file will be written to stackmob-customcode-example/java/target
  4. Upload JAR to StackMob through the StackMob dashboard.

Try it out

In the StackMob dashboard on the left side select Test Console.  Click on twilio_sms under Custom Methods.  Enter your VERIFIED mobile number, a personal message and press the submit button.  You should get your text message shortly.


Are there other third party API examples you’d like see? Please let us know.

We always welcome contributions. You can fork the custom-code-examples repo and submit a pull request if you’d like to contribute your own examples.