To send a text message, your application makes an HTTP Request to the SMS resource in the Telecoms Cloud API, which then sends the SMS to your recipient.
The first thing we’ll need is a Telecoms Cloud number, so if you’ve not done so already sign up using this link. Choose any number you like and then keep a note of it once you’ve bought it so we can use it in our script.
You’ll then need to generate yourself a set of Credentials to use with the API. In your Telecoms Cloud account just head over to your API Settings page to generate your Client ID and Client Secret.
Then, in your favourite text editor create a new script. The first thing we need to do is authenticate ourselves by creating a POST request to the /authorization resource and POSTing our API credentials as JSON data in the request. We’ll receive back an access token, which we can use to sign our requests to any of the API’s resources.
PAUSE: In the real world, you should save this access token either in a database or some local storage, and re-use it with each request until it expires.
To send a text message we’ll construct another POST request, this time to the /SMS/outbound resource, and sign it with our access token. We include JSON data consisting of the recipient mobile phone number, our Telecoms Cloud number that we bought earlier on, and the message itself. When we execute that request we’ll receive back a unique ID which lets us check the status of that message later.
So now if we run our script we’ll see the unique ID returned and a couple of moments later, the text message is received!
That’s all there is to it! You can download a copy of this example code, and don’t forget to add in things like proper error handling and any other processing required by your application.
Don’t forget to subscribe to Telecoms Cloud on YouTube and follow us on Twitter. If you’ve got any questions or comments please leave them below and take a look at our other videos to learn more about what you can do with Telecoms Cloud.