
Using our HTTP API technology means it’s never been easier to connect up our Bulk SMS service with your organisation.
Integrating our technology into your application or software offers you a true communication extension; it works seamlessly with the technology you and your employees are already familiar with.
This is ideal for those needing texts with both Marketing and Adding Value functions, which require something built-in and running in the background.
Designed to deal with high volumes of business texts, customers connected through this delivery method can:
Once you’ve been allocated your user name and password, you need to generate a GET or POST request. This you can do in your preferred programming language. Use the information below for single or multiple messages, changing the fields in red to your relevant information. Please note that if you are using the Standard route this has a fixed Sender ID (the originator will be ignored). Only Premium supports a dynamic Sender ID, allowing for this to be changed.
http://faretext-api.co.uk:9501/api?action=sendmessage&username=USERNAME&password=PASSWORD&recipient=447xxxxxxxxx&originator=SENDERID&messagedata=MESSAGE
http://faretext-api.co.uk:9501/api?action=sendmessage&messagecount=3&username=USERNAME&password= PASSWORD&originator=SENDERID&recipient0=447xxxxxxxxx&messagedata0=MESSAGE0&recipient1=447xxxxxxxxx&messagedata1=MESSAGE1&recipient2=447xxxxxxxxx&messagedata0=MESSAGE2
<form action=http://faretext-api.co.uk:9501/api method=post><br> action: <input type=text name=action value=sendmessage><br> username: <input type=text name=username value=USERNAME><br> password: <input type=text name=password value=PASSWORD><br> originator: <input type=text name=originator value=SENDERID><br> recipient: <input type=text name=recipient value=447xxxxxxxxx><br> messagedata: <input type=text name=messagedata0 value='MESSAGE'><br> <input type=submit value=OK> </form>
<form action=http://faretext-api.co.uk:9501/api method=post><br> action: <input type=text name=action value=sendmessage><br> messagecount: <input type=text name=messagecount value=2><br> username: <input type=text name=username value=USERNAME><br> password: <input type=text name=password value=PASSWORD><br> originator: <input type=text name= originator value=SENDERID><br> recipient0: <input type=text name=recipient0 value=447xxxxxxxxx><br> messagedata0: <input type=text name=messagedata0 value=''MESSAGE0''><br> recipient1: <input type=text name=recipient1 value=447xxxxxxxxx><br> messagedata1: <input type=text name=messagedata1 value='''MESSAGE1'><br> <input type=submit value=OK> </form>
Now that you’re armed with your user name and password, copy and paste the example codes below to start using our API in your preferred format.
<?php
########################################################
# Login information for FareText SMS Gateway
########################################################
$FareText_user = "USERNAME";
$FareText_password = "PASSWORD";
$FareText_url = "http://faretext-api.co.uk:9501/api?";
########################################################
# Functions used to send the SMS message
########################################################
function httpRequest($url){
$pattern = "/http...([0-9a-zA-Z-.]*).([0-9]*).(.*)/";
preg_match($pattern,$url,$args);
$in = "";
$fp = fsockopen("$args[1]", $args[2], $errno, $errstr, 30);
if (!$fp) {
return("$errstr ($errno)");
} else {
$out = "GET /$args[3] HTTP/1.1\r\n";
$out .= "Host: $args[1]:$args[2]\r\n";
$out .= "User-agent: FareText PHP client\r\n";
$out .= "Accept: */*\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
$in.=fgets($fp, 128);
}
}
fclose($fp);
return($in);
}
function FareTextSend($phone, $msg, $debug=false){
global $FareText_user,$FareText_password,$FareText_url;
$url = 'username='.$FareText_user;
$url.= '&password='.$FareText_password;
$url.= '&action=sendmessage';
$url.= '&recipient='.urlencode($phone);
$url.= '&messagedata='.urlencode($msg);
$urltouse = $FareText_url.$url;
if ($debug) { echo "Request: <br>$urltouse<br><br>"; }
//Open the URL to send the message
$response = httpRequest($urltouse);
if ($debug) {
echo "Response: <br><pre>".
str_replace(array("<",">"),array("<",">"),$response).
"</pre><br>"; }
return($response);
}
?>
import java.net.*;
public class Java_example_httprequest {
public static void main(String[] args) {
try {
String recipient = "NUMBER";
String message = "MESSAGE";
String username = "USERNAME";
String password = "PASSWORD";
String originator = "SENDERID";
String requestUrl = "http://faretext-api.co.uk:9501/api?action=sendmessage&" +
"username=" + URLEncoder.encode(username, "UTF-8") +
"&password=" + URLEncoder.encode(password, "UTF-8") +
"&recipient=" + URLEncoder.encode(recipient, "UTF-8") +
"&messagetype=SMS:TEXT" +
"&messagedata=" + URLEncoder.encode(message, "UTF-8") +
"&originator=" + URLEncoder.encode(originator, "UTF-8") +
"&serviceprovider=GSMModem1" +
"&responseformat=html";
URL url = new URL(requestUrl);
HttpURLConnection uc = (HttpURLConnection)url.openConnection();
System.out.println(uc.getResponseMessage());
uc.disconnect();
} catch(Exception ex) {
System.out.println(ex.getMessage());
}
}
}
#include <iostream>
#include <string>
#include <Windows.h>
using namespace std;
// dll description
HINSTANCE hDLL = NULL;
// This function unload ozApi.dll
void UnLoadOzekiApi()
{
FreeLibrary((HMODULE)hDLL);
}
// This function load ozApi.dll
ozApi* LoadOzekiApi()
{
HINSTANCE hDLL = NULL;
SmsConnection conn;
// Load ozApi.dll
hDLL = LoadLibrary("ozApi.dll");
if (hDLL != NULL)
{
conn = (SmsConnection)GetProcAddress((HMODULE)hDLL, "CreateSmsConnection");
if (conn != NULL) return conn();
UnLoadOzekiApi();
}
return NULL;
}
int main(int argc, char** argv)
{
// Load ozApi dll and connect to it.
ozApi* myConn = LoadOzekiApi();
if (myConn == NULL)
{
// Error while connect to dll.
cout << "Unable to load ozApi.dll" << endl;
system("pause");
return 0;
}
else
{
// Dll is loaded.
cout << "Loaded" << endl;
}
// Connect to FareText SMS Gateway
// on localhost (faretext-api.co.uk) at port 9500.
myConn->open("faretext-api.co.uk", 9500);
// Login with default username and password
// (USERNAME / PASSWORD)
if(myConn->login("USERNAME", "PASSWORD"))
{
// Send a test message to 447xxxxxxxxxx
myConn->sendMessage("447xxxxxxxxxx", "MESSAGE.");
}
else
{
// If username/password is bad
cout << "Bad usename or password" << endl;
}
// Closing connection.
cout << "Closing connection..." << endl;
myConn->close();
// Unload ozApi.dll
UnLoadOzekiApi();
cout << "Done" << endl;
return 0;
}
Imports System
Imports System.IO
Imports System.Net
Imports System.Text
Imports System.Web
Public Class fMain
Private Sub bSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bSend.Click
Dim request As HttpWebRequest
Dim response As HttpWebResponse = Nothing
Dim url As String
Dim username As String
Dim password As String
Dim host As String
Dim originator As String
Try
host = "http://faretext-api.co.uk:9501"
originator = "SENDERID"
username = "USERNAME"
password = "PASSWORD"
url = host + "/api?action=sendmessage&" _
& "username=" & HttpUtility.UrlEncode(username) _
& "&password=" + HttpUtility.UrlEncode(password) _
& "&recipient=" + HttpUtility.UrlEncode(tbReceiver.Text) _
& "&messagedata=" + HttpUtility.UrlEncode(tbMessage.Text) _
& "&originator=" + HttpUtility.UrlEncode(originator) _
& "&responseformat=html"
request = DirectCast(WebRequest.Create(url), HttpWebRequest)
response = DirectCast(request.GetResponse(), HttpWebResponse)
MessageBox.Show("Response: " & response.StatusDescription)
Catch ex As Exception
End Try
End Sub
End Class
<form method="post" action="">
<table align="center">
...
<tr>
<td colspan="2" align="center">
<%
if Request.form("recipient") = "" then
response.write("<font color='red'>Recipient field mustn't be empty!</font>")
else
dim createdURL
createdURL = "" 'It will be the entire URL that we
'send to FareText SMS Gateway Server
dim ozSURL
ozSURL = "http://faretext-api.co.uk" 'URL of that machine
'on where FareText SMS Gateway Server is running
dim ozSPort
ozSPort = "9501" 'Port number on which FareText SMS
'Gateway Server is listening to
dim ozUser
ozUser = server.URLEncode("USERNAME") 'User name of that user
'who can login to FareText SMS Gateway Server
dim ozPassw
ozPassw = server.URLEncode("PASSWORD") 'Password of user above
dim ozOriginator
ozOriginator = server.URLEncode("+SENDERID") 'originator of the message
dim ozRecipient
ozRecipient = server.URLEncode(Request.form("447xxxxxxxxxx")) 'Recipient of
'the message
dim ozMessageText
ozMessageData = server.URLEncode(Request.form("messagetext"))
'Message text we want to send
createdURL = ozSURL & ":" & ozSPort & "/httpapi?action=sendMessage" &
"&username=" & ozUser & "&password=" & ozPassw & "&messageType=" &
"&originator=" & ozOriginator &
"&recipient=" & ozRecipient & "&messageData=" &
ozMessageData
response.Write("<iframe src=" & createdURL & " width='500'>")
end if
%>
</td>
</tr>
</table>
</form>
###############################################
## FareText - SMS Gateway Python example ##
###############################################
import urllib
###############################################
### FareText information ###
###############################################
host = "http://faretext-api.co.uk"
user_name = "USERNAME"
user_password = "PASSWORD"
recipient = "NUMBER"
message_body = "MESSAGEn"
###############################################
### Putting together the final HTTP Request ###
###############################################
http_req = host
http_req += ":9501/api?action=sendmessage&username="
http_req += urllib.quote(user_name)
http_req += "&password="
http_req += urllib.quote(user_password)
http_req += "&recipient="
http_req += urllib.quote(recipient)
http_req += "&messagedata="
http_req += urllib.quote(message_body)
################################################
#### Sending the message ###
################################################
get = urllib.urlopen(http_req)
req = get.read()
get.close()
################################################
### Verifying the response ###
################################################
if req.find("Message accepted for delivery") > 1:
print "Message successfully sent"
else:
print "Message not sent! Please check your settings!"
#!/usr/bin/perl
###############################################
## FareText - SMS Gateway Perl example ##
###############################################
use HTTP::Request;
use LWP::UserAgent;
use URI::Escape;
###############################################
### FareText information ###
###############################################
$host = "faretext-api.co.uk ";
$port = "9501";
$username = "USERNAME";
$password = "PASSWORD";
$recipient = "NUMBER";
$message = "MESSAGE";
###############################################
### Putting together the final HTTP Request ###
###############################################
$url = "http://" . $host;
$url .= ":" . $port;
$url .= "/api?action=sendmessage&";
$url .= "username=" . uri_escape($username);
$url .= "&password=" . uri_escape($password);
$url .= "&recipient=" . uri_escape($recipient);
$url .= "&messagedata=" . uri_escape("$message");
################################################
#### Sending the message ###
################################################
$request = HTTP::Request->new(GET=>$url);
$useragent = LWP::UserAgent->new;
$response = $useragent->request($request);
################################################
### Verifying the response ###
################################################
if ($response->is_success) {
print "Message successfully sent"
} else {
print "Message not sent! Please check your settings!"
}
#!/usr/bin/tclsh
package require http
###############################################
## FareText - SMS Gateway TCL example ##
###############################################
###############################################
## Functions for url - encoding ###
###############################################
proc init {} {
variable map
variable alphanumeric a-zA-Z0-9
for {set i 0} {$i <= 256} {incr i} {
set c [format %c $i]
if {![string match \[$alphanumeric\] $c]} {
set map($c) %[format %.2x $i]
}
}
array set map { " " + \n %0d%0a }
}
proc url-encode {string} {
variable map
variable alphanumeric
regsub -all \[^$alphanumeric\] $string {$map(&)} string
regsub -all {[][{})\\]\)} $string {\\&} string
return [subst -nocommand $string]
}
init
###############################################
### FareText information ###
###############################################
set host "faretext-api.co.uk"
set port "9501"
set username [url-encode "USERNAME"]
set password [url-encode "PASSWORD"]
set recipient [url-encode "NUMBER"]
set message [url-encode "MESSAGE"]
###############################################
### Putting together the final HTTP Request ###
###############################################
set url "http://$host:$port/api?action=sendmessage&username=$username
&password=$password&recipient=$recipient&messagedata=$message"
################################################
#### Sending the message ###
################################################
set http [::http::geturl $url]
################################################
### Verifying the response ###
################################################
upvar #0 $http state
if {$state(http) == "HTTP/1.1 200 OK"} {
puts "Message successfully sent\n"
} else {
puts "Message not sent! Please check your settings!\n"
}
exit
<cfset smsstring = "http://faretext:9501/api?action=sendmessage&username=USERNAME&password=PASSWORD&recipient=#URLEncodedFormat(to)#&messagedata=#URLEncodedFormat(msg)#"> <cfhttp url="#smsstring#"> <cfoutput> #cfhttp.filecontent# </cfoutput>
We can also supply code for the following. However, these will have to be generated specifically for you – please drop us an email with your request and we’ll send these over.
Can’t see your programming language? Technology is constantly advancing and, although we regularly update our website with any new coding, your particular language may not have been posted yet. We’re confident that we can provide example code for almost every programming language, so if it’s not there, please just let us know and we’ll see what we can do.
Please note, our example code provides you with an insight on how you might integrate with our systems. It offers an illustration only – for further information and API documentation, please just give us a call.
Interested? Then simply Register, using the link near the top right and we’ll generate you a user name and password within a couple of hours, and throw in 100 free texts.