View Categories

SMS HTTP(S) API

14 minutes of reading

v4.1.0

1. Introduction #

HTTP Bulk Service API enables customers to send SMS over HTTP/HTTPS and to receive Delivery Reports (DLRs) over the same protocol.

1.1 Help with Formatting Special Types of Messages #

SMS.ES HTTP Bulk Service API helps customers to format special types of messages, such as concatenated messages and WSI (WAP Service Indication) messages. HTTP Bulk Service API may split the submitted message into several physical SMS messages (concatenated messages) or reject the message because it is too long. Customer balance is charged per physical SMS, as in details described in the following text.

1.2 Integration #

Integration libraries are available on the following links:

PHP: https://github.com/horisen/smsgate-smshttpclient-php

JavaScript: https://github.com/horisen/smsgate-smshttpclient-node

Go: https://github.com/horisen/smsgate-smshttpclient-golang

2. Protocol Description #

This chapter provides information about the supported types of bulk SMS messages and the data flow of the messages and delivery reports.

It also provides information on the types of cases for the delivery status of the messages.

2.1 Types of Bulk Messages #

Customers can send different types of messages:

  • GSM Text messages
  • Unicode Text Messages
  • WAP Service Indicators (WSI)

2.2 Data Flow of Message and Delivery Reports #

The message is submitted over HTTP/HTTPS from the customer to SMS.ES HTTP Bulk Service API. When API has information on what happened with the delivery of the message (described in 2.5.3 Delivery Report Events section), it will send (also using HTTP/HTTPS) an event to the Callback DLR URL provided by the customer.

There are four cases:

  • Delivered message (DELIVERED)
  • Undelivered message (UNDELIVERED)
  • Rejected message (REJECTED)
  • Buffered (temporary undelivered) message (BUFFERED) followed by final DLR event, delivered (DELIVERED), undelivered (UNDELIVERED) or rejected (REJECTED)

When the message cannot be delivered as fast as possible due to temporary problems and if the DLR mask allows sending buffered events to customers for each delivery attempt, DLR event Buffered will be sent to the Callback DLR URL, as described in 2.2.4 Buffered (Temporary Undelivered Message) section.

If the DLR mask does not allow sending DLR event Buffered to the customer, no notification will be provided until the final event, Delivered or Undelivered. When the message is delivered (at first attempt or at any latter attempt), DLR event Delivered will be sent, as described in 2.2.1 Delivered Message section.

When the Bulk Service decides that a message cannot be delivered (at first attempt or at any latter attempt or when message validity expires), a DLR event Undelivered will be sent, as described in 2.2.2 Undelivered Message section.

When the message is rejected immediately on submission, the customer will be informed with HTTP response about the reason, as described in 2.2.3 Rejected Message section. Rejection may also happen later, and the customer will be informed using DLR event Rejected.

The following sections explain these cases more in detail.

2.2.1 Delivered Message #

When a customer submits an SMS to SMS.ES Bulk System, the message will be delivered to its destination as fast as possible. When SMS.ES Bulk System receives confirmation from a destination that the message is delivered, it will send a DLR Event Delivered to Callback DLR URL.

Figure: Data flow for delivered message

2.2.2 Undelivered Message #

This case is similar to Delivered Message except it describes a failure in delivery. Callback DLR URL will be called with DLR event Undelivered and a reason. No further attempt to deliver will be made. Messages are undelivered in cases when:

  • The destination number does not represent an existing mobile phone.
  • There is no route to the required destination.
  • If SMS.ES Bulk System was not able to deliver the message to the phone during the validity period (which is by default 24 hours).
  • In case of some other permanent error that makes a delivery to mobile phone impossible.

Figure: Data flow for undelivered message

2.2.3 Rejected Message #

Messages can be rejected by SMS.ES Bulk System in several cases:

  • When the username and/or password submitted in the request don’t match the one configured for the account.
  • When the account is disabled.
  • When there is no money on the account balance.
  • When the destination is not allowed for the customer.
  • When the sender field contains not allowed characters.
  • When the format of any parameter is not correct.
  • When the contents of some parameter (for example parameter text for text message submission) contains characters not supported with selected data coding.
  • Rejection can happen:
    • immediately on submission, in which case the error will be returned to the customer with HTTP/HTTPS response on the submission request.
    • or it can happen later, in which case the Callback DLR URL will be called with the DLR event Rejected.

Figure: Data flow for rejected message

Data flow for the message that is rejected later, after successful submission:

Figure: Data flow for message that is rejected later, after successful submission.

2.2.4 Buffered (Temporary Undelivered) Message #

