Send an SMS with Cellcast API

Estimated reading: 4 minutes 1791 views

Base URL

https://cellcast.com.au/api/v3/send-mms

Method: POST

Parameters

Header ParametersDescription
APPKEYPlease add provided APPKEY – linked to your Cellcast account.
Content-Typeapplication/json

SMS Data Parameters

NameExampleDescription
sms_textSMS Text goes herestring – 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
fromSender 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
sourceAllow any text in source. eg. ZOHO, ZappierAllowed characters: letters, numbers, and dashes in the source
custom_stringAllow any text in Custom string. eg. ZOHO, ZappierAllowed 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 minutesLeave blank for immediate delivery. Allowed max 1440 Delay minutes (24 Hours)

Successful Responses

CodeStatusDescription
200SUCCESSYou 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

StatusCodeDescription
AUTH_FAILED_NO_DATA401You have not provided APPKEY
AUTH_FAILED401– APPKEY you have provided is invalid
– You are not a registered user
FIELD_EMPTY400Required field is empty
RECIPIENTS_ERROR400No valid recipients left after validation or recipient in unsubscribed list.(You can send an SMS to any Australian Mobile number.)
FIELD_INVALID400-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_REQUEST400Please 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: <<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("<<Number1>>","<<Number2>>","<<Number3>>");

//Call function to send SMS
sendSms($text, $phone_number);