D7 SMS allows you to reach your customers via SMS over D7’s own connectivity to global mobile networks. D7 provides reliable and cost-effective SMS services to businesses across all industries and aims to connect all countries and territories via direct connections.
*** For FREE SMS credits Signup here
*** Click here for detailed documentation.
This document is targeted at software designers/programmers wishing to integrate SMS messaging as a function
into their applications using RESTful API, e.g. in connection with WEB-server, unified messaging, information
services etc.
SMS Messages can be transmitted using the RESTful API, the following requirements must be met to enable the
service:
D7 RESTful API allows you to
Send and receive SMS
Receive http callbacks for delivery notification (receipts) when SMS is received (or not) on mobilestation
Send long (more than 160 characters) SMS, unicode/binary content and receivehttpcallbacks when a mobile station sends you a SMS-MO.
Services having the /secure/ path require authentication using Basic Auth
which transmits Direct7 account credentials as username/password pairs, encoded using base64.
Example::
curl -X GET -H ‘Authorization: Basic Zm9vOmJhcg==’ https://rest-api.d7networks.com/secure/sendbatch
We have passed the base64 encoded credentials through the Authorization header, ‘Zm9vOmJhcg==’ is the encoded username:password pair (‘foo:bar’), you can use any tool to base64 encode/decode.
If wrong or no authentication credentials are provided, a 401 Unauthorized error will be returned.
Send a single message to one destination address.
https://rest-api.d7networks.com/secure/send
You can find the detailed list of parameters here:
curl -X POST -H ‘Authorization: Basic Zm9vOmJhcg==’ -d ‘{
“to”: 19012233451,
“from”: “D7sms”,
“content”: “Hello”,
“dlr”: “yes”,
“dlr-url”: “http://192.168.202.54/dlr_receiver.php”,
“dlr-level”: 3
}’ https://rest-api.d7networks.com/secure/send
Do not include username and password in the parameters, they are already provided through the Authorization header.
{“data”: "Success “c723d42a-c3ee-452c-940b-3d8e8b944868”}
If successful, response header HTTP status code will be 200 OK and the message will be sent, the message id will be returned in data.
Send multiple messages to one or more destination addresses.
https://rest-api.d7networks.com/secure/sendbatch
curl -X POST -H ‘Authorization: Basic Zm9vOmJhcg==’ -d ‘{
“messages”: [
{
“to”: [
“971509001XXX”,
“971549001XXX”,
“971559001XXX”
],
“content”: “Same content goes to 3 numbers”,
“from”: “D7sms”
}
]
}’ https://rest-api.d7networks.com/secure/sendbatch
{“data”: {“batchId”: “af268b6b-1ace-4413-b9d2-529f4942fd9e”, “messageCount”: 3}}
If successful, response header HTTP status code will be 200 OK and the messages will be sent, the batch id and total message count will be returned in data.
The Rest API server has an advanced QoS control to throttle pushing messages back to Direct7, you may fine-tune it through the http_throughput_per_worker and smart_qos parameters.
Sending binary messages can be done using single or batch messaging APIs.
It’s made possible by replacing the content parameter by the hex_content, the latter shall contain your binary
data hex value.
curl -X POST -H ‘Authorization: Basic Zm9vOmJhcg==’ -d ‘{
“to”: 971509001XXX,
“from”: “D7sms”,
“coding”: 8,
“hex_content”: “0623063106460628”
}’ https://rest-api.d7networks.com/secure/send
The hex_content used in the above example is the UTF16BE encoding of arabic word “أرنب” (’\x06\x23\x06\x31\x06\x46\x06\x28’).
Same goes for sending batches with binary
curl -X POST -H ‘Authorization: Basic Zm9vOmJhcg==’ -d ‘{
“messages”: [
{
“to”: [
“971509001XXX”,
“971504001XXX”,
“971505001XXX”
],
“hex_content”: “0623063106460628”
}
]
}’ https://rest-api.d7networks.com/secure/sendbatch
The parameter listed above can be used in many ways to setup a sendout batch, we’re going to list some use cases to show the flexibility of these parameters:
{
“messages”: [
{
“from”: “Brand1”,
“to”: [
“55555551”,
“55555552”,
“55555553”
],
“content”: “Message 1 goes to 3 numbers”
},
{
“from”: “Brand2”,
“to”: [
“33333331”,
“33333332”,
“33333333”
],
“content”: “Message 2 goes to 3 numbers”
},
{
“from”: “Brand2”,
“to”: “7777771”,
“content”: “Message 3 goes to 1 number”
}
]
}
From the previous Example (#1) we used the same “from” address for two different messages (“from”: “Brand2”), in the below example
we’re going to make the “from” a global variable, and we are asking for level3 dlr for all sendouts:
{
“globals” : {
“from”: “Brand2”,
“dlr-level”: 3,
“dlr”: “yes”,
“dlr-url”: “http://some.fancy/url”
}
“messages”: [
{
“from”: “Brand1”,
“to”: [
“55555551”,
“55555552”,
“55555553”
],
“content”: “Message 1 goes to 3 numbers”
},
{
“to”: [
“33333331”,
“33333332”,
“33333333”
],
“content”: “Message 2 goes to 3 numbers”
},
{
“to”: “7777771”,
“content”: “Message 3 goes to 1 number”
}
]
}
So, globals are vars to be inherited in messages, we still can force a local value in some messages like the “from”: “Brand1” in the above example.
As explained, Direct7 is enqueuing a sendout batch everytime you call /secure/sendbatch,
the batch job will run and call Direct7’s http api to deliver the messages, since this is running in background you can ask
for success or/and error callbacks to follow the batch progress.
{
“batch_config”: {
“callback_url”: “http://127.0.0.1:7877/successful_batch”,
“errback_url”: “http://127.0.0.1:7877/errored_batch”
},
“messages”: [
{
“to”: [
“55555551”,
“55555552”,
“55555553”
],
“content”: “Hello world !”
},
{
“to”: “7777771”,
“content”: “Holà !”
}
]
}
The RESTful api is a wrapper around Direct7’s http api, it relies on Celery task queue to process long running batches.
When you launch a batch, the api will enqueue the sendouts through Celery and return a batchId, that’s the Celery task id.
Since the batch will be executed in background, the API provides a convenient way to follow its progression through two different
callbacks passed inside the batch parameters:
{
“batch_config”: {
“callback_url”: “http://127.0.0.1:7877/successful_batch”,
“errback_url”: “http://127.0.0.1:7877/errored_batch”
},
“messages”: [
{
“to”: “7777771”,
“content”: “Holà !”
}
]
}
The callback_url will be called (GET) everytime a message is successfuly sent, otherwise the errback_url is called.
It is possible to schedule the launch of a batch, the api will enqueue the sendouts through Celery and return a batchId while
deferring message deliveries to the scheduled date & time.
{
“batch_config”: {
“schedule_at”: “2017-11-15 09:00:00”
},
“messages”: [
{
“to”: “7777771”,
“content”: “Good morning !”
}
]
}
The above batch will be scheduled for the 15th of November 2017 at 9am, the Rest API will consider it’s local server time to make the delivery, so please make sure it’s accurate to whatever timezone you’re in.
It’s possible to use another schedule_at format:
{
“batch_config”: {
“schedule_at”: “86400s”
},
“messages”: [
{
“to”: “7777771”,
“content”: “Good morning !”
}
]
}
The above batch will be scheduled for delivery in 1 day from now (86400 seconds = 1 day).
Get user account’s balance and quota.
Definition::
https://rest-api.d7networks.com/secure/balance
Parameters are the same as the http api
curl -X GET -H ‘Authorization: Basic Zm9vOmJhcg==’ https://rest-api.d7networks.com/secure/balance
… note:: Do not include username and password in the parameters, they are already provided through the Authorization header.
{“data”: {“balance”: “10.23”, “sms_count”: “ND”}}
If successful, response header HTTP status code will be 200 OK, the balance and the sms count will be returned in data.