If SMS.ES HTTP Bulk Service cannot deliver the message at the first attempt, and the DLR mask allows sending of buffered messages to the customer, DLR will be sent to the customer for each attempt with the reason of temporary failed delivery.

Reasons for temporary failures can be:

  • Absent subscriber (subscriber is not within reach of destination network or his phone is offline).
  • The mobile phone buffer for SMS is full.
  • Any other temporary failures of mobile device or destination mobile network when there is a chance to be resolved within the message validity period.

SMS.ES Bulk System will stop trying to deliver the message in the following situations:

  • The message is successfully delivered, in which case the DLR event Delivered is sent.
  • A permanent error happened which makes delivery impossible (e.g. the destination number does not exist). DLR event Undelivered or Rejected is sent.
  • Message validity period expired – within the validity period, SMS.ES Bulk System was not able to deliver the message to the mobile phone. DLR event Undelivered or Rejected is sent.

Figure: Data flow for buffered (temporary undelivered message)

2.3 Sending SMS #

Messages are sent using POST HTTP Method, to the URLs provided together with the credentials.

HTTP Post JSON payload must be encoded using UTF-8 encoding.

2.3.1 JSON Fields in Submitted Message #

JSON fields in submitted message, common for all types:

NameTypeDescription
typestringType of a message. It can be: text or wsi.For type=’text’:
– text – UTF-8 encoded text of message content,
– dcs – message coding, gsm (for GSM messages) or ucs (for Unicode messages).For type=’wsi’:
– url – URL to show in WSI,
– title – Title of WSI.
senderstringSMS originator address, alphanumeric or numeric.
receiverstringSMS destination address, numeric. Recipient phone number in international format (E.164) without the leading plus sign (+). Example: "receiver": "4179123456".
dlrMaskintegerDLR mask represents DLRs customer wants to receive, described in the following text (optional, default=19).
dlrUrlstringDLR URL where to send DLR callbacks (optional, if not present, the one set in an account settings in the platform is used).
flashbooleanIs the SMS “flash”? A flash SMS is a message that appears directly on a mobile screen for immediate viewing and then disappears, without being stored in the inbox.
validityPeriodMinutesintegerSMS validity period, which is the duration in minutes that delivery will be attempted.
customobjectCustom JSON object that will be sent back as a part of each DLR (optional, default empty).
authobjectAuthentication object with two fields:username – account usernamepassword – account password.

2.3.2 Example of Submission URLs #

  • For HTTP:http://sms.example.org/bulk/sendsms
  • For HTTPS:https://sms.example.org/bulk/sendsms

NOTE: Instead of ‘sms.example.org’ please use URLs provided to you in Excel file with your account data.

2.3.3 Text Messages in GSM Encoding #

SMS to be sent is encoded in JSON document:

and it must be submitted to the URL (HTTP or HTTPS) that is given together with the credentials.

2.3.4 Examples (From Bash Shell) #

For HTTP:

For HTTPS:

NOTE: Instead of ‘sms.example.org’ please use URLs provided to you in Excel file with your account data.

2.3.5 Unicode Messages #

Message text must be UTF-8 encoded as well, but it will be sent to the destination device encoded using UTF-16 protocol. Content is converted by Bulk Service.

Note that GSM messages, when long, need to be encoded to 140 bytes or 160 septets when content is converted to GSM encoding. Available number of bytes is further reduced by the length of the UDH (used for concatenation). Unicode messages use the same number of bytes (140) but require more bytes for each character (UTF-16 encoding). This means, when message content is longer, and must be sent as concatenated parts, Unicode messages will require more parts than GSM messages.

2.3.6 WAP Server Indication (WSI) Messages #

2.3.7 HTTP Response When Sending SMS #

If the message is accepted to be sent, HTTP status code is 202 and JSON response is:

Where:

  • msgId – message ID formatted as UUID and used for referencing further this message, for example in DLR.
  • numParts – number of parts if the message is concatenated. If the message can be sent as one SMS part (without concatenation), numParts will be 1.

If the message is rejected, the HTTP status code is 420 and the response is:

API may also return other error codes from the 5xx range. In this case, there is no JSON response and error codes conform to standard HTTP error codes.

2.4 Error Codes #

Error codes are listed in the following table:

