Basic connectivity

If you want to just send SMS and dont want to use our wrappers, it can be done with the minimum of effort using our basic SMS API. If you have any integration questions then just call us, 0117 205 0202 – option 3.

 

Skills Required

  • Understanding of the HTTP (GET) protocol
  • Some knowledge of a programming language
  • Basic XML

 

Fast and easy: send SMS

In your preferred programming language all you need to do is generate a GET request like this:

https://api.textmarketer.co.uk/gateway/?username=u&password=p&to=4477777777&message=test+message&orig=my_script

If you want to send to multiple numbers, use a comma delimited list. Here is an example:

https://api.textmarketer.co.uk/gateway/?username=u&password=p&to=4477777777,4477777778,4477777779&message=test+message&orig=my_script

Beware that, due to limitations on the HTTP protocol, sending to multiple numbers is limited to 500 recipients. So, if you want to send the same SMS to more than 500 recipients, e.g. 750 recipients, you'll have to send it in two batches: 500 + 250.

 

Code Examples for sending SMS

Get started instantly. You can copy & paste the code examples below for use with our SMS API Gateway.

PHP

<?php
    // Simple SMS send function
    function sendSMS($username, $password, $to, $message, $originator) {
        $URL = 'http://api.textmarketer.co.uk/gateway/'."?username=$username&password=$password&option=xml";
        $URL .= "&to=$to&message=".urlencode($message).'&orig='.urlencode($originator);
        $fp = fopen($URL, 'r');
        return fread($fp, 1024);
    }
    // Example of use 
    $response = sendSMS('myUsername', 'myPassword', '4477777777', 'My test message', 'TextMessage');
    echo $response;?>

JAVA

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;

