Tutorials
SENDING SMS
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/
These are the standard request parameters that are needed when using the EgoSms Balance Inquiry XML Api
The account username.
The account password.
Balance
XXX
XXX
Once the request has been successfully submitted, it will return the balance of the account in xml format as shown below
OK
XXX
Failed
Error Message
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.
// 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)
{
}
}
Egosms Documentation
Tutorials
SENDING SMS