Error codeValueDescription
RC_APPLICATION_ERROR101Internal application error.
RC_ENCODING_ERROR102Encoding not supported or message not encoded with selected encoding.
RC_NO_ACCOUNT103No account with given username/password.
RC_IP_NOT_ALLOWED104Sending from clients IP address not allowed.
RC_THROTTLING_ERROR105Too many messages were submitted within a short period of time. Resend later.
RC_BLACKLISTED_SENDER106Sender contains words blacklisted on destination.
RC_INVALID_SENDER107Sender contains illegal characters.
RC_MESSAGE_TOO_LONG108The message is too long.
RC_BAD_CONTENT_FORMAT109The format of the text parameter is wrong.
RC_MISSING_MANDATORY_PARAMETER110Mandatory parameter is missing.
RC_UNKNOWN_MESSAGE_TYPE111Unknown message type.
RC_BAD_PARAMETER_VALUE112Format of some parameter is wrong.
RC_NO_CREDIT113No credit on account balance.
RC_NO_ROUTE114No route for given destination.
RC_CONCAT_ERROR115Message cannot be split into concatenated messages (e.g. too many parts will be needed).
RC_LOOP_DETECTED116Loop detected.

2.4.1 How to Handle Errors #

When the customer receives an HTTP status code 420 METHOD_INVOCATION_FAILURE, he should not retry the submission of the message, except in the case of RC_THROTTLING_ERROR.

2.4.1.1 Throttling Error #

In case when submission fails with RC_THROTTLING_ERROR, the customer should wait one second and then retry the submission.

2.4.1.2 Internal server Error #

In case when submission fails with HTTP status code 500 INTERNAL_SERVER_ERROR, the customer should wait at least one minute and then retry the submission.

2.5 Receiving DLR #

Delivery reports are sent to the customer to the URL provided in JSON field “dlrUrl” when submitting an SMS. Alternatively, the account could be set up with a default value for “dlrUrl”.

It is JSON encoded, with the following form:

The previous JSON is an example of DLR for a message that is not concatenated (numParts=1), then partNum is 0.

Fields in DLR:

NameTypeDescription
msgIdstringID of the message, the one returned when SMS is submitted.
eventstringOne of DELIVERED, UNDELIVERED, REJECTED, BUFFERED, SENT_TO_SMSC.
errorCodeintegerError code, a reason for delivery failure (check DLR error code list in the next section). Zero represents no error.
errorMessagestringA message associated with errorCode.
numPartsintegerTotal number of concatenated parts. If message is not concatenated then numParts=1.
partNumintegerA number of a message part. It can be from [0..numParts-1] interval.
Example:If message is not concatenated, then numParts=1. Then partNum=0.If message is concatenated of two parts i.e. numParts=2, then partNum is one from [0, 1] interval.
sendTimeintegerSeconds passed from SMS submission until Bulk Service successfully sent SMS to the route (next hop).
dlrTimeintegerSeconds passed from SMS being sent to the route (next hop) until the delivery report was received.

Depending on an account settings, DLR may contain additional fields:

  • mcc – Mobile Country Code discovered for the destination number.
  • mnc – Mobile Network Code discovered for the destination number.
  • country – ISO2 code of the country where the destination number is registered.
  • price – The price of the SMS (this information is informal and may be subject to change).
  • currency – The currency of the price.

If SMS is submitted with “custom” field, DLR will have:

  • custom – The same object sent back in each DLR.

When a message is concatenated, it is submitted by the customer as one submission, and then split by Bulk Service to required number of SMS parts. DLRs are sent to the Callback URL for each SMS part independently.

2.5.1 Example of DLRs for a Concatenated Message #

  1. An example of DLR for the first part of a concatenated message of two parts, i.e. numParts=2, then partNum=0:{ "msgId": "9325d0a8-2638-11e6-afe7-bffc7cc8fa5e", "event": "DELIVERED", "errorCode": 0, "errorMessage": "", "partNum": 0, "numParts": 2, "accountName": "testuser", "sendTime": 0, "dlrTime": 2 }
  2. An example of DLR for the second part of a concatenated message of two parts, i.e. numParts=2, then partNum=1:{ "msgId": "9325d0a8-2638-11e6-afe7-bffc7cc8fa6g", "event": "DELIVERED", "errorCode": 0, "errorMessage": "", "partNum": 1, "numParts": 2, "accountName": "testuser", "sendTime": 0, "dlrTime": 2 }

2.5.2 DLR Error Codes #

DLR Error Codes may vary across different platforms, influenced by factors such as error code mapping and other considerations.

DLR error codes are given in the following table:

