Versatile, Scalable,
Easy To Use Sms Api

The Cosmic SMS REST API enables you to integrate SMS messaging into your website or business application to send SMS messages globally and in any language.

Sign up for free today REST API SPECIFICATION

Already using an SMS API with someone else?

  • Moving over to Cosmic requires only a change to your API credentials and end point details.
  • Whoever you are with, we can make changing SMS providers straightforward and effortless!
  • Text SWITCH to 07537400500 for a call back or email us at sales@cosmicsms.com.

User Guide Snippets

Introduction

This document describes the interface for the Cosmic SMS Gateway and how to connect to our messaging platform to send SMS messages to UK and International mobile numbers.

The main features provided with the Cosmic SMS API are as follows:

  • Send SMS messages up to 918 characters long.
  • Send SMS messages in any language, including multiple symbol sets and emoji.
  • Schedule messages for later delivery.
  • Get the delivery status of each SMS sent.
  • Get your latest account balance.

The Technical Specification has been designed to provide developers with a detailed description of the functionality available via the Cosmic SMS API - the submission parameters and valid data values, request and response examples and character encoding regimes. However, if any queries arise then please contact Cosmic SMS Customer Support –

Address: 2nd Floor, Nucleus House, 2 Lower Mortlake Road, Richmond. TW9 2JA

Tel: +44 (0) 20 7183 9065

Email: support@cosmicsms.com

Connectivity

This section describes how to connect to the Cosmic REST API and the authentication requirements.

Base URL

Base URL for all REST API connections: https://api.cosmicsms.com

Authentication

All Web API requests are authenticated using Basic Access authentication. The account username and API password are concatenated with a colon ‘:’ separator to produce an authentication string. For example, if your user name is ‘Geoffrey’ and your password is ‘AbC123DeF456’, then your authentication string is: Geoffrey:AbC123DeF45

This authentication string is required to be Base64 encoded. Online tools are available to help, one example can be found at https://www.base64encode.org/. The encoded authentication string is then added to the HTTP header for all API requests. In the following example the encoded authentication string is shown in red.

POST * HTTP/1.1

From: www.myserver.co.uk

Host: api.cosmicsms.com

Authorization: Basic R2VvZmZyZXk6QWJDMTIzRGVGNDU2

Content-Type: application/xml

Content-Length: 247

HTTP Header Values

Name Description Example
POST The Send SMS request uses the HTTP POST method. POST * HTTP/1.1
Authorization Basic authentication is used to pass the username and password in the HTTP header. Authorization: Basic R2VvZmZyXk6QWJDMTIzRGVGNDU2
Content-Type The message body uses XML Content-Type: application/xml

HTTP Response Status Codes

All HTTP requests to the Cosmic API REST API will return one of the HTTP response status codes shown below.

Status Message
200 OK The request has succeeded
201 Created The request has been fulfilled and resulted in a new resource being created.
400 Bad Request The request could not be understood by the server due to malformed syntax
401 Unauthorized The request requires user authentication
402 Payment Required The request could not be processed due to insufficient funds.
404 Not Found The server has not found anything matching the Request-URI.
405 Method Not Allowed The method specified in the Request-Line is not allowed for the resource identified by the Request-URI.
415 Unsupported Media Type The server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method
5xx Server error Server error – contact Cosmic Support at support@cosmicsms.com

Sending SMS Messages

Request endpoint: https://api.cosmicsms.com/prod/rest/sms/send

The following tables describe the XML parameters and values that can be specified in the HTTP request when submitting SMS messages for delivery and the XML parameters and values received in the returned HTTP response.

XML Request Parameters

