Here we provide you sample source codes that might help you to jump-start with using SMSEagle’s API.

The code snippets are only examples of possible use. SMS API integration code helps you to get started with integration of SMSEagle device into your application.

PHP Send SMS using HTTP GET

    $base_url = 'https://url-of-smseagle/index.php/http_api/send_sms';
    $params = array(
        'access_token' => '0005gOjCOlMH8F2BP8',
        'to'       => '1234567',    
        'message'  => "my message", 
    );
    $data = '?'.http_build_query($params);
    $ret = fopen($base_url.$data,'r');
    $result = fread($ret,1024);
    fclose($ret);
    if (substr($result,0,2) == "OK") {
    echo "Message has been sent successfully!";
    } else {
    echo "Send message failed!";
    }

C# .NET Send SMS using HTTP GET

using System.Net;
using System.IO;
string baseUrl ="https://url-of-smseagle/index.php/http_api/send_sms";
WebClient client = new WebClient();
client.QueryString.Add("access_token", "0005gOjCOlMH8F2BP8");
client.QueryString.Add("to", "1234567");
client.QueryString.Add("message", HttpUtility.UrlEncode("My message"));
client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0");
Stream receivedStream = client.OpenRead(baseUrl);
StreamReader reader = new StreamReader(receivedStream);
string result = reader.ReadToEnd();
receivedStream.Close();
reader.Close();
return result;

Java Send SMS using HTTP GET

import java.io.*;
import java.net.*;
HttpURLConnection conn;
BufferedReader reader;
String line;
String result = "";
URL baseUrl ="https://url-of-smseagle/index.php/http_api/send_sms";
String charset = "UTF-8";
String query = String.format("access_token=%s&to=%s&message=%s&format=php",
URLEncoder.encode("0005gOjCOlMH8F2BP8", charset),
URLEncoder.encode("1234567", charset),
URLEncoder.encode("My message", charset)
);
url = new URL(baseUrl + "?" + query);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.connect();
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line = reader.readLine()) != null) {
result += line;
}
reader.close();
conn.disconnect();
System.out.println(result);
return result;

Java Send SMS using JSON-RPC

import java.io.*;
import java.net.*;
import net.sf.json.JSONObject;
HttpURLConnection connection = null;
OutputStreamWriter writer = null;
BufferedReader reader = null;
StringBuilder sbuilder = null;
URL serverAddress = null;
serverAddress = new URL("https://url-of-smseagle/index.php/jsonrpc/sms");
connection = (HttpURLConnection) serverAddress.openConnection();
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Accept", "application/json");
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.connect();
//
writer = new OutputStreamWriter(connection.getOutputStream());
JSONObject parameters=new JSONObject();
parameters.put("access_token", "0005gOjCOlMH8F2BP8");
parameters.put("to", "481234567");
parameters.put("message", "My message");
JSONObject json=new JSONObject();
json.put("method", "sms.send_sms");
json.put("params", parameters);
System.out.println(json);
writer.write(json.toString());
writer.close();
//
reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
sbuilder = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sbuilder.append(line + 'n');
}
connection.disconnect();
reader.close();
String result = sbuilder.toString();
System.out.println(result);
return result;

Python Send SMS using HTTP GET

import urllib
import urllib2
base_url = 'https://url-of-smseagle/index.php/http_api/send_sms'
query_args = { 'access_token':'0005gOjCOlMH8F2BP8', 'to':'1234567', 'message':'My message' }
encoded_args = urllib.urlencode(query_args)
url = base_url + '?' + encoded_args
result = urllib2.urlopen(url).read()

VB.NET Send SMS using HTTP GET

Imports System.Net
Imports System.IO
Imports System.Web
Dim baseUrl as String = "https://url-of-smseagle/index.php/http_api/send_sms"
Dim client as WebClient = New WebClient()
client.QueryString.Add("access_token", "0005gOjCOlMH8F2BP8")
client.QueryString.Add("to", HttpUtility.UrlEncode("1234567"))
client.QueryString.Add("message", HttpUtility.UrlEncode("My message"))
client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0")
Dim receivedStream As Stream = client.OpenRead(baseUrl)
Dim reader As StreamReader = new StreamReader(receivedStream)
Dim result As String = reader.ReadToEnd()
receivedStream.Close()
reader.Close()
return result

Perl Send SMS using HTTP GET