Value (dec)Description
0No error.
1Unknown subscriber.
9Illegal subscriber.
11Teleservice not provisioned.
13Call barred.
15CUG reject.
19No SMS support in MS.
20Error in MS.
21Facility not supported.
22Memory capacity exceeded.
29Absent subscriber.
30MS busy for MT SMS.
36Network/Protocol failure.
44Illegal equipment.
60No paging response.
61GMSC congestion.
63HLR timeout.
64MSC/SGSN timeout.
70SMRSE/TCP error.
72MT congestion.
75GPRS suspended.
80No paging response via MSC.
81IMSI detached.
82Roaming restriction.
83Deregistered in HLR for GSM.
84Purged for GSM.
85No paging response via SGSN.
86GPRS detached.
87Deregistered in HLR for GPRS.
88The MS purged for GPRS.
89Unidentified subscriber via MSC.
90Unidentified subscriber via SGSN.
112Originator missing credit on prepaid account.
113Destination missing credit on prepaid account.
114Error in prepaid system.
500Other error.
989Supplier rejected SMS.
990HLR failure.
991Rejected by message text filter.
992Ported numbers not supported on destination.
993Blacklisted sender.
994No credit.
995Undeliverable.
996Validity expired.
997Blacklisted receiver.
998No route.
999Repeated submission (possible looping).

Delivery error codes are very often unreliable because of a lack of standards in messaging protocols. Bulk Service tries to provide the best effort to unify error code values. Error codes returned by underlying routes are mapped to the above table.

2.5.3 Delivery Report Events #

Delivery events that SMS.ES Bulk Service sends to the Callback are:

NameDLR mask valueDescription
DELIVERED1Delivered to phone, final status.
UNDELIVERED2Non-Delivered to Phone, final status.
BUFFERED4Queued on SMSC, temporary status.
SENT_TO_SMSC8Delivered to SMSC, temporary status.
REJECTED16Non-Delivered to SMSC, final status.

Statuses described with ‘final status’ are final delivery reports – no further delivery reports will be sent for the message. Statuses described with ‘temporary status’ are of two kinds:

  • Queued on SMSC usually means that there was some problem delivering the message to the mobile phone, and further DLRs will follow.
  • Queued on SMSC means that SMS.ES Bulk Service sent the message to the destination network.

DLR Mask set for each sent message can be a combination of these values. For example, 1+2+16=19 means that all the final statuses will be reported (DELIVERED, UNDELIVERED, REJECTED). DLR Mask 19 is recommended.

Temporary statuses are not always available, and it may depend on various criteria when they can be sent.

3. Additional Tables #

3.1 GSM Character Set #

Dec0163248648096112
Hex010203040506070
00@ΔSP0¡Pp
11£_!1AQaq
22$Φ2BRbr
33¥Γ#3CScs
44èΛ¤4DTdt
55éΩ%5EUeu
66ùΠ&6FVfv
77ìΨ7GWgw
88òΣ(8HXhx
99ÇΘ)9IYiy
10ALFΞ*:JZjz
11BØ<ESC>+;KÄkä
12CøÆ,<LÖlö
13DCRæ=MÑmñ
14EÅ.>NÜnü
15FåÉ/?O§oà

Additional characters on GSM phones (in conversion to GSM character set counted as two characters):

You want to send ASCIISend the following
CharacterDecimalHexCharactersHexDecimal
<ESC> e1B 6527 101
<FF>100C<ESC> <LF>1B 0A27 10
[915B<ESC> <1B 3C27 60
\925C<ESC> /1B 2F27 47
]935D<ESC> >1B 3E27 62
^945E<ESC> ^1B 1427 20
{1237B<ESC> (1B 2827 40
|1247C<ESC> @1B 4027 64
}1257A<ESC> )1B 2927 41
~1267E<ESC> =1B 3D27 61

3.2 Supported Characters in Alphanumeric Sender #

When the SMS sender is alphanumeric, it can contain characters in the printable ASCII set, but depending on the destination being used some characters may not work.

The following tables give recommendations on which characters are typically supported.

3.2.1 Special Characters #

SupportedNot Supported
CharacterASCII CodeCharacterASCII Code
SPACE0×20$0×24
!0×21@0×40
0×22[0x5B
#0×23\0x5C
%0×25]0x5D
&0×26^0x5E
0×27_0x5F
(0×28`0×60
)0×29{0x7B
*0x2A|0x7C
+0x2B}0x7D
,0x2C~0x7E
0x2D
.0x2E
/0x2F
:0x3A
;0x3B
<0x3C
=0x3D
>0x3E
?0x3F

3.2.2 Supported Letters and Digits #

  • 0123456789
  • abcdefghijklmnopqrstuvwxyz
  • ABCDEFGHIJKLMNOPQRSTUVWXYZ