Name Description Example
xml The XML header specifies the version and character-encoding of the message. <?xml version="1.0" encoding="UTF-8" ?>
message (ignored if template is set) SMS Message text Hello World!
template (optional) SMS Template Id
Set the template Id instead of sending message text. Contact Cosmic support to set up a template
1234
params (optional) List of parameters.
Parameters are used with templates to enable dynamic content. The parameter name is set in the tag <>
<param1>1234</param1>
mobile Target mobile phone number – mobile numbers are listed within the ‘<mobiles>’ tag. Remove the ‘+’ sign and any leading zeros when using international codes. A UK number can start with ‘07’ or ‘447’. 07123456701
447123456701
491700015555
sender The name shown on the recipient mobile handset as the sender of the message. The sender can be set to a name or a mobile phone number – for inbound SMS the sender must be set to a mobile phone number. Numeric – max length 15, Alphanumeric – max length 11 [a-z] [A-Z] [0-9] _-, no spaces. CosmicSMS
447711456000
sendtime (optional) Set the date and time to send the message, if this is not included or is set in the past, then the message will be sent immediately. Format ISO-8601 (YYYY-MM-DDThh:mmZ) 2014-11-05T13:15:30Z
multilingual (optional) Enable Multi-Lingual message options. 0 = GSM7 - Send as GSM-7 message (default) 1 = Multi-Lingual - Send as Unicode SMS message 0, 1 or 2
2 = Auto-detect - Send as Unicode SMS message automatically if non-GSM-7 characters detected. The subject of Unicode and GSM7 encoding is explained in more detail in Section 6.

Send SMS Example

Here is a simple example of how to send a batch (1 or more recipients) SMS message using Curl:

curl -k https://api.cosmicsms.com/prod/rest/sms/send -X POST -H "Authorization: Basic R2VvZmZyZXk6QWJDMTIzRGVGNDU2" --data-binary @cosmicsms_send.xml


Note: the above example will return ‘401 Unauthorised’ so the Authorization header value needs to be replaced with valid authentication credentials.
The file ‘cosmicsms_send.xml’ contains the following example code –

<?xml version="1.0" encoding="UTF-8"?> <sendsms> <sender>447711456000</sender> <message>test message</message> <mobiles> <mobile>07123456701</mobile> <mobile>07123456702</mobile> </mobiles> </sendsms>

XML Response Parameters

Name Description Example
batch Unique id set by Cosmic SMS 156243
mobilestatus Container element for the response status elements ‘mobile’, ‘status id’, and ‘status text’.
mobile The submitted mobile number (international format). 447123456701
statusid The status of the submitted message. Status SUCCESS = Message submitted successfully. See below for full list of submission status codes returned and descriptions SUCCESS
statustext The status description text. Message submitted successfully

Response Status Values

The message submission status is returned in the XML response parameter

<statusid>

Status ID Status Text
SUCCESS Success: Message submitted successfully
INVALID_REQUEST Error: Invalid or badly formatted request
INVALID_VALUES Error: Missing or badly formatted request value(s)
INVALID_USER Error: Invalid username/password combination
INSUFFICIENT_CREDIT Error: Insufficient credit
SYSTEM_ERROR Error: System error
INVALID_MPNS Error: No valid mobile numbers supplied
MAX_MPNS_EXCEEDED Error: Too many mobile numbers supplied (Max: 500)
INVALID_MESSAGE_LENGTH Error: Message length too long, max length 612 characters
INVALID_DELIVERY_DATE Error: Invalid date/time for scheduled delivery
INVALID_MPN Error: Invalid or badly formatted mobile number
INVALID_SENDER Error: Invalid sender id. Max length: 11, [a-z] [A-Z] [0-9], no spaces
INVALID_RECEIPT_URL Error: Invalid or badly formatted URL reply path
INVALID_TEMPLATE Error: Invalid template
INVALID_PARAMS Error: Invalid parameters

XML Response Example

<?xml version="1.0" encoding="UTF-8" ?> <sendsms><batch>20154010</batch> <mobilestatus> <mobile>447123456701</mobile><statusid>SUCCESS</statusid> <statustext>Success: Message submitted successfully</statustext> </mobilestatus><mobilestatus> <mobile>447123456702</mobile> <statusid>SUCCESS</statusid> <statustext>Success: Message submitted successfully</statustext> </mobilestatus></sendsms>

Get SMS Delivery Status

Request endpoint: https://api.cosmicsms.com/prod/rest/sms/status/{batch_id}

Get the delivery status for submitted messages. Returns the message delivery status for the 1 or more recipient mobile numbers associated with the specified batch id. The batch id is sourced from the XML response when an SMS message is submitted for delivery as described in section 3.3

