Balance Inquiry Using XML
Overview
This method provides a way to send check for the EgoSms balance using XML.Â
Check balance by making an HTTP POSTÂ request to the following endpoints:
LIVE URL: https://www.egosms.co/api/v1/xml/
SANDBOX URL: http://sandbox.egosms.co/api/v1/xml/
XML Balance Request Parameters
These are the standard request parameters that are needed when using the EgoSms Balance Inquiry XML API.
methodString Required
Specifies the action being performed i.e. Balance for Balance Inquiry.
usernameString Required
The account username.
passwordString Required
The account password.
Example
Submitted XML
Balance
XXX
XXX
System Feedback
A Successful Request
Once the request has been successfully submitted, it will return the balance of the account in xml format as shown below
OK
XXX
A Failed Request
Once the request fails, xml in the format below will be returned.
Failed
Error Message
Possible Error Messages
Error
Meaning
Wrong Username or Password.
This occurs if either your username or password is wrong.
That user does not exist or user not active
It occurs if the account being used does not exist or is inactive or if the username is not set.
One Of The Values Is Empty
Occurs if any of the parameters is empty.
Method Of Request Not Set
Occurs if the method value is empty.
Programming Example
// XML Request
$xml = '
Balance
XXX
' . htmlspecialchars('XXX') . '
';
// URL of the server that handles the XML request
$url = 'https://egosms.co/api/v1/xml/';
// Initialize cURL session
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: text/xml',
));
// Execute the cURL session and get the response
$response = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
echo 'cURL error: ' . curl_error($ch);
} else {
// Close cURL session
curl_close($ch);
// Trim leading whitespace or characters
$response = ltrim($response);
// Handle the XML response
$xml_response = simplexml_load_string($response);
if ($xml_response === false) {
echo 'Error parsing the XML response: ' . libxml_get_last_error()->message;
} else {
// Access the data in the XML response
$status = $xml_response->Status;
$balance = $xml_response->Balance;
// Create the XML response structure
$xml_response = '';
$xml_response .= '';
$xml_response .= '' . $status . ' ';
$xml_response .= '' . $balance . ' ';
$xml_response .= ' ';
// Set the content type for the response
header('Content-Type: text/xml');
// Echo the XML response
echo $xml_response;
}
}
import requests
# XML Request
xml = '''
Balance
drbugembe
drbugembe
'''
# URL of the server that handles the XML request
url = 'https://egosms.co/api/v1/xml/'
# Set the headers for the request
headers = {
'Content-Type': 'text/xml',
}
# Send the POST request with XML data
response = requests.post(url, data=xml, headers=headers)
# Check for request errors
if response.status_code != 200:
print('Request failed with status code:', response.status_code)
else:
# Handle the XML response
try:
xml_response = response.text
status = xml_response.split('')[1].split(' ')[0]
balance = xml_response.split('')[1].split(' ')[0]
# Create the XML response structure
xml_response = f'\n'
xml_response += f'\n'
xml_response += f'{status} \n'
xml_response += f'{balance} \n'
xml_response += f' '
# Set the content type for the response
print('Content-Type: text/xml\n')
# Echo the XML response
print(xml_response)
except Exception as e:
print('Error parsing the XML response:', e)
import java.net.URL;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
public static void main(String[] args) {
try
{
// URL for the API content
URL url = new URL("https://www.egosms.co/api/v1/xml/");
// Create an HTTPURL Conncetion
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/xml");
connection.setDoOutput(true);
// XML data to send
String xmlData = " \r\n""\r\n"
" \r\n"
"\r\n"
" Balance \r\n"
"\r\n"
" \r\n"
"\r\n"
" abelego \r\n"
"\r\n"
" PASSWORD@EGOsMS \r\n"
"\r\n"
" \r\n"
"\r\n"
"";
// Send XML data
try(OutputStream os = connection.getOutputStream())
{
byte[] input = xmlData.getBytes("utf-8");
os.write(input, 0, input.length);
}
// GET THE RESPONSE
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK)
{
// READ THE RESPONSE
try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())))
{
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null)
{
response.append(inputLine);
}
// JSON response
String jsonResponse = response.toString();
System.out.println("JSON Response: " + jsonResponse);
}
}
else
{
System.out.println("Request failed with response code :" + responseCode);
}
}
catch (Exception e)
{
}
}