Tutorials

SENDING SMS

SENDING SMS

Using JSON

Overview

This method provides a way to send the message (SMS) via JSON using account details.

Send SMS through your application by making an HTTP POST request to the following endpoints:

JSON Request Parameters

These are the standard request parameters that are needed when using the EgoSms JSON Api

userdataString Required

Contains the user information.

msgdataString Required

Contains the message information.

usernameString Required

The account user name.

passwordString Required

The account password.

numberString Required

The phone number the message is being sent to.

messageString Required

This represents the message you are sending out. The message source must have a maximum of 160 characters.

senderidString Required

This represents who the message is coming from. Sender can have a maximum of 11 characters.

Request format

Request for sending one message.

				
					{
   "method":"SendSms",
   "userdata":{
      "username":"xxxxxx",
      "password":"xxxxxx"
   },
   "msgdata":[
      {
         "number":"2567xxxxxxxx",
         "message":"xxxxxx",
         "senderid":"xxxxxx"
      }
   ]
}
				
			

Request for sending multiple messages.

				
					{
   "method":"SendSms",
   "userdata":{
      "username":"xxxxxxxx",
      "password":"xxxxxxxx"
   },
   "msgdata":[
      {
         "number":"2567xxxxxxxxx",
         "message":"First Message",
         "senderid":"Egosms"
      },
      {
         "number":"2567xxxxxxxxx",
         "message":"Second Message",
         "senderid":"Egosms"
      },
      {
         "number":"2567xxxxxxxxx",
         "message":"Third Message",
         "senderid":"Egosms"
      },
      {
         "number":"2567xxxxxxxxx",
         "message":"Fourth message",
         "senderid":"Egosms"
      }
   ]
}
				
			

System Feedback

For a successful request

Once your message has been successfully submitted to the Egosms system, it will return Json in the format shown below.
				
					{
   "Status":"OK",
   "Cost":"xxxx",
   "MsgFollowUpUniqueCode":"xxxxx"
}
				
			

For a failed request

Once the request fails, Json in the  format below will be returned.
				
					{
   "Status":"Failed",
   "Message":"xxxxxx"
}
				
			

Example

Submited JSON

				
					{
   "method":"SendSms",
   "userdata":{
      "username":"Egotest",
      "password":"xxxxxxxx"
   },
   "msgdata":[
      {
         "number":"256707811113",
         "message":"Welcome to Egosms",
         "senderid":"Egosms"
      }
   ]
}
				
			

Returned JSON for a Successful Request

				
					{
   "Status":"OK",
   "Cost":"35",
   "MsgFollowUpUniqueCode":"ApiJsonSubmit53b5155c1a3f90.65989312"
}
				
			

Returned JSON for a Failed Request

				
					{
   "Status":"Failed",
   "Message":" Error Response message"
}
				
			

Possible Error Messages

Wrong JSON Passed

Occurs if there is a syntax error in your json code.

Money Not Enough To Send This Batch of Msgs

Occurs if there are insufficient funds on the sender’s account.

Wrong Username or Password

Occurs if either the password or username is wrong.

That user does not exist or user not active

Occurs if the user account does not exist or is inactive.

Either Username or Password Not Set

Occurs if either the username or password is empty.

Programming Example

				
					<?php
$data = array(
    'method' => 'SendSms',
    'userdata' => array(
        'username' => 'Egotest', // Egosms Username
        'password' => 'xxxxxxx'
        //Egosms Password    ),
        'msgdata' => array(
            array(
                'number' => 256707811113,
                'message' => 'elias',
                'senderid' => 'Good'
            ) ,
            array(
                'number' => 256788200915,
                'message' => 'marvin',
                'senderid' => 'Bad'
            )
        )
    );

    //encode the array into json
    $json_builder = json_encode($data);
    //use curl to post the the json encoded information
    $ch = curl_init('https://www.egosms.co/api/v1/json/');

    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json'
    ));
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json_builder);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $ch_result = curl_exec($ch);
    curl_close($ch);
    //print an array that is json decoded
    print_r(json_decode($ch_result, true));
?>