Tutorials
SENDING SMS
This method provides a way to send check for the EgoSMS balance using JSON.
Check balance by making an HTTP POSTĀ request to the following endpoints:
These are the standard request parameters that are needed when using the EgoSms Balance Inquiry JSON Api.
The account username.
The account password.
{
"method":"Balance",
"userdata":{
"username":"Egotest",
"password":"xxxxxxxxxxx"
}
}
Once the request has been successfully submitted, it will return the balance of the account in Json format as shown below.
{
"Status":"OK",
"Balance":"1380"
}
{
"Status":"Failed",
"Message":"xxxxxxx"
}
Occurs if either your username or password is wrong.
Occurs if the account being used does not exist or isĀ inactive or if the username is not set.
Occurs if any of the parameters is empty.
Occurs if theĀ method value is empty.
'Balance',
'userdata' => array(
'username' => 'Egotest', // Egosms Username
'password' => 'xxxxxxxxxxx'
)
);
//encode the array into json
$json_builder = json_encode($data);
//use curl to post the the json encoded information
$ch = curl_init('http://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 = "xxxxxx"
username = "egotest"
# data to be sent to api
data = {
"method": "Balance",
"userdata": {
"username": html.escape(username),
"password": html.escape(password)
}
}
data_in_json = json.dumps(data)
timeout = 5
# Check for 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)
# extracting response text
response = r.text
print(response)
except(requests.ConnectionError, requests.Timeout) as exception:
print("Check your internet connection")
/**
* Java API for Egosms Balance inquiry using 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 CheckBalanceJSON {
public static void main(String args[]) {
try {
/**
* Egosms url for Balance inquiry using JSON
*/
URL url = new URL("https://www.egosms.co/api/v1/json/");
/**
* Opening the connection to the egosms JSON url
*/
URLConnection con = url.openConnection();
HttpURLConnection http = (HttpURLConnection) con;
/**
* Setting the request method to POST
*/
http.setRequestMethod("POST");
http.setDoOutput(true);
/**
* User name and password for a registered Egosms user
*/
String username = "Egosmstest";
String password = "egotest";
/**
* Passing the method(Balance), username and password in JSON format The method,
* username and password are appended to the url as parameters when sending the
* data
*/
byte[] out = ("{\"method\":\"Balance\"," + "\"userdata\":" + "{" + "\"username\":\"" + username + "\","
+ "\"password\":\"" + password + "\"" + "}" + "}").getBytes(StandardCharsets.UTF_8);
int length = out.length;
//For Testing purposes
String outString = new String(out);
System.out.println("Content to send : " + outString);
http.setFixedLengthStreamingMode(length);
http.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
http.connect();
try (OutputStream os = http.getOutputStream()) {
os.write(out);
}
/**
* Setting the input stream to read the response data
*/
BufferedReader in = new BufferedReader(new InputStreamReader(http.getInputStream()));
String line = null;
/**
* Printing the response data
*/
while ((line = in.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Egosms Documentation
Tutorials
SENDING SMS