// Simple send SMS programm
public class SendSMS {
    public static String sendSMS(String username, String password, String to, String message, String originator) {
        String url;
        StringBuilder inBuffer = new StringBuilder();
        try {
            url = "http://api.textmarketer.co.uk/gateway/" +
                "?username=" + username + "&password=" + password + "&option=xml" +
                "&to=" + to + "&message=" + URLEncoder.encode(message, "UTF-8") +
                "&orig=" + URLEncoder.encode(originator, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            return null;
        }
        try {
            URL tmUrl = new URL(url);
            URLConnection tmConnection = tmUrl.openConnection();
            tmConnection.setDoInput(true);
            BufferedReader in = new BufferedReader(new InputStreamReader(tmConnection.getInputStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null)
                inBuffer.append(inputLine);
            in.close();
        } catch (IOException e) {
            return null;
        }
        return inBuffer.toString();
    }
    public static void main(String[] args) {
        // Example of use 
        String response = sendSMS("myUsername", "myPassword", "4477777777", "My test message", "TextMessage");
        System.out.println(response);
    }
}

C#/.NET

using System;
using System.IO;
using System.Net;
using System.Text;
using System.Web;

namespace SendSMS {
    class Program {
        public static string SendSMS(string username, string password, string to, string message, string originator) {
            StringBuilder sb  = new StringBuilder();
            byte[]        buf = new byte[1024];
            string url = "http://api.textmarketer.co.uk/gateway/" +
                "?username=" + username + "&password=" + password + "&option=xml" +
                "&to=" + to + "&message=" + HttpUtility.UrlEncode(message) +
                "&orig=" + HttpUtility.UrlEncode(originator);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream resStream = response.GetResponseStream();
            string tempString = null;
            int count = 0;
            do {
                count = resStream.Read(buf, 0, buf.Length);
                if (count != 0) {
                    tempString = Encoding.ASCII.GetString(buf, 0, count);
                    sb.Append(tempString);
                }
            }
            while (count > 0);
            return sb.ToString();
        }
        static void Main(string[] args) {
            string respXML = SendSMS("myUsername", "myPassword", "4477777777", "My test message", "TextMessage");
            Console.WriteLine(respXML);
       }
    }
}

C++/CLI

#include <iostream>
#include <string>
#using <System.Dll>
#using <System.Web.Dll>

using namespace std;
using namespace System;
using namespace System::Web;
using namespace System::Net;
using namespace System::IO;
using namespace System::Runtime::InteropServices;

ref class SMSSender
{

private:
        static String^ Username = "myUsername";
        static String^ Password = "myPassword";

public:
        SMSSender()
        {}
        String^ SendSMS(String^ To, String^ Message, String^ From)
        {
                Message = HttpUtility::UrlEncode(Message);
                From = HttpUtility::UrlEncode(From);
                String^ URL = "http://api.textmarketer.co.uk/gateway/?&option=xml&username=" + Username + "&password=" + Password + "&message=" + Message + "&orig=" + From + "&to=" + To;
                WebRequest^ Handle = WebRequest::Create(URL);
                WebResponse^ HTTPResponse = Handle->GetResponse();
                StreamReader^ Stream = gcnew StreamReader(HTTPResponse->GetResponseStream());
                String^ Response = Stream->ReadToEnd()->Trim();
                HTTPResponse->Close();
                return Response;
        }
};

int main() {
        SMSSender^ test = gcnew SMSSender();
        String^ resp = test->SendSMS("4477777777", "My test message", "TextMessage");
        Console::WriteLine(resp);
        return 0;
}

C

/* * Send SMS C/C++ example need curllib download from http://curl.haxx.se/ */

#include <stdio.h>
#include <tchar.h>
#include <string.h>
#include <curl/curl.h>
#define URLSIZE 256

struct MemoryStruct {
        char *memory;
        size_t size;
};

/* Converts a hex character to its integer value */

char from_hex(char ch) {
        return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10;
}

/* Converts an integer value to its hex character*/

char to_hex(char code) {
        static char hex[] = "0123456789abcdef";
        return hex[code & 15];
}

/* Returns a url-encoded version of str */

char *url_encode(char *str) {
        char *pstr = str, *buf = (char *)malloc(strlen(str) * 3 + 1), *pbuf = buf;
        while (*pstr) {
                if (isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~')
                        *pbuf++ = *pstr;
                else if (*pstr == ' ')
                        *pbuf++ = '+';
                else
                        *pbuf++ = '%', *pbuf++ = to_hex(*pstr >> 4), *pbuf++ = to_hex(*pstr & 15);
                pstr++;
        }
        *pbuf = '\0';
        return buf;
}

/* CURL Callback write function */

static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp) {
        size_t realsize = size * nmemb;
        struct MemoryStruct *mem = (struct MemoryStruct *)userp;
        mem->memory = (char *)realloc(mem->memory, mem->size + realsize + 1);
        if (mem->memory == NULL) {
                /* out of memory! */
                printf("not enough memory (realloc returned NULL)\n");
                exit(EXIT_FAILURE);
        }
        memcpy(&(mem->memory[mem->size]), contents, realsize);
        mem->size += realsize;
        mem->memory[mem->size] = 0;
        return realsize;
}

/* Send SMS */

char * sendSMS(const char *username, const char *password, const char *to, char *message, char *originator) {
        static char url[URLSIZE] = "http://api.textmarketer.co.uk/gateway/?option=xml";
        char *encoded;
        CURL *curl;
        CURLcode res;
        struct MemoryStruct chunk;
        chunk.memory = (char *)malloc(1);  /* will be grown as needed by the realloc above */
        chunk.size = 0;    /* no data at this point */
        curl = curl_easy_init();
        if(curl) {
                strcat_s(url, URLSIZE, "&username=");
                strcat_s(url, URLSIZE, username);
                strcat_s(url, URLSIZE, "&password=");
                strcat_s(url, URLSIZE, password);
                strcat_s(url, URLSIZE, "&to=");
                strcat_s(url, URLSIZE, to);
                strcat_s(url, URLSIZE, "&message=");
                encoded = url_encode(message);
                strcat_s(url, URLSIZE, encoded);
                free(encoded);
                encoded = url_encode(originator);
                strcat_s(url, URLSIZE, "&orig=");
                strcat_s(url, URLSIZE, encoded);
                free(encoded);
                curl_easy_setopt(curl, CURLOPT_URL, url);
                /* send all data to this function  */
                curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
                /* we pass our 'chunk' struct to the callback function */
                curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
                if((res = curl_easy_perform(curl)) != CURLE_OK) {
                        return NULL;
                }
                curl_easy_cleanup(curl);
        }
        return chunk.memory;
}

int main(void) {
        char *response;
        response = sendSMS("myuser", "mypass", "4477777777", "test test test", "me");
        if(response != NULL) {
                printf(response);
                free(response);
        }
        getchar();
        return 0;
}

VB.NET

Imports System.Web

Module Module1
    Public Function SendSMS(ByVal username As String, ByVal password As String, ByVal toPhone As String,
                            ByVal message As String, ByVal originator As String)
        Dim webClient As New System.Net.WebClient
        Dim url As String = "http://api.textmarketer.co.uk/gateway/?username=" &
                username & "&password=" & password & "&option=xml" &
                "&to=" & toPhone & "&message=" & System.Web.HttpUtility.UrlEncode(message) &
                "&orig=" & System.Web.HttpUtility.urlencode(originator)
        Dim result As String = webClient.DownloadString(url)
        SendSMS = result
    End Function

    Sub Main()
        Dim result As String = SendSMS("myUsername", "myPassword", "4477777777", "My test message", "TextMessage")
        Console.WriteLine(result)
        Console.ReadKey()
    End Sub

End Module

ASP

<%@language=JScript%><%
    username = "myUsername";
    password = "myPassword";
    to = "4477777777";
    message = Server.URLEncode("My test message");
    originator  = Server.URLEncode("TextMessage");
    url = "http://api.textmarketer.co.uk/gateway/?&option=xml" +
            "&username=" + username + "&password=" + password +
            "&to=" + to + "&message=" + message +
            "&orig=" + originator;
    var objSrvHTTP;
    objSrvHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP");
    objSrvHTTP.open(url, false);
    objSrvHTTP.send();
    Response.ContentType = "text/xml";
    xmlResp = objSrvHTTP.responseXML.xml;
    Response.Write(xmlResp);%>

Ruby

require 'net/http'
require 'uri'

def send_sms(username, password, to, message, originator)
  requested_url = 'http://api.textmarketer.co.uk/gateway/?option=xml' +
                "&username=" + username + "&password=" + password +
                "&to=" + to + "&message=" + URI.escape(message) +
                "&orig=" + URI.escape(originator)
  url = URI.parse(requested_url)
  full_path = (url.query.blank?) ? url.path : "#{url.path}?#{url.query}"
  the_request = Net::HTTP::Get.new(full_path)
  the_response = Net::HTTP.start(url.host, url.port) { |http|
    http.request(the_request)
  }
  raise "Response was not 200, response was #{the_response.code}" if the_response.code != "200"
  return the_response.bodyend
resp = send_sms('myUsername', 'myPassword', '4477777777', 'My test message', 'TextMessage')

puts(resp)

Our example code is an illustration of how you might integrate with our systems and is not certified for production environments. You are responsible for testing and QA.

 

Feature List

  • Send SMS
  • Send SMS to multiple numbers
  • Schedule SMS

Basic SMS Gateway API PDF documents...

Example uses of the SMS Gateway API

  • SMS appointment reminders from software
  • SMS alerts from software such as server monitoring software
  • Sign up confirmation texts and forgot password texts
  • Order confirmations by SMS such as train tickets or cinema tickets
  • SMS notifications when products back in stock for registered users
  • 'Mail merged' data SMS campaigns for coupon code promotions

In fact, any communication where your application might send an email, you can send a text message instead (or as well). The main benefit is that 99% of text messages are read, compared to only around 10% of emails. So, if the information you need to send is important, then sending a text via the SMS Gateway API is your solution.

This SMS Gateway API is great for a quick set up for sending out text messages. Often, people will also want to pipe text responses back into a system or to an email address. You may consider a virtual mobile number to achieve this.

 

What some of our clients say...

Text Marketer Clients

“This is so easy to use, we got up and running in 5 minutes.”

Sales increased by 32% using this sms service”

“Low priced and incredibly efficient

Independent Reviews

ReviewCentre Reviews

reviewcentre

 “Excellent Product, Support, Documentation and Price”

Really impressed with the whole package, after looking at a few alternatives for integrating SMS to web projects, I found this by the best documented API and was up and running very quickly. The customer service has been first class too. Real value for money.

 “5 Star value for money”

Simple as anything to sign up, great current promotion on, and the cheapest I found for this service. Can access from anywhere as your account is through the web. It also has the functionality to schedule messages, so you can have them all set up and sent whenever you want them to.

 “Suits our needs perfectly”

Text Marketer certainly live up to their tag line of them delivering and us saving. As well as this, they also deliver first class customer service to their clients. I highly recommend them.

 5 star service by Text Marketer

 5 star service by Text Marketer

 5 star service by Text Marketer

 

 “Simple, great value and excellent customer service”

I've set up my website to send txt messages to customers, it took me less than a few hours to get something working using the free txts that text marketer give you to get up and running... Great pricing, simple API, can't it recommend enough.

 “Easy to do business with...”

Very easy to use web interface, lots of good features and ideas on the site to help with your SMS based marketing. Plus the SMS credits are very competitively priced. What more do you need to know?

 “Very Helpful and Cheaper than the rest”

Not only is TextMarketer by far the cheapest it is also the most simple to use! We have had a constant contact to the company who has been very helpful along the way. I’m sure we will stick with this company if it starts as we mean to go on. Many Thanks.

 5 star service by Text Marketer

 5 star service by Text Marketer

 5 star service by Text Marketer

Click to see more ReviewCentre reviews

Google Reviews

 “Best prices easy to set up and reliable.”

 “This company has been great to do business with.”

 “Excellent service - very efficient and easy to do business with.”

 5 star service by Text Marketer

 5 star service by Text Marketer

 5 star service by Text Marketer

Click to see more Google reviews

Get started today and you’ll have your first message sent in minutes

Use promo code DEV6 and get 50 free credits.

Sign Up for Bulk SMS service with Text Marketer

Follow Us

For all the latest news, follow us:

Bulk SMS RSS FeedFollow TextMarketer on TwitterFollow TextMarketer on Facebook

Follow TextMarketer on SlideshareFind Text Marketer on Google PlusFind Text Marketer on Google PlusLinkedIn

 
 
Contacts

Tel: +44 (0) 117 205 0202

txtUs: 07860 021 840

Fax: 0870 458 0383

 

Email

This email address is being protected from spambots. You need JavaScript enabled to view it.