Tutorials

SENDING SMS

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:

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. ie Balance for Balance Inquiry.

usernameString Required

The account username.

passwordString Required

The account password.

Example

Submitted XML

				
					<?xml version="1.0" encoding="UTF-8" ?> 
<Request> 
    <method>Balance</method> 
    <userdata> 
        <username>XXX</username> 
        <password>XXX</password> 
    </userdata> 
</Request> 
				
			

System Feedback

For a successful request

Once the request has been successfully submitted, it will return the balance of the account in xml format as shown below

				
					<?xml version="1.0" encoding="UTF-8" ?> 
<Response> 
    <Status>OK</Status> 
    <Balance>XXX</Balance> 
</Response> 
				
			

For a failed request

Once the request fails, xml in the  format below will be returned.
				
					<?xml version="1.0" encoding="UTF-8" ?> 
<Response> 
    <Status>Failed</Status>
    <Message>Error Message</Message> 
</Response> 
				
			

Possible Error messages

Error

Meaning

Wrong Username or Password.

Occurs if either your username or password is wrong.

That user does not exist or user not active

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 = '<?xml version="1.0" encoding="UTF-8"?> 
<Request> 
   <method>Balance</method> 
   <userdata> 
      <username>XXX</username> 
      <password>' . htmlspecialchars('XXX') . '</password> 
   </userdata> 
</Request>'; 

// 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 version="1.0" encoding="UTF-8" ?>'; 
        $xml_response .= '<Response>'; 
        $xml_response .= '<Status>' . $status . '</Status>'; 
        $xml_response .= '<Balance>' . $balance . '</Balance>'; 
        $xml_response .= '</Response>'; 
 
        // Set the content type for the response 
        header('Content-Type: text/xml'); 
 
        // Echo the XML response 
        echo $xml_response; 
    } 
}