In order to send a Standard Rate SMS, you must POST your query to the following URL:
http(s)://api.onesixty.co.uk/rest/v2/messages/create
For batch sends, please use the following URL:
http(s)://api2.onesixty.co.uk/rest/v2/messages/create
Batch sends allow you to send an array of recipients and an array of messages (up to 1,000) in one POST and receive a submission reference back for each pair. Batch sends must be enabled on a per account basis and are designed for high volumes.
| Parameters | Type | Information |
| username (required) |
String | Your OneSixty username. |
| api_key (required) |
String | Your API key. This is different from your password. |
| to (required) |
String or Array |
When performing a batch send, please use an array of strings (see below for the format). The first recipient in this array will be sent the first message in the message array and so on. You must provide an equal number of recipients and messages. If you are not performing a batch send, please provide a (string) comma separated list of (up to 10) recipients (no spaces). An international format is required for all recipients. Do not use the plus sign (+). For example: 44712345678 |
| message (required) |
String (160) or Array |
When performing a batch send, please use an array of strings (see below for the format). The first message in this array will be sent to the first recipient in the to array and so on. You must provide an equal number of messages and recipients. The following characters are allowed on route 5 (including newlines): @£$¥èéùìòÇØøÅå_^{}[~]€ÆæßÉ !"#%&'()*+,-./0-9:;<=>?A-Za-z For all other routes, the full GSM character set is allowed (including newlines): @£$¥èéùìòÇØøÅåΔ_ΦΓΛΩΠΨΣΘΞ^{}[~]|€ÆæßÉ !"#¤%&'()*+,-./0-9:;<=>?¡A-ZÄÖÑܧ¿a-zäöñüà Please make sure your characters are UTF-8 encoded. The following may help: utf8_encode() |
| type (required) |
String | Please set the type to: sms |
| sender_id (required) |
String (11) String (15) |
The following characters are allowed on route 5: 0-9A-Za-z '- For all other routes, alphanumeric only: 0-9A-Za-z If the sender ID contains numbers only, the maximum length is 15. Otherwise it is 11. |
| route (required) |
Integer | Please use the route number specified by your account manager. |
The response format is currently JSON. You will receive an array in which the first element is either integer 0 (fail) or integer 1 (success). The second element is a string message and the third element (if successful) is a string submission reference. Here are some sample responses:
[ 0, "You have insufficient credits remaining." ]
[ 1, "Your message has been sent successfully.", "640ab2bae07bedc4c163f679a746f7ab7fb5d1fa" ]
For batch sends, the third element will be a multi-dimensional array and the format will be as follows:
[
1,
"Your message has been sent successfully.",
[
[
1,
"447123456789",
"47cca229f33afb550cf01394e0f0241ad9ea714d",
"2011-11-27 20:23:30.54598200"
],
[
1,
"447123456780",
"7befed4863bce4f0c96138323461d0df1235bde5",
"2011-11-27 20:23:30.57577000"
]
]
]
Each array will contain 4 elements. The first element is either integer 0 (fail) or integer 1 (success). The second element is a string recipient. The third element is a string submission reference. The fourth element is a string timestamp (GMT) with microseconds.
If you are using route 9 which has an inbuilt HLR checker, you will receive a success message even if your message has been "Stopped". Please expect to receive a "Stopped" delivery report before you receive one of the responses above.
You can use the json_decode() function in PHP to convert this string into a PHP variable.
Sample code
<?php
function send_sms($params)
{
$options = array(
CURLOPT_HEADER => FALSE,
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => $params,
CURLOPT_RETURNTRANSFER => TRUE
);
$ch = curl_init('http://api.onesixty.co.uk/rest/v2/messages/create');
if ($ch)
{
if (curl_setopt_array($ch, $options))
{
$response = curl_exec($ch);
if ($response)
{
$result = json_decode($response);
if ( ! empty($result))
{
if (is_array($result) && isset($result[0]))
{
if ($result[0] > 0 && isset($result[2]))
{
if (is_array($result[2]))
{
// Batch send
foreach ($result[2] as $arr)
{
//add_to_log("Success: {$arr[2]}");
}
}
else
{
// Regular send
//add_to_log("Success: {$result[2]}");
}
}
else
{
//add_to_log("Error: {$result[1]}");
}
return (bool)$result[0];
}
}
}
}
curl_close($ch);
}
return FALSE;
}
// Send one message to one recipient
$params = http_build_query(array(
'username' => 'MyUsername',
'api_key' => '47acd2028cf81b5da88ddeedb2aea4eca4b71fbd',
'to' => '447123456789',
'message' => 'Testing 123.',
'type' => 'sms',
'sender_id' => 'YourBiz',
'route' => 2
));
if (send_sms($params))
{
echo 'Message sent successfully...';
}
// Send one message to multiple recipients
$params = http_build_query(array(
'username' => 'MyUsername',
'api_key' => '47acd2028cf81b5da88ddeedb2aea4eca4b71fbd',
'to' => '447123456789,447123456780', // Notice the comma separated recipients
'message' => 'Testing 123.',
'type' => 'sms',
'sender_id' => 'YourBiz',
'route' => 2
));
if (send_sms($params))
{
echo 'Message sent successfully...';
}
// Send different messages to different recipients
$params = http_build_query(array(
'username' => 'MyUsername',
'api_key' => '47acd2028cf81b5da88ddeedb2aea4eca4b71fbd',
'to' => array(
'447123456789',
'447123456780',
),
'message' => array(
'Message to recipient 1',
'Message to recipient 2',
),
'type' => 'sms',
'sender_id' => 'YourBiz',
'route' => 2
));
if (send_sms($params))
{
echo 'Message sent successfully...';
}
?>
Speak to a real person
(01323) 800 160
One direct number for all enquiries - sales and support.
Monday - Friday, 10am to 6pm.
Clear SMS pricing
SMS text messages from just 2.99p. Lower prices available for an agreeable monthly quota.
