Tutorials
SENDING SMS
This method provides a way to send the message (SMS) via JSON using account details.
These are the standard request parameters that are needed when using the EgoSms JSON Api
Contains the user information.
Contains the message information.
The account user name.
The account password.
The phone number the message is being sent to.
This represents the message you are sending out. The message source must have a maximum of 160 characters.
This represents who the message is coming from. Sender can have a maximum of 11 characters.
{
"method":"SendSms",
"userdata":{
"username":"xxxxxx",
"password":"xxxxxx"
},
"msgdata":[
{
"number":"2567xxxxxxxx",
"message":"xxxxxx",
"senderid":"xxxxxx"
}
]
}
{
"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"
}
]
}
{
"Status":"OK",
"Cost":"xxxx",
"MsgFollowUpUniqueCode":"xxxxx"
}
{
"Status":"Failed",
"Message":"xxxxxx"
}
{
"method":"SendSms",
"userdata":{
"username":"Egotest",
"password":"xxxxxxxx"
},
"msgdata":[
{
"number":"256707811113",
"message":"Welcome to Egosms",
"senderid":"Egosms"
}
]
}
{
"Status":"OK",
"Cost":"35",
"MsgFollowUpUniqueCode":"ApiJsonSubmit53b5155c1a3f90.65989312"
}
{
"Status":"Failed",
"Message":" Error Response message"
}
Occurs if there is a syntax error in your json code.
Occurs if there are insufficient funds on the sender’s account.
Occurs if either the password or username is wrong.
Occurs if the user account does not exist or is inactive.
Occurs if either the username or password is empty.
'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));
?>
# importing the requests library
import json
import requests
import html
# The api url
url = "https://www.egosms.co/api/v1/json/"
# The parameters to be sent to the ego sms api
password = "xxxxx"
username = "egotest"
senderid = "Egosms"
number = "256707811113"
message = "This is a message to be sent using the python programming language"
# data to be sent to api
data = {"method": "SendSms",
"userdata":
{
"username": html.escape(username),
"password": html.escape(password)
},
"msgdata":
[{
"message": html.escape(message),
"number": html.escape(number),
"senderid": html.escape(senderid),
}]
}
data_in_json = json.dumps(data)
timeout = 5
# Check whether there is an internet connection and make the request
try:
# sending post request and saving response as response object
r = requests.post(url=url, data=data_in_json, timeout=timeout)
# extracting response text
response = r.text
print(response)
except(requests.ConnectionError, requests.Timeout) as exception:
print("Check your internet connection")
package json;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
public class SendJson {
public static void main(String[] args) {
try {
//Setting up the connection
URL url = new URL("https://www.egosms.co/api/v1/json/");
URLConnection con = url.openConnection();
HttpURLConnection http = (HttpURLConnection)con;
http.setRequestMethod("POST");
http.setDoOutput(true);
//Details to be sent
String username = "EgosmsTest";
String password = "egotest";
String message = "My first message through Egosms";
String number = "256788200915";
String senderid = "Egosms";
//Creating JSON format of the details above
byte[] out = ("{\"method\":\"SendSms\"," +
"\"userdata\":" +
"{" +
"\"username\":\""+username+"\"," +
"\"password\":\""+password+"\"" +
"}," +
"\"msgdata\":[" +
"{" +
"\"number\":\""+number+"\"," +
"\"message\":\""+message+"\"," +
"\"senderid\":\""+senderid+"\"" +
"}" +
"]" +
"}").getBytes(StandardCharsets.UTF_8);
int length = out.length;
//Sending the details through established connection
http.setFixedLengthStreamingMode(length);
http.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
http.connect();
try(OutputStream os = http.getOutputStream()) {
os.write(out);
}
//Receiving response
BufferedReader in = new BufferedReader(new InputStreamReader(http.getInputStream()));
String line = null;
while((line = in.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Tutorials
SENDING SMS