use strict;
use LWP::Simple;
use LWP::UserAgent;
use URI::Escape;
use Getopt::Long;
use HTTP::Request::Common;
my %args;
GetOptions(
'help' => $args{help},
'smseagleip=s' => $args{smseagleip},
'access_token' => $args{access_token},
'password=s' => $args{password},
'dstnum=s' => $args{dstnum},
'msg=s' => $args{msg}
);
if(defined($args{help}) || !defined($args{smseagleip}) || !defined($args{access_token}) || !defined($args{dstnum}) || !defined($args{msg}) ) {
print "Usage: script_name.pl --smseagleip --access_token --dstnum --msg n";
exit(0);
}
my $text = uri_escape($args{msg});
my $baseurl = "https://".$args{smseagleip}.'/index.php/http_api/';
my $req = GET $baseurl."send_sms?access_token=$args{access_token}&to=$args{dstnum}&message=$text";
my $ua = LWP::UserAgent->new();
my $rsp = $ua->request($req);
if($rsp->content == "OK") {
print "Message sent succesfully to $args{dstnum}n";
} else {
print "Sent failure: " . $rsp->content . "n";
}

Powershell Send SMS using HTTP GET

param(
[string]$to = $(throw "Script usage: sendsms.ps1 -to -message "),
[string]$message = $(throw "Script usage: sendsms.ps1 -to -message ")
)
Add-Type -AssemblyName System.Web
$smseagleip = "192.168.0.101"
$access_token = "0005gOjCOlMH8F2BP8"
$smstext = [System.Web.HttpUtility]::UrlEncode($message)
$url = "https://$smseagleip/index.php/http_api/send_sms?access_token=$access_token&to=$to&message=$smstext"
$client = New-Object system.Net.WebClient
$result = $client.downloadString($url)
Write-Host $result

Powershell Send SMS using JSON-RPC

$smseagleUrl='https://192.168.1.101/index.php/jsonrpc/sms'
$smseagleToken='0005gOjCOlMH8F2BP8'
$msgReceiver='123456789'
$msgText='Message test'
$header = @{"Content-Type"="text/plain"}

$jsonBody=@{method="sms.send_sms";params=@{access_token=$smseagleToken;to=$msgReceiver;message=$msgText}} | ConvertTo-Json -Compress

Invoke-RestMethod -Uri $smseagleUrl -Headers $header -Body $jsonBody -Method Post

CURL Send SMS using HTTP GET

curl -G --data-urlencode "to=+48123456789" --data-urlencode "message=my message" https://smseagleip/index.php/http_api/send_sms?access_token=0005gOjCOlMH8F2BP8

CURL Send SMS using JSON-RPC

curl -H "Content-Type: application/json" -X POST -d '{"method":"sms.send_sms", "params":{"access_token":"0005gOjCOlMH8F2BP8","to":"+48123456789","message":"My message"}}' https://smseagleip/index.php/jsonrpc/sms

C++ Send SMS using HTTP GET

#include 
#include 
#include <curl/curl.h>

int main(void) {
  CURL *curl;
  CURLcode res;
  using namespace std;

  curl = curl_easy_init();
  if(curl) {

    //prepare URL with parameters   
    string path = "https://smseagleip/index.php/http_api/send_sms?access_token=0005gOjCOlMH8F2BP8";

    char *receipent = curl_easy_escape(curl, "+4812345678", 0);
    char *message = curl_easy_escape(curl, "my message", 0);

    string url;

    url += path;
    url += "&to=";
    url += receipent;
    url += "&message=";
    url += message;

    char * urlchar = new char[url.size() + 1];
    std::copy(url.begin(), url.end(), urlchar);
    urlchar[url.size()] = '\0'; 

    curl_easy_setopt(curl, CURLOPT_URL, urlchar);

    //send HTTP GET request
    res = curl_easy_perform(curl);

    //check for errors
    if(res != CURLE_OK)
      fprintf(stderr, "curl_easy_perform() failed: %s\n",
              curl_easy_strerror(res));

    curl_easy_cleanup(curl);
  }
 return 0;
}

VBA Send SMS using HTTP GET

Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
UrlOfSmseagle = "https://url-of-smseagle"
Phone = "123456789"
Message = "My message"
Url = UrlOfSmseagle & "/http_api/send_sms/?access_token=" & APIAccessToken & "&to=" & Phone & "&message=" & Message
objHTTP.Open "GET", Url, False
objHTTP.Send
Debug.Print objHTTP.ResponseText

Other languages

You can also use Ruby, C/C++, VBScript, or other programming/scripting language of your choice. Just use the tools you know best. How to to it? Create a webclient and call HTTP GET as described above. In response you will get OK or ERROR message.