Sending SMS Using XML
Overview
This method provides a way to send the message (SMS) via XML using account details.
Send SMS through your application 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 Request Parameters
These are the standard request parameters that are needed when using the EgoSms XML API.
userdataString Required
Contains the user information.
msgdataString Required
Contains the message information.
usernameString Required
The account username.
passwordString Required
The account password.
numberString Required
The phone number the message is being sent to.
messageString Required
This represents the message you are sending out. The message source must have a maximum of 160 characters.
senderidString Required
This represents who the message is coming from. Sender can have a maximum of 11 characters.
priorityString Optional
This represents level of priority. Priority can have values from (0-4) with 0: highest, 1: high, 2: Medium, 3: Low, 4: Lowest
Example
Example for sending a single message.
SendSms
Egotest
xxxxx
256788200915
welcome to Egosms
Egosms
1
Example for sending multiple messages.
SendSms
Egotest
xxxxx
256788200915
First message
test
0
256788200915
Second message
test
0
256707811116
Third message
test
0
256702662127
Forth message
test
0
System Feedback
On Success
Once your message has been successfully submitted to the EgoSms system, it will return xml in the format shown below:
OK
---
---
On Failure
Once your message fails to be submitted to the EgoSms system, it will return xml in the format shown below:
Failed
---
Possible Errors
Error
Meaning
Add Your Heading Text Here
Occurs when there is a syntax error in your XML code.
Money Not Enough To Send This Batch of Msgs
Occurs if there are insufficient funds of your Egosms Account
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
Either Username or Password Not Set
Occurs if either the password or username is empty
Programming Example
$xml_builder = '''
SendSms
Egotest
xxxxx
256702662127
test mtn
test
0
''';
//use curl to post the xml information
$ch = curl_init('https://www.egosms.co/api/v1/xml/');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: text/xml'
));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_builder);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$ch_result = curl_exec($ch);
curl_close($ch);
echo $ch_result;
?>
import requests
# The XML data
xml_builder = '''
SendSms
Egotest
xxxxx
256702662127
test mtn
test
'''
# The API URL
url = 'https://www.egosms.co/api/v1/xml/'
# Set the headers
headers = {
'Content-Type': 'text/xml',
}
# Make the request
response = requests.post(url, headers=headers, data=xml_builder)
# Extract the response body
response_body = response.text
print(response_body)
package xml;
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 SendXml {
public static void main(String [] args) {
try {
//Setting up the connection
URL url = new URL("https://www.egosms.co/api/v1/xml/");
URLConnection con = url.openConnection();
HttpURLConnection http = (HttpURLConnection)con;
http.setRequestMethod("POST");
http.setDoOutput(true);
//Details to be sent
String username = "EgosmsTest";
String password = "egotest";
String message = "My first message through Egosms";
String number = "256788200915";
String senderid = "Egosms";
//Creating XML format of the details above
byte[] out = ("\n" +
"\n" +
" SendSms \n" +
" \n" +
" "+username+" \n" +
" "+password+" \n" +
" \n" +
" \n" +
" "+number+" \n" +
" "+message+" \n" +
" "+senderid+" \n" +
" \n" +
" ").getBytes(StandardCharsets.UTF_8);
int length = out.length;
//Sending the details through established connection
http.setFixedLengthStreamingMode(length);
http.setRequestProperty("Content-Type", "application/xml; charset=UTF-8");
http.connect();
try(OutputStream os = http.getOutputStream()) {
os.write(out);
}
//Receiving response
BufferedReader in = new BufferedReader(new InputStreamReader(http.getInputStream()));
String line = null;
while((line = in.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
require 'net/http'
require 'uri'
# The XML data
xml_builder = '
SendSms
Egotest
xxxxx
256702662127
test mtn
test
0
'
# The API URL
url = URI.parse("https://www.egosms.co/api/v1/xml/")
# Create the HTTP object
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
# Create the request
request = Net::HTTP::Post.new(url.path)
request.body = xml_builder
request.add_field('Content-Type', 'text/xml')
# Make the request
response = http.request(request)
# Extract the response body
response_body = response.body
puts response_body
#!/bin/bash
# The XML data
xml_builder='
SendSms
Egotest
xxxxx
256702662127
test mtn
test
0
'
# The API URL
url="https://www.egosms.co/api/v1/xml/"
# Make the cURL request
curl -X POST -H "Content-Type: text/xml" -d "$xml_builder" "$url"
SendSms
Egotest
xxxxx
256702662127
test mtn
test
0