SMS API

API change history

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

Get SMS Campaign report

This method returns campaign report. Report always contains campaign name, status, number of recipients, number of delivered and bounced messages, number of replies and recipients that decided to unsubscribe. Based on 'select' query parameter, for each of the last 5 numeric values, a detailed information can be returned (a list of records). For all but replies, detailed information contains recipient phone number and a date when event happened. For replies, actual message text is also present.

Try it

Request

Request URL

Request parameters

  • int

    ID value of campaign report is requested for. Please use 'Get SMS Campaigns' method to return a list of campaigns with associated ID values

  • (optional)
    int

    An integer value that designates what detailed data report should contain. Each additional detail to get is represented with numeric value. Combine one or more by adding their respective numeric values and using result sum:

    • Value [1] to return the list of recipients
    • Value [2] to return the list of numbers message got delivered
    • Value [4] to return the list of numbers for which delivery failed
    • Value [8] to return the list of replies received and
    • Value [16] to return the list of numbers that got unsubscribed

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

Responses

200 OK

Report was successfully created. Response body contains the data

Representations

{
  "Name": "Black November 2021",
  "Status": "Delivered",
  "TotalRecipients": 8,
  "TotalDelivered": 2,
  "TotalBounced": 2,
  "TotalReplies": 2,
  "TotalUnsubscribed": 2,
  "Recipients": [
    "+27601111111",
    "+27602222222",
    "+27613333333",
    "+27614444444",
    "+27715555555",
    "+27716666666",
    "+27717777777",
    "+27718888888"
  ],
  "Delivered": [
    {
      "Number": "+27601111111",
      "Date": "2021-11-08T08:44:18.827Z"
    },
    {
      "Number": "+27602222222",
      "Date": "2021-11-08T08:44:18.89Z"
    }
  ],
  "Bounced": [
    {
      "Number": "+27613333333",
      "Date": "2021-11-08T09:00:06.667Z"
    },
    {
      "Number": "+27614444444",
      "Date": "2021-11-08T09:00:07.43Z"
    }
  ],
  "Replies": [
    {
      "Message": "??",
      "Number": "27715555555",
      "Date": "2021-11-08T14:04:30.74Z"
    },
    {
      "Message": "2",
      "Number": "27716666666",
      "Date": "2021-11-08T08:49:52.407Z"
    }
  ],
  "Unsubscribed": [
    {
      "Number": "27717777777",
      "Date": "2021-11-08T10:37:13.587Z"
    },
    {
      "Number": "27718888888",
      "Date": "2021-11-08T09:43:21.76Z"
    }
  ]
}
{
  "type": "object",
  "properties": {
    "Name": {
      "type": "string",
      "description": "Campaign name"
    },
    "Status": {
      "type": "string",
      "description": "Campaign status"
    },
    "TotalRecipients": {
      "type": "integer",
      "description": "Number of recipients for campaign"
    },
    "TotalDelivered": {
      "type": "integer",
      "description": "Number of recipients that successfully received campaign message"
    },
    "TotalBounced": {
      "type": "integer",
      "description": "Number of recipients that failed to receive campaign message"
    },
    "TotalReplies": {
      "type": "integer",
      "description": "Number of replies received"
    },
    "TotalUnsubscribed": {
      "type": "integer",
      "description": "Number of recipients that have unsubscribed from one or more lists"
    },
    "Recipients": {
      "type": "array",
      "description": "A list of campaign recipient phone numbers",
      "items": {
        "type": "string",
        "description": "Recipient phone number"
      }
    },
    "Delivered": {
      "type": "array",
      "items": {
        "type": "object",
        "description": "Object containing phone number and the date event took place",
        "properties": {
          "Number": {
            "type": "string",
            "description": "Recipient phone number"
          },
          "Date": {
            "type": "string",
            "description": "Date and time message got received"
          }
        },
        "required": [
          "Number",
          "Date"
        ]
      }
    },
    "Bounced": {
      "type": "array",
      "items": {
        "type": "object",
        "description": "Object containing phone number and the date event took place",
        "properties": {
          "Number": {
            "type": "string",
            "description": "Recipient phone number"
          },
          "Date": {
            "type": "string",
            "description": "Date and time message got flagged as undeliverable"
          }
        },
        "required": [
          "Number",
          "Date"
        ]
      }
    },
    "Replies": {
      "type": "array",
      "items": {
        "type": "object",
        "description": "Object containing phone number, message received and the date event took place",
        "properties": {
          "Message": {
            "type": "string",
            "description": "Reply message"
          },
          "Number": {
            "type": "string",
            "description": "Recipient phone number"
          },
          "Date": {
            "type": "string",
            "description": "Date and time reply was received"
          }
        },
        "required": [
          "Message",
          "Number",
          "Date"
        ]
      }
    },
    "Unsubscribed": {
      "type": "array",
      "items": {
        "type": "object",
        "description": "Object containing phone number and the date event took place",
        "properties": {
          "Number": {
            "type": "string",
            "description": "Recipient phone number"
          },
          "Date": {
            "type": "string",
            "description": "Date and time recipient unsubscribed"
          }
        },
        "required": [
          "Number",
          "Date"
        ]
      }
    }
  }
}

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"
    }
  }
}

Code samples

@ECHO OFF

curl -v -X GET "https://api.touchbasepro.com/sms/campaigns/{campaignId}/report?select=0"
-H "Authorization: Bearer "

--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["select"] = "0";
            var uri = "https://api.touchbasepro.com/sms/campaigns/{campaignId}/report?" + queryString;

            var response = await client.GetAsync(uri);
        }
    }
}	
// // 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/campaigns/{campaignId}/report");

            builder.setParameter("select", "0");

            URI uri = builder.build();
            HttpGet request = new HttpGet(uri);
            request.setHeader("Authorization", "Bearer ");


            // 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
            "select": "0",
        };
      
        $.ajax({
            url: "https://api.touchbasepro.com/sms/campaigns/{campaignId}/report?" + $.param(params),
            beforeSend: function(xhrObj){
                // Request headers
                xhrObj.setRequestHeader("Authorization","Bearer ");
            },
            type: "GET",
            // 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/campaigns/{campaignId}/report";
    NSArray* array = @[
                         // Request parameters
                         @"entities=true",
                         @"select=0",
                      ];
    
    NSString* string = [array componentsJoinedByString:@"&"];
    path = [path stringByAppendingFormat:@"?%@", string];

    NSLog(@"%@", path);

    NSMutableURLRequest* _request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:path]];
    [_request setHTTPMethod:@"GET"];
    // Request headers
    [_request setValue:@"Bearer " forHTTPHeaderField:@"Authorization"];
    // 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/campaigns/{campaignId}/report');
$url = $request->getUrl();

$headers = array(
    // Request headers
    'Authorization' => 'Bearer ',
);

$request->setHeader($headers);

$parameters = array(
    // Request parameters
    'select' => '0',
);

$url->setQueryVariables($parameters);

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

// 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 ',
}

params = urllib.urlencode({
    # Request parameters
    'select': '0',
})

try:
    conn = httplib.HTTPSConnection('api.touchbasepro.com')
    conn.request("GET", "/sms/campaigns/{campaignId}/report?%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 ',
}

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

try:
    conn = http.client.HTTPSConnection('api.touchbasepro.com')
    conn.request("GET", "/sms/campaigns/{campaignId}/report?%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/campaigns/{campaignId}/report')

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

request = Net::HTTP::Get.new(uri.request_uri)
# Request headers
request['Authorization'] = 'Bearer '
# 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