Send an SMS with Cellcast API
Estimated reading: 4 minutes
2454 views
Base URL
https://cellcast.com.au/api/v3/send-mms
Method: POST
Parameters
Header Parameters | Description |
---|---|
APPKEY | Please add provided APPKEY – linked to your Cellcast account. |
Content-Type | application/json |
SMS Data Parameters
Name | Example | Description |
---|---|---|
sms_text | SMS Text goes here | string – Required field – To add a new line to the message, use “\r\n” in the message string with only double quote |
numbers | [“+61400000000”] | JSON encoded Array – Required field For multiple SMS send: [“+61400000000″,”+61400000001”] You can pass 1000 numbers to send an SMS in one API call |
from | Sender ID (Custom ID) | Sender ID (Custom ID): Valid characters: A-Z a-z 0-9, space and Dash(-),A numeric sender ID can be a maximum length of 16 digits,An alpha-numeric Sender ID can be a maximum length of 11 characters. if ‘from’ is left blank system will default to ‘Regular ID’ *note price difference |
source | Allow any text in source. eg. ZOHO, Zappier | Allowed characters: letters, numbers, and dashes in the source |
custom_string | Allow any text in Custom string. eg. ZOHO, Zappier | Allowed characters: letters, numbers, and dashes in Custom string |
schedule_time | (Optional) Y-m-d H:i:s format. eg. 2020-02-14 20:00:05 | Leave blank for immediate delivery. Your schedule time in Y-m-d H:i:s format. |
delay | (Optional) Valid value : 1 to 1440 minutes | Leave blank for immediate delivery. Allowed max 1440 Delay minutes (24 Hours) |
Successful Responses
Code | Status | Description |
---|---|---|
200 | SUCCESS | You will get SMS scheduled count and credit deduction count. |
Successful Responses look like
{
"meta": {
"code": 200,
"status": "SUCCESS"
},
"msg": "Queued",
"data": {
"messages": [
{
"message_id": "6EF87246-52D3-74FB-C319-NNNNNNNNNN",
"from" : "SENDER_ID",
"to": "+614NNNNNNNN",
"body": "SMS body here",
"date": "2019-06-15 14:02:29",
"custom_string": "lead",
"direction": "out"
}
],
"total_numbers": 1,
"success_number": 1,
"credits_used": 1
}
}
Error Response
Status | Code | Description |
---|---|---|
AUTH_FAILED_NO_DATA | 401 | You have not provided APPKEY |
AUTH_FAILED | 401 | – APPKEY you have provided is invalid – You are not a registered user |
FIELD_EMPTY | 400 | Required field is empty |
RECIPIENTS_ERROR | 400 | No valid recipients left after validation or recipient in unsubscribed list.(You can send an SMS to any Australian Mobile number.) |
FIELD_INVALID | 400 | -You can pass 10000 numbers to send an SMS in one API call – You can send the maximum message length of 918 characters, or send a message length of 402 characters for the Unicode character set. -You do not have enough credit to send SMS |
BAD_REQUEST | 400 | Please provide proper data |
Error Responses look like
{
"meta": {
"code": 400,
"status": "FIELD_INVALID"
},
"msg": "You can send the maximum message length of 918 characters, or send a message length of 402 characters for the Unicode character set.",
"data": []
}
PHP Code Example
You can call following function to send SMS.
Need to pass “SMS text” and “Mobile number array” parameters for this function.
function sendSms($text, $phone_number) {
try {
$url = 'https://cellcast.com.au/api/v3/send-sms'; //API URL
$fields = array(
'sms_text' => $text, //here goes your SMS text
'numbers' => $phone_number // Your numbers array goes here
);
$headers = array(
'APPKEY: <>',
'Accept: application/json',
'Content-Type: application/json',
);
$ch = curl_init(); //open connection
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if (!$result = curl_exec($ch)) {
$response_error = json_decode(curl_error($ch));
return json_encode(array("status" => 400, "msg" => "Something went to wrong, please try again", "result" => $response_error));
}
curl_close($ch);
return json_encode(array("status" => 200, "msg" => "SMS sent successfully", "result" => json_decode($result)));
} catch (\Exception $e) {
return json_encode(array("status" => 400, "msg" => "Something went to wrong, please try again.", "result" => array()));
}
}
Call Function
//Set text and mobile numbers
$text = "Hi User, This is my first SMS Test!";
$phone_number = array("<>","<>","<>");
//Call function to send SMS
sendSms($text, $phone_number);