HTTP Header Values

Name Description Example
GET The Get Balance request uses the HTTP GET method. GET * HTTP/1.1
Authorization Basic authentication is used to pass the username and password in the HTTP header (see section 2.2: Authentication for more details). Authorization: Basic R2VvZmZyZXk6QWJDMTIzRGVGNDU2

Request Endpoint Path Values

Name Description Example
batch Unique batch number associated with a submitted message to 1 or more mobile numbers. 12345678

Get SMS Delivery Status Example

Below is an example of how to get the delivery status for an SMS message batch using Curl:


curl -k https://api.cosmicsms.com/prod/rest/sms/status/12345678 -X GET -H "Authorization: Basic R2VvZmZyZXk6QWJDMTIzRGVGNDU2"


Note: The above example will return ‘401 Unauthorised’ so the Authorization header value needs to be replaced with valid authentication credentials, and a valid batch number needs to be set

XML Response Parameters

Name Description Example
batch Unique batch id set by Cosmic SMS. 156243
messagestatus Container element for the response status elements, this is repeated for each mobile in the batch. <messagestatus> <messageid/> <mobile/> <statusid/> <statustext/> ... </messagestatus>
messageid Unique message id set by the Mobile networks. 12345678
mobile The submitted mobile number (international format). 447123456701
statusid The status of the submitted message. Status DELIV = Message successfully delivered. See below for full list of submission status codes returned and descriptions. DELIVERED
FAILED
REJECTED
UNKNOWN
statustext The status description text. Message successfully delivered
submittime The date and time the message was submitted to the mobile networks. 2014-11-05T13:15:00Z
Format ISO-8601 (YYYY-MM-DDThh:mmZ)
deliverytime The date and time from the delivery receipt confirming when the message was received by the mobile phone Note: this value is left blank if the delivery time is not relevant or not known 2014-11-05T13:16:00Z

Response Status Values

The message delivery status is returned in the XML response parameter

<statusid>.

Status ID Status Text
DELIVERED Success: Message successfully delivered
FAILED Fail: Message failed to deliver
REJECTED Fail: Message was rejected by the network / handset
UNKNOWN Unknown: Message delivery status is unknown
PENDING Pending: Message is waiting to be processed
INVALID_USER Error: Invalid username/password combination
SYSTEM_ERROR Error: System error

Get Account Balance

Request endpoint: https://api.cosmicsms.com/prod/rest/account/balance

Retrieve the current account balance using the HTTP GET method.

HTTP Header Values

Name Description Example
GET The Get Balance request uses the HTTP GET method. GET * HTTP/1.1
Authorization Basic authentication is used to pass the username and password in the HTTP header (see section 2.2: Authentication for more details). Authorization: Basic R2VvZmZyZXk6QWJDMTIz RGVGNDU2

Get Account Balance Example

Here is an example of how to retrieve your account balance using Curl:


curl -k https://api.cosmicsms.com/prod/rest/account/balance -X GET -H "Authorization: Basic UGhpbFRlc3QyOmY1NjI3MzLTRjNg=="


Note: The above example will return ‘401 Unauthorised’ as the Authorization header value needs to be replaced with valid authentication credentials.

XML Response Parameters

Name Description Example
getbalance Container element for the response status elements ‘balance’ and ‘currency’
balance Account balance 65.82
currency Currency for returned account balance returned in <balance> GBP (UK pounds) EUR (Euros)

Response Status Values

Status ID Status Text
SUCCESS Success: Account balance successfully retrieved
INVALID_USER Error: Invalid username/password combination
SYSTEM_ERROR Error: System error

XML Response Example

<?xml version="1.0" encoding="UTF-8" ?> <getbalance> <balance>65.82</balance> <currency>GBP</currency> </getbalance>

Character Sets and Encodings

The GSM-7 and Unicode character encoding standards are supported for sending SMS text messages. GSM-7 defines the standard alphabet which is mandatory for mobile networks and GSM mobile handsets (all mobile phones with a SIM card). Unicode is implemented at the mobile network level as UCS-2 and enables the transmission of a broader range of languages and richer content to mobile phones.

