api-banner
Telephone: 0114 294 5993

Total integration.

api

apiUsing 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:

  • Send single and multiple text messages
  • Receive replies as emails via a long number or short code reply
  • Schedule text campaigns for future dates
  • Delivery receipts
  • Message balance
  • Add new contacts
  • Send SMS reminders from software
  • Send SMS updates at different stages of customer process
  • Send SMS promotional campaigns with voucher codes

Getting connected.

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.

Single message HTTP GET API.

https://faretext-api.co.uk:9443/api?action=sendmessage&username=USERNAME&password=PASSWORD&recipient=447xxxxxxxxx&originator=SENDERID&messagedata=MESSAGE

Multiple messages HTTP GET API.

https://faretext-api.co.uk:9443/api?action=sendmessage&messagecount=3&username=USERNAME&password=
PASSWORD&originator=SENDERID&recipient0=447xxxxxxxxx&messagedata0=MESSAGE0&recipient1=447xxxxxxxxx&messagedata1=MESSAGE1&recipient2=447xxxxxxxxx&messagedata0=MESSAGE2

Single message HTTP POST API.

<form action=https://faretext-api.co.uk:9443/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>

Multiple messages HTTP POST API.

<form action=https://faretext-api.co.uk:9443/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>

Code examples for sending SMS.

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.

<?php
########################################################
# Login information for FareText SMS Gateway
########################################################

$FareText_user = "USERNAME";
$FareText_password = "PASSWORD";
$FareText_url = "https://faretext-api.co.uk:9443/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("&lt;","&gt;"),$response).
           "</pre><br>"; }

      return($response);
}
?>

JAVA.

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  = "https://faretext-api.co.uk:9443/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());

                }
        }

}

C++.

