SAARA system allows several ways for endusers to send SMS (text) messages. The procedure how to set up SMS functionality is described in this step by step guide.
Here we will discuss another option: sending SMS by use of RESTful API. This is especially useful for high-volume and/or application generated messages where implementation of SMPP client is not feasible.
Below are steps necessary to grant client access to API for sending text messages and ways to test it.
Setting it up
Please set up your SMS carriers, rates, routes and Clients as discussed in SMS Service Quick Start Guide. Test it from endusers GUI. If the testing is successful, we can now create an API access.
Navigate to Clients and select a client for which you would like to create API access. In this example we will start from the simplest method: Token based API Access. Click "Add Token API Access" button:
Fill "APi Access Name" field. It is just a descriptive name, and is optional. Copy or write down Access Token value. It will not be displayed ever again, and you will need to create new API Access Token if you did not save it. Click "Save" button. API Token is now created.
RESTful API can be tested either programmatically from almost any programming language, or by using some specially designed browsers extensions. Here below we use RESTClient add-on for Mozilla Firefox. Plugins for other browsers also exist, like Advanced REST Client for Google Chrome etc. Open the Add on in a new tab and fill set the URL to the address of your SAARA server followed by path
/api/sms/send and method to
Open Headers popup window and enter authentication header. Here you should insert token generated in previos step:
The header name always is "
Authorization" and the value contains word "
token" followed by a space and then the token value generated in above step.
Request body should contain JSON-formatted object with at least following attributes: "to", "from" and "content". Paste following into request field (replace by your actual
from and to numbers:
Note, that the from number should in most cases be one of the SMS DID numbers assigned to this client.
The resulting Request should look similar to this:
Once the request is prepared, hit "SEND" button. The API should accept the message and reply with response which should contain code: 0, status code 200, and API request ID similar to this:
If the system is connected to real providers, the short message should have been delivered to the phone. Additionally it is also to verify if message is properly billed in the "SMS Log" tab of the Client: