SMS API

API change history

SMS API contains methods used to send notifications via Short Message Service, directly to your client's phone

Send SMS

This method initiates sending SMS to specified phone number. Long messages are automatically split into fragments. Sending takes place if there is enough credits in your account - you need to have at least as many credits as there are message fragments. Unicode is not currently supported - only standard GSM alphabet.

Try it

Request

Request URL

Request parameters

  • (optional)
    boolean

    When set to true, suppression list is ignored, otherwise number (that SMS is being sent to) is compared against suppression list and only if it's not in the list, SMS is sent to recipient. If mobile number is in suppression list, 403 error is returned

Request headers

  • string

    The authorization token. The token will be in the format "Bearer API_KEY". For example: "Authorization: Bearer 123456789". Please include the space between "Bearer" and "API_KEY".

Request body

Request body must contain a JSON object with the following properties:

  • Number: recipient phone number; can contain leading '+' symbol, but doesn't need to, and
  • Text: Message text
  • Id: Optional user-assigned message ID value

{
  "Text": "Hello again!",
  "Number": "27801234567",
  "Id": "slkedfjo938urxcvx9ejos"
}
{
  "type": "object",
  "properties": {
    "Text": {
      "type": "string",
      "description": "Message text"
    },
    "Number": {
      "type": "string",
      "description": "Message recipient phone number"
    },
    "Id": {
      "type": "string",
      "description": "User assigned (external) message ID value"
    }
  }
}

Responses

200 OK

Message was successfully scheduled for sending. Response body contains details about the message. Message has an initial status - "Accepted", meaning it's accepted by our SMS service and is about to be dispatched to recipient. Each message status is updated according to delivery status. Possible values are:

  • Enroute,
  • Delivered,
  • Expired,
  • Deleted,
  • Undeliverable,
  • Accepted,
  • Unknown,
  • Rejected or
  • Waiting (for delivery)

In order to check current message status, another method is to be called, to read message details. Use MessageId value returned in response body. Please have in mind that some characters increase message length by 2 due to special handling: ^|€[]~

Representations

{
  "Date": "2021-11-30T03:16:17Z",
  "MessageId": 100,
  "MessageSize": 2,
  "Number": "27831122334",
  "Text": "Hello there",
  "Status": "Enroute",
  "RemainingCreditCount": 101,
  "Id": "29384729847293847987345"
}
{
  "type": "object",
  "properties": {
    "Date": {
      "type": "string",
      "description": "Date the last status update has happened"
    },
    "MessageId": {
      "type": "integer",
      "description": "A unique message identifier. Use when checking for message status change"
    },
    "MessageSize": {
      "type": "integer",
      "description": "Number of fragments message was split into (if larger then 160 characters). Also equal to number of credits spent/required for sending"
    },
    "Number": {
      "type": "string",
      "description": "Recipient phone number"
    },
    "Text": {
      "type": "string",
      "description": "Message text"
    },
    "Status": {
      "type": "string",
      "description": "Current message status: 'Accepted' if message was about to be sent, or 'Rejected' if there were insufficient credits on your account"
    },
    "RemainingCreditCount": {
      "type": "integer",
      "description": "Number of SMS credits left on your account"
    },
    "Id": {
      "type": "string",
      "description": "External, user assigned message ID value (if present)"
    }
  }
}

400 Bad Request

An error occurred while making SMS send request. Please check response body to find additional details about error.

Representations

{
  "Code": 153,
  "Message": "Phone number is not valid"
}
{
  "type": "object",
  "properties": {
    "Code": {
      "type": "integer",
      "description": "Error code"
    },
    "Message": {
      "type": "string",
      "description": "Error details in user-friendly form"
    }
  }
}

401 Unauthorized

Provided API credentials is not valid. Please check out response body for more details

Representations