#include <iostream&gt
#include <string&gt
#include <Windows.h&gt
using namespace std;
// dll description
HINSTANCE hDLL = NULL;
// This function unload ftApi.dll
void UnLoadFareTextApi()
{
        FreeLibrary((HMODULE)hDLL);
}
// This function load ftApi.dll
ftApi* LoadFareTextApi()
{
        HINSTANCE hDLL = NULL;
        SmsConnection conn;
        // Load ftApi.dll
        hDLL = LoadLibrary("ftApi.dll");
        if (hDLL != NULL)
        {
                conn = (SmsConnection)GetProcAddress((HMODULE)hDLL, "CreateSmsConnection");
            if (conn != NULL) return conn();
                UnLoadFareTextApi();
        }
        return NULL;
}
int main(int argc, char** argv)
{
        // Load ftApi dll and connect to it.
        ftApi* myConn = LoadFareTextApi();
        if (myConn == NULL)
        {
                // Error while connect to dll.
                cout << "Unable to load ftApi.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 9443.
        myConn-&gtopen("faretext-api.co.uk", 9443);
        // Login with default username and password
        // (USERNAME / PASSWORD)
        if(myConn-&gtlogin("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-&gtclose();
        // Unload ftApi.dll
        UnLoadFareTextApi();
        cout << "Done" << endl;
    return 0;
}

VB.NET.

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 = "https://faretext-api.co.uk:9443"
            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

ASP.

<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 = "https://faretext-api.co.uk" 'URL of that machine
                                'on where FareText SMS Gateway Server is running
                            dim ozSPort
                            ozSPort = "9443" '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>

Python.

###############################################

##   FareText - SMS Gateway Python example   ##

###############################################



import urllib



###############################################

###            FareText information         ###

###############################################



host = "https://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 += ":9443/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!"

Perl.

 #!/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 = "9443";

$username = "USERNAME";

$password = "PASSWORD";

$recipient = "NUMBER";

$message = "MESSAGE";





###############################################

### Putting together the final HTTP Request ###

###############################################

$url  = "https://"       . $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!"

}

TCL/TK.

   #!/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 "9443"

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 "https://$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

Coldfusion.

<cfset smsstring =
"https://faretext.co.uk:9443/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.

C#.
SQL.
AJAX.
Delphi.
VB 6.

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. 

Additional request parameters.

To make it that little bit more bespoke, you’ll find a detailed list below of all the available request parameters.

ParameterDescriptionPossible valuesExampleM/O*
action Specifies the HTTP API command sendmessage action=sendmessage M
username Specifies the username. The username and password parameters are used to authenticate the user. When you send an message it will be sent in the name of the authenticated user. The value must be urlencoced. string value, maximum length is 16 characters username=USERNAME M
password Specifies the password. The username and password parameters are used to authenticate the user. When you send an message it will be sent in the name of the authenticated user. The value must be urlencoced. string value, maximum length is 16 characters password=PASSWORD M
originator Specifies the sender address. This information will be displayed on the mobile phone, that receives the message. This is the sender address. This can be a telephone number, a short code or an alphanumeric sender address. The telephone number must can be formatted in local number format (e.g.06201234567) or in international number format (e.g.+36201234567). If you use an alphanumeric sender address (e.g.FareText), the characters must be encoded in UTF8 and the value must be urlencoded. string value, maximum length is 16 characters. NOTE: UK Network support upto 11 characters. originator=SENDERID O
recipient Specifies the recipient phone number. The message will be sent to this telephone number. The telephone number can be specified in local number format (e.g.06201234567), or in international number format (e.g.+36201234567).
More then one recipient addresses can be separated by a colon (e.g.: +36201234567,+36202222222)
The value must be urlencoded.
string value, maximum length is 16 characters recipient=47xxxxxxxxx M
messagetype Specifies the message type. The type of the SMS message data based on theMobile Message Type Specification. For text messages the message data will be plain text, for other message types it will be an XML document.  SMS:TEXT
SMS:WAPPUSH
...
Possible values can be found in the Mobil Message Type Specification
messagetype=SMS:TEXT O
messagedata Specifies the text or the data of the SMS message. The value must be encoded in UTF8 and must be urlencoded. string value, maximum length is 32768 characters messagedata=MESSAGE M
_charset_ Specifies the charset of the encoded data (if not specified utf-8 will be assumed). Newer browsers should set the value of _charset_ automatically. If your browser doesn't support this feature you can set is manually to: utf-8
windows-1250
iso-8859-1
iso-8859-2
...
(Supported character set values)
_charset_=iso-8859-2 O
sendondate Specifies the date and time, when the message should be sent.
The value must use the following date format: YYYY-MM-DD hh:mm:ss. The value must be url encoded
date value in YYYY-MM-DD hh:mm:ss format sendondate=2015-12-31%2021:00:00 - Example will send a message on 31st December 2015 at 21:00 O
responseformat After the gateway submits the SMS message, the gateway will return a web page indicating that the message was submitted successfully. The content of the webpage is formatted according to the responseformat parameter. You can have html text response to make it easy for humans to read it or you can have xml format to make it easy for software to process the response. xml (default)
html
urlencoded
responseformat=xml O
continueurl After the gateway submits the SMS message, the gateway will return a web page indicating that the message was submitted successfully. The content of the webpage is formatted according to the responseformat parameter. If the responseformat parameter is set to html, the webpage can contain a "Continue" link. If you specify the URL in this parameter the continue link will be displayed and it will point to the specified URL. The value of the URL must be urlencoded.

The URL you specify can contain keywords that will be replaced to state information corresponding to the submitted message. More information about possible keywords can be found in the "Submit URL keywords" guide.
string value, maximum length is 1024 characters continueurl=www.faretext.co.uk
or
continueurl=http%3A%2F%2Fwww.faretext.co.uk%2Findex.php

Note: the second example contains an urlencodedURL.
O
redirecturl After the gateway submits the SMS message, by default the gateway will return a web page indicating that the message was submitted successfully. Optionally you can ask the gateway to automatically redirect the browser to an URL you specify. If you specify an URL in the redirect parameter, the HTTP response returned by the SMS gateway will contain a redirect URL in the HTTP header. This will instruct the webbrowser to follow the link you have specified. The value of the URL must beurlencoded.

The URL you specify can contain keywords that will be replaced to state information corresponding to the submitted message. More information about possible keywords can be found in the "Submit URL keywords" guide.
string value, maximum length is 1024 characters redirecturl=www.faretext.co.uk

or

redirecturl=http%3A%2F%2Fwww.faretext.co.uk%2Findex.php

Note: the second example contains an urlencoded URL.
O
reporturl You can setup a webpage to process information about "delivered to network" and "delivered to handset"events. If you specify an URL in the reporturl parameter, your webpage will be called when these events happen. The value of the URL you specify in the reporturl parameter must be urlencoded.

The URL you specify can contain keywords that will be replaced to state information corresponding to the submitted message. More information about possible keywords can be found in the "Submit URL keywords" guide.

Please also note, that if you want the reporturl parameter to work, you must create a "HTTP server user" account and use it's username and password. The "Standard user" account does not support this option.
string value, maximum length is 1024 characters reporturl=http://www.Domain.com/SMS.php?
reporttype=$reporttype&messageid=$messageid)

Note: this is the urlencoded version of the following URL. Before this URL is called by the SMS gateway, the $reporttype and $messageid parameters will be replaced to the appropriate values:

reporturl=http%3A%2F%2Fwww.domain.com
%2Fsms.php%3Freporttype%3D%24reporttype
%26messageid%3D%24messageid

will be called as:
http://www.Domain.com/SMS.php?reporttype=deliveredtohandset&messageid=e99549d4-65f7-435d-ba19-de6b851801ce
O
maxresponse This number specifies the maximum of messages about which you will receive a feedback. If you exceed this number, your messages will be sent out but you won't receive feedback about them. By default, this parameter is set to 500 messages. number maxresponse=1000 O

* M = Mandatory parameter, O = Optional parameter

Get in touch.

 

Please type your full name.



Invalid email address.

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here Hide