Table of Contents
How to use SMS API?
SMS API Host URL
SMS API Host: https://api.enablex.io/sms/
Every major version release of API will have a sub-directory named after major version number. This is known as Base URL for a SMS API Version, e.g.
Version Base URL: https://api.enablex.io/sms/v1/
All SMS API Routes are mapped to the Version Base URL, e.g.
Message Route: https://api.enablex.io/sms/v1/messages/
API Authentication
The SMS API uses HTTP Basic Authentication mechanism to authenticate API calls. Each API call is validated via the authentication header.
The following Information is used as credentials to access SMS API for your Application in the HTTP basic authentication header in the API call request
- Application ID or APP_ID as Username
- Application Key or APP_KEY as Password
POST https://api.enablex.io/sms/v1/messages/ Authorization: Basic XXXXXXX Content-Type: application/json
The Authorization header in the above example contains a value XXXXX which is a base64 encoded string of the APP_ID:APP_KEY.
How to get APP_ID & APP_KEY
All API Credentials are paired to a Project. You will need to create a Project first to receive the API credentials. To create Project, follow the given steps:
- Login to EnableX Portal
- Navigate: {Main Menu} Projects / My Projects
- Click: Project Name – to reach Project Dashboard. Access Credentials for the Project can be found here.
API Responses
The SMS API call make use of JSON Result Code to determine if the API call is successful.
Success Response
Successful API calls will always return JSON with a 0 (zero) Result Code.
{ "result": 0, …. …. }
Error Response
If unsuccessful for whatever reason the API will return a JSON with a non—zero result code. An error response in JSON will always carry 3 keys, viz. result code, error, description. See example below:
{ "result": "Non-Zero Result Code", "error": "Short reason", "desc": "Descriptive information about the error / warning" }
Result Code Grouping
The Result Codes of API are grouped into 5 categories as shown in the table below:
Code | Category | Description |
1xx | Information | Request received & processed |
2xx | Success | Request received & accepted |
3xx | Redirection | Action required to complete Request |
4xx | Client Error | Illegible Request Syntax. Can’t be fulfilled |
5xx | Server Error | Failed to complete a legit Request |
Outgoing SMS APIs
Send SMS
This Route is used to send promotional and transactional SMS either individually or in bulk. If the request to send SMS is accepted, the API returns a “job_id” for the accepted Job. The Job ID may later be used to query delivery report or receive delivery notification on Web Hook URL.
- API Route: https://api.enablex.io/sms/v1/messages/
- HTTP Request: POST
Request Example
POST https://api.enablex.io/sms/v1/messages/ Authorization: Basic XXXXXXX Content-Type: application/json { “from”: “+44xxxxxxxx”, “body”: “{$name} you are due to pay Rs. {$amount}”, “direct”: true, “recipient”: [ { “to”: “+91xxxxxx”, “name”: “Kamal”, “amount”: “30”, "body": "This body supercedes with direct: true", "uuid": "String" } ], “type”: “sms”, “reference”: “XOXO”, “validity”: “30”, “type_details”: “”, “data_coding”: “plain”, “flash_message”: false, “scheduled_dt”: “2019-12-17T14:26:57+00:00”, “created_dt”: “2019-12-15T14:26:57+00:00”, “campaign_id”: “XX”, “template_id”: “37081401” }
Response Example
{ “result”: 0, “job_id”: “5e71f1b23630865c34443fb4” }
JSON Payload – Key Explanation
Object / Key | Description |
from | String. Optional. Its either a Sender-Id or a Phone Number (Short Code / Long Code) |
body | String. SMS Body |
template_id | String. Optional. ID of of approved Template. body and template_id may not be used together. If used template_id supersedes.[K10] |
direct | Boolean. Optional. If set to true, you can use body in recipient in each object. So, body given against each recipient will overwrite global body explained above. |
to | Array of Strings. One or many Recipient Phone Number |
recipient | Array of Objects. Custom Data Structure of Recipient used for data merging. to and recipient may not be used together. If used recipient supersedes. Note that each object in recipient must have a to key containing the Recipient’s Phone Number. uuid is used as external-reference or Unique Identifier given to the SMS Recipient. Also, if you use body key here with diretct:true , it will overwrite body defined outside. |
type | String. Enumerated values: sms, binary. Default: sms |
type_details | Hash. A hash with extra information. Is only used when a binary message is sent. |
validity | Numeric. Optional. In Seconds that the message is valid. If a message is not delivered within this time, the message will be discarded. |
reference | String. Optional. Any external reference data may be used |
data_coding | String. Enumerated values: plain, unicode, auto |
flash_message | Boolean. Optional. Default false. Flash messages are shown on screen without user interaction while not saving the message to the inbox. |
scheduled_at | Datetime. Optional. Scheduled time of delivery. RFC3339 format (Y-m-d\TH:i:s) |
campaign_id | String. Required. Campaign ID as setup through EnableX Portal. |
Get Delivery Status
This Route is used to get delivery status of SMS Sending Job posted to EnableX SMS Gateway given it’s “job_id”. Note that if Instant Delivery Notification Web Hook URL is configured, the delivery notifications are posted instantly to get real time notification.
- API Route: https://api.enablex.io/sms/v1/message/{job_id}
- HTTP Request: GET
Note the “job_id” is appended in the URL.
Request Example
GET https://api.enablex.io/sms/v1/message/5e71f1b23630865c34443fb4 Authorization: Basic XXXXXXX Content-Type: application/json
Response Example
{ “result”: 0, “job_id”: “5e71f1b23630865c34443fb4”, “summary”: { “total”: 10, “sent”: 10, “delivered”: 8, “failed”: 1, “unknown”: 1 }, "detailed":[{ "to":"+99999999999", "sent":"2020-10-16UTC08:29:42", "delivered":"2020-10-1613:59:43", "uuid":"1268999", "status":"delivered" } ] }
Note: detailed[n].uuid
appears only when its given in the recipients
Array of Objects while sending SMS.
Incoming SMS APIs
Using Incoming SMS Service requires having an Incoming Number and Webhook configuration against your Campaign. Follow the steps below to configure your Campaign:
- Place an order for a Phone Number
- Assign Incoming Number to the Campaign
- Set up your Webhook to receive notifications
Place an order for a Phone Number
To use Incoming SMS Service, you need to get a Phone Number to be configured against your Campaign. You need to place an order for a Phone Number (either Short Code or Long Code). You may opt either to choose one from EnableX Phone Inventory or get a new one. [Read More…]
Assign Incoming Number to the Campaign for Incoming SMS
Set up a campaign and assign the Incoming Number to receive the Incoming SMS. If you have an existing Campaign, attach the Incoming Number to the Campaign.
To setup a campaign, follow the steps as explained in the Create Campaign section.
To assign the Incoming Number to an existing campaign, go to the ‘Edit Campaign’ page of the ‘Campaign Settings’ and follow these steps:
- On ‘My Dashboard’, click ‘SMS’ in the ‘My Projects’ sidebar to reach the SMS Service page.
- Click the Campaign Settings option and select the Project Name from the list. Click ‘Apply’ to confirm the project. Once you select a project, it displays the list of Campaigns created under this project.
- Click the ‘Edit’ icon to navigate to the ‘Edit Campaign’ page for the Campaign. Refer to the Explanation of the Form Elements section for more details on setting up the Campaign.
- As you select the ‘Sender Type’, it displays the list of your existing Local Numbers. Click on the ‘+’ icon to select an existing Local Numbers to link to this campaign.
- In case you want to replace the linked local number to a campaign, click the ‘-‘ icon in front of the selected Local Number and repeat the previous step to assign a new number.
Set up your Webhook
When a message arrives at your Enablex phone number, Enablex sends a request to your web application just like a web browser using the Webhook URL that you’ve specified. Incoming message received on a number is forwarded to the Webhook URL using the HTTP Post.
Webhook Settings
- Enter the Webhook URL and save it to set up your Webhook to receive notifications for incoming SMS.
Receive SMS
Below is the format of received SMS on the configured Webhook for further processing.
Incoming SMS Format
{ "id":"61e8efab5c8ece74657d3d54", "to":"919072670220", "received":"2022-01-20T05:14:19Z", "from":"919560098163", "body":"Hello" }
JSON Payload – Key Explanation
Object / Key | Description |
id | String. Required. Alphanumeric string to uniquely identify the message |
to | Numeric. Required. Recipient Phone Number where the incoming message is received |
received | Datetime. Required. Time in UTC when the message is received. Format (Y-m-d\TH:i:s) |
from | Numeric. Required. Phone number of the sender who has sent the message |
body | String. SMS Body |