{
  "Code": 100,
  "Message": "Provided API key is invalid"
}
{
  "type": "object",
  "properties": {
    "Code": {
      "type": "integer",
      "description": "Error code"
    },
    "Message": {
      "type": "string",
      "description": "Error details in user-friendly form"
    }
  }
}

403 Forbidden

Message sending not allowed due to insufficient credits in your account, or message recipient is in suppression list and "send2Suppressed" parameter is set to "false" (response body contains actual reason)

Representations

{
  "Code": 154,
  "Message": "Insufficient credits on your account"
}
{
  "type": "object",
  "properties": {
    "Code": {
      "type": "integer",
      "description": "Error code"
    },
    "Message": {
      "type": "string",
      "description": "Error details in user-friendly form"
    }
  }
}

Code samples

@ECHO OFF

curl -v -X POST "https://api.touchbasepro.com/sms/message?send2Suppressed=true"
-H "Authorization: Bearer "
-H "Content-Type: application/json"

--data-ascii "{body}" 
using System;
using System.Net.Http.Headers;
using System.Text;
using System.Net.Http;
using System.Web;

namespace CSHttpClientSample
{
    static class Program
    {
        static void Main()
        {
            MakeRequest();
            Console.WriteLine("Hit ENTER to exit...");
            Console.ReadLine();
        }
        
        static async void MakeRequest()
        {
            var client = new HttpClient();
            var queryString = HttpUtility.ParseQueryString(string.Empty);

            // Request headers
            client.DefaultRequestHeaders.Add("Authorization", "Bearer ");

            // Request parameters
            queryString["send2Suppressed"] = "true";
            var uri = "https://api.touchbasepro.com/sms/message?" + queryString;

            HttpResponseMessage response;

            // Request body
            byte[] byteData = Encoding.UTF8.GetBytes("{body}");

            using (var content = new ByteArrayContent(byteData))
            {
               content.Headers.ContentType = new MediaTypeHeaderValue("< your content type, i.e. application/json >");
               response = await client.PostAsync(uri, content);
            }

        }
    }
}	
// // This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
import java.net.URI;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class JavaSample 
{
    public static void main(String[] args) 
    {
        HttpClient httpclient = HttpClients.createDefault();

        try
        {
            URIBuilder builder = new URIBuilder("https://api.touchbasepro.com/sms/message");

            builder.setParameter("send2Suppressed", "true");

            URI uri = builder.build();
            HttpPost request = new HttpPost(uri);
            request.setHeader("Authorization", "Bearer ");
            request.setHeader("Content-Type", "application/json");


            // Request body
            StringEntity reqEntity = new StringEntity("{body}");
            request.setEntity(reqEntity);

            HttpResponse response = httpclient.execute(request);
            HttpEntity entity = response.getEntity();

            if (entity != null) 
            {
                System.out.println(EntityUtils.toString(entity));
            }
        }
        catch (Exception e)
        {
            System.out.println(e.getMessage());
        }
    }
}

<!DOCTYPE html>
<html>
<head>
    <title>JSSample</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>

<script type="text/javascript">
    $(function() {
        var params = {
            // Request parameters
            "send2Suppressed": "true",
        };
      
        $.ajax({
            url: "https://api.touchbasepro.com/sms/message?" + $.param(params),
            beforeSend: function(xhrObj){
                // Request headers
                xhrObj.setRequestHeader("Authorization","Bearer ");
                xhrObj.setRequestHeader("Content-Type","application/json");
            },
            type: "POST",
            // Request body
            data: "{body}",
        })
        .done(function(data) {
            alert("success");
        })
        .fail(function() {
            alert("error");
        });
    });
</script>
</body>
</html>
#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    
    NSString* path = @"https://api.touchbasepro.com/sms/message";
    NSArray* array = @[
                         // Request parameters
                         @"entities=true",
                         @"send2Suppressed=true",
                      ];
    
    NSString* string = [array componentsJoinedByString:@"&"];
    path = [path stringByAppendingFormat:@"?%@", string];

    NSLog(@"%@", path);

    NSMutableURLRequest* _request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:path]];
    [_request setHTTPMethod:@"POST"];
    // Request headers
    [_request setValue:@"Bearer " forHTTPHeaderField:@"Authorization"];
    [_request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    // Request body
    [_request setHTTPBody:[@"{body}" dataUsingEncoding:NSUTF8StringEncoding]];
    
    NSURLResponse *response = nil;
    NSError *error = nil;
    NSData* _connectionData = [NSURLConnection sendSynchronousRequest:_request returningResponse:&response error:&error];

    if (nil != error)
    {
        NSLog(@"Error: %@", error);
    }
    else
    {
        NSError* error = nil;
        NSMutableDictionary* json = nil;
        NSString* dataString = [[NSString alloc] initWithData:_connectionData encoding:NSUTF8StringEncoding];
        NSLog(@"%@", dataString);
        
        if (nil != _connectionData)
        {
            json = [NSJSONSerialization JSONObjectWithData:_connectionData options:NSJSONReadingMutableContainers error:&error];
        }
        
        if (error || !json)
        {
            NSLog(@"Could not parse loaded json with error:%@", error);
        }
        
        NSLog(@"%@", json);
        _connectionData = nil;
    }
    
    [pool drain];

    return 0;
}
<?php
// This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
require_once 'HTTP/Request2.php';

$request = new Http_Request2('https://api.touchbasepro.com/sms/message');
$url = $request->getUrl();

$headers = array(
    // Request headers
    'Authorization' => 'Bearer ',
    'Content-Type' => 'application/json',
);

$request->setHeader($headers);

$parameters = array(
    // Request parameters
    'send2Suppressed' => 'true',
);

$url->setQueryVariables($parameters);

$request->setMethod(HTTP_Request2::METHOD_POST);

// Request body
$request->setBody("{body}");

try
{
    $response = $request->send();
    echo $response->getBody();
}
catch (HttpException $ex)
{
    echo $ex;
}

?>
########### Python 2.7 #############
import httplib, urllib, base64

headers = {
    # Request headers
    'Authorization': 'Bearer ',
    'Content-Type': 'application/json',
}

params = urllib.urlencode({
    # Request parameters
    'send2Suppressed': 'true',
})

try:
    conn = httplib.HTTPSConnection('api.touchbasepro.com')
    conn.request("POST", "/sms/message?%s" % params, "{body}", headers)
    response = conn.getresponse()
    data = response.read()
    print(data)
    conn.close()
except Exception as e:
    print("[Errno {0}] {1}".format(e.errno, e.strerror))

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

########### Python 3.2 #############
import http.client, urllib.request, urllib.parse, urllib.error, base64

headers = {
    # Request headers
    'Authorization': 'Bearer ',
    'Content-Type': 'application/json',
}

params = urllib.parse.urlencode({
    # Request parameters
    'send2Suppressed': 'true',
})

try:
    conn = http.client.HTTPSConnection('api.touchbasepro.com')
    conn.request("POST", "/sms/message?%s" % params, "{body}", headers)
    response = conn.getresponse()
    data = response.read()
    print(data)
    conn.close()
except Exception as e:
    print("[Errno {0}] {1}".format(e.errno, e.strerror))

####################################
require 'net/http'

uri = URI('https://api.touchbasepro.com/sms/message')

query = URI.encode_www_form({
    # Request parameters
    'send2Suppressed' => 'true'
})
if query.length > 0
  if uri.query && uri.query.length > 0
    uri.query += '&' + query
  else
    uri.query = query
  end
end

request = Net::HTTP::Post.new(uri.request_uri)
# Request headers
request['Authorization'] = 'Bearer '
# Request headers
request['Content-Type'] = 'application/json'
# Request body
request.body = "{body}"

response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
    http.request(request)
end

puts response.body