The character encoding you should use depends on the language and symbols you need to send in the SMS message. The character encoding used also dictates the maximum length of a SMS text message and therefore can also affect the cost of an SMS message

GSM-7 is the default character encoding used, if unspecified in the API request.

GSM-7

GSM-7 is the standard character set for sending SMS messages and is supported on GSM networks and mobile handsets globally. It contains the more commonly used letters, accented forms and symbols and is suitable for English and most West-European languages.

Each GSM-7 character uses 7-bits. A standard GSM-7 message contains up to 140 bytes, which translates to 160 characters (140*8)/7 = 160.

GSM-7 Character Set

GSM-7 Character Set - Extended

The GSM-7 standard also defines an extended character set containing the following characters:

{ } \ ~ [ ] | ^ €

These are transmitted to the mobile handset in an escaped format, and consequently use 2 7-bit characters each instead of 1.

Multi-Lingual

With the ‘multilingual’ option enabled, messages are sent using the Unicode standard which allows for a much wider range of characters to be sent that are not available in the GSM-7 character set.

Each Unicode character uses 2 bytes (16 bits). A standard Unicode message contains up to 140 8-bit octets, which translates to 70 characters (140*8)/16 = 70.

The full list of Unicode characters can be found here.

Unicode – Pros and Cons

Pros: The Unicode character set is used for Multi-Lingual messages and supports a huge range of characters not available in the GSM-7 character set. This includes non-Latin alphabets such as Chinese, Russian and Arabic, mathematical and technical symbols and emoji.

Cons: Unicode characters are sent to the mobile handset using 2 bytes per character, which limits the length of a (non-concatenated) Unicode message to 70 characters. The maximum message length for a (non-concatenated) GSM-7 message is 160 characters. SMS messages are charged on a per message basis so this can have cost implications.

Both Unicode and GSM-7 messages can be sent as concatenated multi-part SMS messages which are displayed on the recipient mobile handset as a single long SMS message. Concatenated SMS messages are explained further in Section 7.

XML Special Characters

The following characters should be represented in the message field as XML entity values so they do not interact with the syntax of the XML mark-up.

Character Description Entity
< Less-than &lt;
& Ampersand &amp;
> Greater-than &gt;

Concatenated SMS Messages

If an SMS message exceeds the single message length of 160 characters for a GSM-7 message or 70 characters for a Unicode message, it is split into smaller parts, which are then sent as individual messages, each with a 6 byte user data header (UDH) that contains the information the recipient phone requires to re-order the message parts correctly and display as a single message. The required addition of the 6 byte UDH for messages exceeding the standard length is the reason for the slightly reduced length of the subsequent message parts.

The table below illustrates the incremental and total number of characters available for a concatenated message, depending on the character set used

Number of SMS Max GSM-7 Characters Maximum Unicode Characters Total SMS Message Cost
1 standard SMS 160 70 1 x SMS
2 standard SMS 306 134 2 x SMS
3 standard SMS 459 201 3 x SMS
4 standard SMS 612 268 4 x SMS
5 standard SMS 765 335 5 x SMS
6 standard SMS 918 402 6 x SMS

Cosmic SMS

Providing high throughput with fast and reliable delivery. Suitable for every kind of SMS communication - OTP, 2FA, marketing, staff and customer broadcasts, reminders, alerts, notifications, surveys and more. The Cosmic SMS API is used by organisations across the private and public sectors – Healthcare, Financial Services, Education, IT, Transport, Retail, Communications, Public Utilities and Emergency Services, from small local businesses to large multi-national corporations.

Use any programming language that supports HTTP connections - easy to test and with some free SMS credit to get you started.

Features

Send SMS messages up to 918 characters long

Send SMS messages in any language

Send SMS including multiple symbol sets and emoji

Set SMS message sender id

Create message templates

Schedule messages for later delivery

Get the delivery status of each SMS sent

Get your latest account balance

Useful Links

HTTP REST API Technical Specification

View more

Get started with Cosmic SMS

SIGN UP FOR FREE TODAY VIEW OUR PRICES

Case Studies

Pearlai

Background: Péarlaí is a retail analytic company trusted by multiple shopping centre...

Read more

DPR

Using SMS to improve efficiency and security...

Read more