This method provides a way to send check for the Egosms balance using HTTP.
Check balance by making an HTTP GETĀ request to the following endpoints:
These are the standard request parameters that are needed when using the EgoSms Balance Inquiry HTTP Api.
Specifies the action being performed. ie Balance for Balance Inquiry.
The account username.
The account password.
The above link will return the balance of the Ego Sms with username Egotest and password xxxxx
Once the request is successful, the balance of the account is returned.
Once the request fails, an error message is returned.
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.
function AccountBalance($method,$username, $password)
{
$url = "www.egosms.co/api/v1/plain/?";
$parameters = "method=[method]&username=[username]&password=[password]";
$parameters = str_replace("[method]", urlencode($method) ,$parameters);
$parameters = str_replace("[username]", urlencode($username) , $parameters);
$parameters = str_replace("[password]", urlencode($password) , $parameters);
$live_url = "https://" . $url . $parameters;
$parse_url = file($live_url);
$response = $parse_url[0];
return $response;
}
$method = "Balance";
$username = "xxxxxxx";
$password = "xxxxxxx";
echo AccountBalance($method,$username, $password);
# importing the requests library
import json
import requests
import html
# The api url
url = "https://www.egosms.co/api/v1/plain/"
# The parameters to be sent to the ego sms api
password = "xxxxxx"
username = "egotest"
parameters = {
'method': "Balance",
'username': username,
'password': password
}
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, params=parameters, timeout=timeout)
# 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 HTTP
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
public class CheckBalanceHTTP {
public static void main(String args[]) {
try {
/**
* username and password of registered egosms user
*/
String username = "Egosmstest";
String password = "egotest";
/**
* Mapping method, username and password parameters to their actual values
*/
HashMap params = new LinkedHashMap();
params.put("method", "Balance");
params.put("username", username);
params.put("password", password);
/**
* Appending and enconding each parameter to the url
*/
StringBuilder postData = new StringBuilder();
for (Map.Entry param : params.entrySet()) {
if (postData.length() != 0)
postData.append('&');
postData.append(URLEncoder.encode(param.getKey(), "UTF-8"));
postData.append('=');
postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8"));
}
//For Testing purposes
System.out.println("Content to send: " + postData);
byte[] postDataBytes = postData.toString().getBytes("UTF-8");
/**
* Converting the data to be posted into String format
*/
String outString = new String(postDataBytes);
/**
* egosms url for balance inquiry using HTTP
*/
String urlParams = "https://www.egosms.co/api/v1/plain/?";
/**
* Appending the post data to the url as a String
*/
String finalUrl = urlParams + outString;
URL url = new URL(finalUrl);
/**
* Opening the connection to the url
*/
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
/**
* Setting the request method to GET
*/
conn.setRequestMethod("GET");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
conn.setDoOutput(true);
conn.getOutputStream().write(postDataBytes);
/**
* Reading and printing the response data
*/
Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
for (int c; (c = in.read()) >= 0;)
System.out.print((char) c);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}