Tutorials
SENDING SMS
This method provides a way to send the message (SMS) via HTTP using account details.
Send SMS through your application by making an HTTP GET request to the following endpoints:
LIVE URL:https://www.egosms.co/api/v1/plain/
These are the standard request parameters that are needed when using the HTTP method of the EgoSMS Api.
The parameters should be separated using the ‘&’ sign just like in a normal http get.
The API callers username used to login to Egosms.
The URL encoded password to your Ego Sms Account
The phone number the message is being sent to.
This represents the URL encoded SMS you are sending out. The message source must have a maximum of 160 characters.
This represents who the message is coming from. Sender can have a maximum of 11 characters and needs to be URL encoded too.
This represents level of priority. Priority can have values from (0-4) with 0: highest, 1: high, 2: Medium, 3: Low, 4: Lowest
This is returned if either the provided password or username is wrong.
This is if returned any of the fields (username /Â password / number / message / ‘senderid) is empty.
Occurs if there are insuffient funds of your Egosms Account.
Occurs if the account being used does not exist or is inactive or if the username is not set.
function SendSMS($username, $password, $sender, $number, $message)
{
$url = "www.egosms.co/api/v1/plain/?";
$parameters = "number=[number]&message=[message]&username=[username]&password=[password]&sender=[sender]";
$parameters = str_replace("[message]", urlencode($message) , $parameters);
$parameters = str_replace("[sender]", urlencode($sender) , $parameters);
$parameters = str_replace("[number]", urlencode($number) , $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;
}
$username = "Egosmstest";
$password = "egotest";
$sender = "Egosms";
$number = "+256788200915";
$message = "My First Message through Egosms";
echo SendSMS($username, $password, $sender, $number, $message);
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void saveMessageToFile(String data, String filename) throws IOException {
try (BufferedWriter writer = new BufferedWriter(new FileWriter(filename, true))) {
writer.write(data + "\n");
}
}
public static void main(String[] args) {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String data = reader.readLine().trim();
reader.close();
if (!data.isEmpty()) { saveMessageToFile(data, "msg_details.txt");
System.out.println("ok, msg delivered");
} else {
System.out.println("Error: No data received.");
}
} catch (IOException e) {
System.out.println("Error: " + e.getMessage());
}
}
}
# 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"
sender = "Egosms"
number = "256707811113"
message = "This is a message"
parameters = {
'username': html.escape(username),
'password': html.escape(password),
'number': html.escape(number),
'message': html.escape(message),
'sender': html.escape(sender)
}
timeout = 5
# Check for the internet connection and make the request
try:
# sending post request and saving response as response object
r = requests.get(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")
require 'net/http'
require 'uri'
def send_sms(username, password, sender, number, message)
url = "www.egosms.co/api/v1/plain/?"
parameters = "number=[number]&message=[message]&username=[username]&password=[password]&sender=[sender]"
parameters = parameters.gsub("[message]", URI.encode_www_form_component(message))
.gsub("[sender]", URI.encode_www_form_component(sender))
.gsub("[number]", URI.encode_www_form_component(number))
.gsub("[username]", URI.encode_www_form_component(username))
.gsub("[password]", URI.encode_www_form_component(password))
live_url = "https://" + url + parameters
uri = URI.parse(live_url)
response = Net::HTTP.get(uri)
return response
end
username = "Egosmstest"
password = "egotest"
sender = "Egosms"
number = "+256788200915"
message = "My First Message through Egosms"
result = send_sms(username, password, sender, number, message)
puts result
import curl
func SendSMS(username string, password string, sender string, number string, message string) string {
url := "https://www.egosms.co/api/v1/plain/"
parameters := "number=" + curl.Escape(number) + "&message=" + curl.Escape(message) + "&username=" + curl.Escape(username) + "&password=" + curl.Escape(password) + "&sender=" + curl.Escape(sender)
liveURL := url + "?" + parameters
c := curl.EasyInit()
defer c.Cleanup()
c.Setopt(curl.OPT_URL, liveURL)
var response string
c.Setopt(curl.OPT_WRITEFUNCTION, func(buf []byte, userdata interface{}) bool {
response = string(buf)
return true
})
err := c.Perform()
if err != nil {
fmt.Println("Error:", err)
}
return response
}
func main() {
username := "Egosmstest"
password := "egotest"
sender := "Egosms"
number := "+256788200915"
message := "My First Message through Egosms"
fmt.Println(SendSMS(username, password, sender, number, message))
}
using System;
using System.IO;
using System.Net;
class Program
{
static string SendSMS(string username, string password, string sender, string number, string message)
{
string url = "www.egosms.co/api/v1/plain/?";
string parameters = "number=[number]&message=[message]&username=[username]&password=[password]&sender=[sender]";
parameters = parameters.Replace("[message]", Uri.EscapeDataString(message));
parameters = parameters.Replace("[sender]", Uri.EscapeDataString(sender));
parameters = parameters.Replace("[number]", Uri.EscapeDataString(number));
parameters = parameters.Replace("[username]", Uri.EscapeDataString(username));
parameters = parameters.Replace("[password]", Uri.EscapeDataString(password));
string liveUrl = "https://" + url + parameters;
using (WebClient client = new WebClient())
{
string response = client.DownloadString(liveUrl);
return response;
}
}
static void Main()
{
string username = "Egosmstest";
string password = "egotest";
string sender = "Egosms";
string number = "+256788200915";
string message = "My First Message through Egosms";
string result = SendSMS(username, password, sender, number, message);
Console.WriteLine(result);
}
}
function SendSMS($username, $password, $sender, $number, $message)
{
$url = "www.egosms.co/api/v1/plain/?";
$parameters = "number=[number]&message=[message]&username=[username]&password=[password]&sender=[sender]";
$parameters = str_replace("[message]", urlencode($message) , $parameters);
$parameters = str_replace("[sender]", urlencode($sender) , $parameters);
$parameters = str_replace("[number]", urlencode($number) , $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;
}
$username = "Egosmstest";
$password = "egotest";
$sender = "Egosms";
$number = "+256788200915";
$message = "My First Message through Egosms";
echo SendSMS($username, $password, $sender, $number, $message);
require 'net/http'
require 'uri'
def send_sms(username, password, sender, number, message)
url = "www.egosms.co/api/v1/plain/?"
parameters = "number=[number]&message=[message]&username=[username]&password=[password]&sender=[sender]"
parameters = parameters.gsub("[message]", URI.encode_www_form_component(message))
.gsub("[sender]", URI.encode_www_form_component(sender))
.gsub("[number]", URI.encode_www_form_component(number))
.gsub("[username]", URI.encode_www_form_component(username))
.gsub("[password]", URI.encode_www_form_component(password))
live_url = "https://" + url + parameters
uri = URI.parse(live_url)
response = Net::HTTP.get(uri)
return response
end
username = "Egosmstest"
password = "egotest"
sender = "Egosms"
number = "+256788200915"
message = "My First Message through Egosms"
result = send_sms(username, password, sender, number, message)
puts result
# 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"
sender = "Egosms"
number = "256707811113"
message = "This is a message"
parameters = {
'username': html.escape(username),
'password': html.escape(password),
'number': html.escape(number),
'message': html.escape(message),
'sender': html.escape(sender)
}
timeout = 5
# Check for the internet connection and make the request
try:
# sending post request and saving response as response object
r = requests.get(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")
package http;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.StringJoiner;
public class SendHttp {
public static void main(String[] args) {
try {
//Parameters to add to the URL
LinkedHashMap params = new LinkedHashMap<>();
params.put("number", "256788200915");
params.put("message", "My first message through Egosms");
params.put("username", "EgosmsTest");
params.put("password", "egotest");
params.put("sender", "Egosms");
StringJoiner sj = new StringJoiner("&");
//Encoding the above parameters
for(Map.Entry entry : params.entrySet())
sj.add(URLEncoder.encode(entry.getKey(), "UTF-8") + "="
+ URLEncoder.encode(entry.getValue(), "UTF-8"));
String encoded_params = sj.toString();
//URL with necessary parameters added
String urlParams = "https://www.egosms.co/api/v1/plain/?"+encoded_params;
//Sending Http request to above composed URL
URL url = new URL(urlParams);
URLConnection con = url.openConnection();
HttpURLConnection http = (HttpURLConnection)con;
http.setRequestMethod("GET");
http.setDoOutput(true);
http.setRequestProperty("Content-Type", "text/plain; charset=UTF-8");
//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();
}
}
}
import curl
func SendSMS(username string, password string, sender string, number string, message string) string {
url := "https://www.egosms.co/api/v1/plain/"
parameters := "number=" + curl.Escape(number) + "&message=" + curl.Escape(message) + "&username=" + curl.Escape(username) + "&password=" + curl.Escape(password) + "&sender=" + curl.Escape(sender)
liveURL := url + "?" + parameters
c := curl.EasyInit()
defer c.Cleanup()
c.Setopt(curl.OPT_URL, liveURL)
var response string
c.Setopt(curl.OPT_WRITEFUNCTION, func(buf []byte, userdata interface{}) bool {
response = string(buf)
return true
})
err := c.Perform()
if err != nil {
fmt.Println("Error:", err)
}
return response
}
func main() {
username := "Egosmstest"
password := "egotest"
sender := "Egosms"
number := "+256788200915"
message := "My First Message through Egosms"
fmt.Println(SendSMS(username, password, sender, number, message))
}
Egosms Documentation
Tutorials
SENDING SMS