Use just one API to send Email, SMS, Fax and Voice Calls -
If you don't have an account, head to https://www.tnz.co.nz/Customer/SignUp/ and fill in the form.
You'll need a Sender and APIKey to authenticate with the API.
You can request this from your TNZ Representative or if you have a Dashboard login you can generate one under: Users | Outbound Users | Create
The API uses plain authentication. For OAuth2 authentication, contact your TNZ Representative.
You can use one Sender/APIKey for multiple use-cases - the SubAccount and Department values can be specified for rebilling.
This flexible API allows you to send multiple message types. For a brief overview of the API, see the TNZ API Structure guide.
https://api.tnz.co.nz/api/[Version]/[Action]/[MessageType][Version] is the API Version ('v2.01')[Action] defines the module ('send' a message or 'get' a status)[MessageType] is the type of message ('email', 'sms', 'fax', etc.)The HTTP Headers define the API call's formatting (JSON or XML) -
> JSON Headers:
Content-Type="application/json; encoding='utf-8'"> XML Headers:
Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"** Both 'Content-Type' and 'Accept' headers are required for XML
The basic parameters are -
Sender is the API userAPIKey is the API Sender's tokenMessageData contains the variables relevant to your chosen Message Type (Email, SMS, Fax, Voice, etc)An example for sending an outbound SMS using Raw JSON -
URL: https://api.tnz.co.nz/api/v2.01/send/sms
Header: Content-Type="application/json; encoding='utf-8'"
{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" : {
"Message": "Hello, this is a test.",
"Destinations" : [ { "Recipient": "+6421000001" } ]
}
}
Possible HTTP status values are:
200 OK - Message Accepted400 BAD REQUEST - Invalid Variables500 Internal Server Error - API Server FaultAn example JSON response value:
{
"Result": "%STATUS%",
"MessageID": "%MESSAGEID%"
}Status - 'Success' or 'Failed' refers to your API POST result (explains whether your POST was accepted by our server). This is not your message's delivery result - to track message delivery, see API - Status Reporting.MessageID - A message tracking identifier (maximum 40 characters, alphanumeric). If you do not supply this field in your submitted MessageData, the API will return one for you in the response body (UUID v4 of 36 characters).Note - The API will verify that required fields are supplied, however it will not validate data. See TNZ API Errors for error descriptions.Find instructions for each Message Type:
API URL: https://api.tnz.co.nz/api/v2.01/send/email
HTTP Header: Content-Type="application/json; encoding='utf-8'"
{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"EmailSubject": "Test Email Subject",
"MessagePlain": "Hello, This is a test message. Thank you.",
"Destinations" :
[
{ "Recipient": "recipient.one@example.com" },
{ "Recipient": "recipient.two@example.com" },
]
}
}
{
"Result": "Success",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}
{
"Result": "Failed",
"ErrorMessage": [
"Missing or empty sender",
"Invalid sender format"
]
}
API URL: https://api.tnz.co.nz/api/v2.01/send/email
HTTP Header: Content-Type="application/json; encoding='utf-8'"
{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"MessageID": "ID123456",
"Reference": "Test1",
"WebhookCallbackURL": "https://www.example.com/webhook",
"WebhookCallbackFormat": "JSON",
"SendTime": "2021-08-01T09:00:00",
"TimeZone": "New Zealand",
"SubAccount": "SubAccount01",
"Department": "Department01",
"ChargeCode": "BillingGroup01",
"EmailSubject": "Test Email Subject",
"SMTPFrom": "noreply@example.com",
"From": "noreply",
"FromEmail": "noreply@example.com",
"ReplyTo": "reply@example.com",
"MessagePlain": "Hello,\r\nThis is a test message.\r\nThank you.",
"MessageHTML": "<html>Hello,<br /><br />This is a test message.<br /><br />Thank you.</html>",
"Destinations" :
[
{
"Recipient": "john.doe@example.com",
"Attention": "John Doe",
"First Name": "John",
"Last Name": "Doe",
"Company": "Example Corp",
"Custom1": "",
"Custom2": ""
},
{ "Recipient": "recipient.two@example.com", "Attention": "Recipient2" },
{ "Recipient": "recipient.three@example.com" },
{ "Recipient": "recipient.four@example.com" }
],
"Files":
[
{
"Name": "Sample1.pdf",
"Data": "%%BASE-64 CONTENT%%"
},
{
"Name": "Sample2.pdf",
"Data": "%%BASE-64 CONTENT%%"
}
]
}
}
{
"Result": "Success",
"MessageID": "ID123456"
}
{
"Result": "Failed",
"ErrorMessage": [
"Missing or empty sender",
"Invalid sender format"
]
}
API URL: https://api.tnz.co.nz/api/v2.01/send/email
HTTP Header: Content-Type="application/json; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/send/email \
--header "Content-Type: application/json" \
--header "encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"EmailSubject": "Test Email Subject",
"MessagePlain": "Hello, This is a test message. Thank you.",
"Destinations" :
[
{ "Recipient": "recipient.one@example.com" },
{ "Recipient": "recipient.two@example.com" },
]
}
}'
{
"Result": "Success",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}
{
"Result": "Failed",
"ErrorMessage": [
"Missing or empty sender",
"Invalid sender format"
]
}
API URL: https://api.tnz.co.nz/api/v2.01/send/email
HTTP Header: Content-Type="application/json; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/send/email \
--header "Content-Type: application/json" \
--header "encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"MessageID": "ID123456",
"Reference": "Test1",
"WebhookCallbackURL": "https://www.example.com/webhook",
"WebhookCallbackFormat": "JSON",
"SendTime": "2021-08-01T09:00:00",
"TimeZone": "New Zealand",
"SubAccount": "SubAccount01",
"Department": "Department01",
"ChargeCode": "BillingGroup01",
"EmailSubject": "Test Email Subject",
"SMTPFrom": "noreply@example.com",
"From": "noreply",
"FromEmail": "noreply@example.com",
"ReplyTo": "reply@example.com",
"MessagePlain": "Hello,\r\nThis is a test message.\r\nThank you.",
"MessageHTML": "<html>Hello,<br /><br />This is a test message.<br /><br />Thank you.</html>",
"Destinations" :
[
{
"Recipient": "john.doe@example.com",
"Attention": "John Doe",
"First Name": "John",
"Last Name": "Doe",
"Company": "Example Corp",
"Custom1": "",
"Custom2": ""
},
{ "Recipient": "recipient.two@example.com" },
{ "Recipient": "recipient.three@example.com" },
{ "Recipient": "recipient.four@example.com" }
],
"Files":
[
{
"Name": "Sample1.pdf",
"Data": "%%BASE-64 CONTENT%%"
},
{
"Name": "Sample2.pdf",
"Data": "%%BASE-64 CONTENT%%"
}
]
}
}'
{
"Result": "Success",
"MessageID": "ID123456"
}
{
"Result": "Failed",
"ErrorMessage": [
"Missing or empty sender",
"Invalid sender format"
]
}
API URL: https://api.tnz.co.nz/api/v2.01/send/email
HTTP Header: Content-Type="application/json; encoding='utf-8'"
<?php
$data = array(
"Sender" => "application@domain.com", // your user id
"APIKey" => "ta8wr7ymd", // your api key
"MessageData" => array(
"EmailSubject" => "Test Email Subject",
"MessagePlain" => "Hello, This is a test message. Thank you.",
"Destinations" => array(
array(
"Recipient" => "recipient.one@example.com"
),
array(
"Recipient" => "recipient.two@example.com"
),
),
)
);
$headers = array(
"Content-Type: application/json",
"encoding='utf-8'",
"Content-length: ".strlen(json_encode($data)),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/send/email");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header('Content-Type: application/json');
echo $response;
break;
case "400": // error
header('Content-Type: application/json');
echo $response;
break;
case "500": // critical error
echo $response;
echo $err;
break;
default:
echo $response;
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
{
"Result": "Success",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}
{
"Result": "Failed",
"ErrorMessage": [
"Missing or empty sender",
"Invalid sender format"
]
}
API URL: https://api.tnz.co.nz/api/v2.01/send/email
HTTP Header: Content-Type="application/json; encoding='utf-8'"
<?php
function GetBase64Contents($file_name)
{
// returns base64 encoded file data
if( file_exists($file_name) )
{
$fp = fopen($file_name,"r");
$file_content = fread($fp,filesize($file_name));
fclose($fp);
return base64_encode($file_content);
}
}
$sender = "application@domain.com"; // your user id
$apikey = "ta8wr7ymd"; // your api key
$message_id = "ID123456"; //optional
$file1 = "[File Location]/Sample1.pdf";
$file2 = "[File Location]/Sample2.pdf";
$data = array(
"Sender" => $sender,
"APIKey" => $apikey,
"MessageData" => array(
"MessageID" => $message_id,
"Reference" => "Test1",
"WebhookCallbackURL" => "https://www.example.com/webhook",
"WebhookCallbackFormat" => "JSON",
"SendTime" => "2021-08-01T09:00:00",
"TimeZone" => "New Zealand",
"SubAccount" => "SubAccount01",
"Department" => "Department01",
"ChargeCode" => "BillingGroup01",
"EmailSubject" => "Test Email Subject",
"SMTPFrom" => "noreply@example.com",
"From" => "noreply",
"FromEmail" => "noreply@example.com",
"ReplyTo" => "reply@example.com",
"MessagePlain" => "Hello,\r\nThis is a test message.\r\nThank you.",
"MessageHTML" => "Hello,
This is a test message.
Thank you.",
"Destinations" => array(
array(
"Recipient" => "john.doe@example.com",
"Attention" => "John Doe",
"First Name" => "John",
"Last Name" => "Doe",
"Company" => "Example Corp",
"Custom1" => "",
"Custom2" => ""
),
array( "Recipient" => "recipient.two@example.com" ),
array( "Recipient" => "recipient.three@example.com" ),
array( "Recipient" => "recipient.four@example.com" )
),
"Files" => array(
array(
"Name" => basename($file1),
"Data" => GetBase64Contents($file1)
),
array(
"Name" => basename($file2),
"Data" => GetBase64Contents($file2)
)
),
)
);
$headers = array(
"Content-Type: application/json",
"encoding='utf-8'",
"Content-length: ".strlen(json_encode($data)),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/send/email");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header('Content-Type: application/json');
echo $response;
break;
case "400": // error
header('Content-Type: application/json');
echo $response;
break;
case "500": // critical error
echo $response;
echo $err;
break;
default:
echo $response;
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
{
"Result": "Success",
"MessageID": "ID123456"
}
{
"Result": "Failed",
"ErrorMessage": [
"Missing or empty sender",
"Invalid sender format"
]
}
API URL: https://api.tnz.co.nz/api/v2.01/send/email
HTTP Header: Content-Type="application/json; encoding='utf-8'"
using System;
using System.IO;
using System.Net;
using System.Text;
namespace TNZ
{
class Program
{
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/send/email";
//
// Build JSON Data
//
string strJSONData = $@"{{
""Sender"": ""application@domain.com"",
""APIKey"": ""ta8wr7ymd"",
""MessageData"": {{
""EmailSubject"": ""Test Email Subject"",
""MessagePlain"": ""Hello, This is a test message. Thank you."",
""Destinations"":
[
{{ ""Recipient"": ""recipient.one@example.com"" }},
{{ ""Recipient"": ""recipient.two@example.com"" }},
]
}}
}}";
//
// Send HTTP Request to TNZ Rest API
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/json; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
request.ContentLength = byteArray.Length;
Stream stream = request.GetRequestStream(); //open connection
stream.Write(byteArray, 0, byteArray.Length); // Send the data.
stream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
{
"Result": "Success",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}
{
"Result": "Failed",
"ErrorMessage": [
"Missing or empty sender",
"Invalid sender format"
]
}
API URL: https://api.tnz.co.nz/api/v2.01/send/email
HTTP Header: Content-Type="application/json; encoding='utf-8'"
using System;
using System.IO;
using System.Net;
using System.Text;
namespace TNZ
{
class Program
{
private static string GetFileContents(string strFileLocation)
{
//
// Read files in bytes, convert to Base64String and return in string
//
using (FileStream reader = new FileStream(strFileLocation, FileMode.Open))
{
byte[] buffer = new byte[reader.Length];
reader.Read(buffer, 0, (int)reader.Length);
string strContent = Convert.ToBase64String(buffer);
ASCIIEncoding encoding = new ASCIIEncoding();
return Encoding.ASCII.GetString(encoding.GetBytes(strContent));
}
}
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/send/email";
string file1 = "[File Location]/Sample1.pdf";
string file2 = "[File Location]/Sample2.pdf";
string file1_data = GetFileContents(file1);
string file2_data = GetFileContents(file2);
//
// Build JSON Data
//
string strJSONData = $@"{{
""Sender"": ""application@domain.com"",
""APIKey"": ""ta8wr7ymd"",
""MessageData"": {{
""MessageID"": ""ID123456"",
""Reference"": ""Test1"",
""WebhookCallbackURL"":""https://www.example.com/webhook"",
""WebhookCallbackFormat"":""JSON"",
""SendTime"": ""2021-08-01T09:00:00"",
""TimeZone"": ""New Zealand"",
""SubAccount"": ""SubAccount01"",
""Department"": ""Department01"",
""ChargeCode"": ""BillingGroup01"",
""EmailSubject"": ""Test Email Subject"",
""SMTPFrom"": ""noreply@example.com"",
""From"": ""noreply"",
""FromEmail"": ""noreply@example.com"",
""ReplyTo"": ""reply@example.com"",
""MessagePlain"": ""Hello,\r\nThis is a test message.\r\nThank you."",
""MessageHTML"": ""<html>Hello,<br /><br />This is a test message.<br /><br />Thank you.</html>"",
""Destinations"":
[
{{
""Recipient"": ""john.doe@example.com"",
""Attention"": ""John Doe"",
""First Name"": ""John"",
""Last Name"": ""Doe"",
""Company"": ""Example Corp""
}},
{{ ""Recipient"": ""recipient.two@example.com"", ""Attention"": ""Recipient 2"" }},
{{ ""Recipient"": ""recipient.three@example.com"" }},
{{ ""Recipient"": ""recipient.four@example.com"" }}
],
""Files"":
[
{{
""Name"": ""Sample1.pdf"",
""Data"": ""{file1_data}""
}},
{{
""Name"": ""Sample2.pdf"",
""Data"": ""{file2_data}""
}}
]
}}
}}";
//
// Send HTTP Request to TNZ Rest API
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/json; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
request.ContentLength = byteArray.Length;
Stream stream = request.GetRequestStream(); //open connection
stream.Write(byteArray, 0, byteArray.Length); // Send the data.
stream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
{
"Result": "Success",
"MessageID": "ID123456"
}
{
"Result": "Failed",
"ErrorMessage": [
"Missing or empty sender",
"Invalid sender format"
]
}
API URL: https://api.tnz.co.nz/api/v2.01/send/email
HTTP Header: Content-Type="application/json; encoding='utf-8'"
import requests
import json
url = "https://api.tnz.co.nz/api/v2.01/send/email"
headers = {
"Content-Type": "application/json",
"encoding": "utf-8"
}
data = {
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"EmailSubject" : "Test Email Subject",
"MessagePlain" : "Hello, This is a test message. Thank you.",
"Destinations" :
[
{ "Recipient": "recipient.one@example.com" },
{ "Recipient": "recipient.two@example.com" }
]
}
}
r = requests.post(url, data=json.dumps(data), headers=headers)
print(r)
print(r.text)
{
"Result": "Success",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}
{
"Result": "Failed",
"ErrorMessage": [
"Missing or empty sender",
"Invalid sender format"
]
}
API URL: https://api.tnz.co.nz/api/v2.01/send/email
HTTP Header: Content-Type="application/json; encoding='utf-8'"
import requests
import base64
import json
url = "https://api.tnz.co.nz/api/v2.01/send/email"
headers = {
"Content-Type": "application/json",
"encoding": "utf-8"
}
file_data = base64.b64encode(open("[File Location]/Sample1.pdf","rb").read()).decode("utf-8")
data = {
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"MessageID": "ID123456",
"Reference": "Test1",
"WebhookCallbackURL": "https://www.example.com/webhook",
"WebhookCallbackFormat": "JSON",
"SendTime": "2021-08-01T09:00:00",
"TimeZone": "New Zealand",
"SubAccount": "SubAccount01",
"Department": "Department01",
"ChargeCode": "BillingGroup01",
"EmailSubject": "Test Email Subject",
"SMTPFrom": "noreply@example.com",
"From": "noreply",
"FromEmail": "noreply@example.com",
"ReplyTo": "reply@example.com",
"MessagePlain": "Hello,\r\nThis is a test message.\r\nThank you.",
"MessageHTML": "<html>Hello,<br /><br />This is a test message.<br /><br />Thank you.</html>",
"Destinations" :
[
{
"Recipient": "john.doe@example.com",
"Attention": "John Doe",
"First Name": "John",
"Last Name": "Doe",
"Company": "Example Corp",
"Custom1": "",
"Custom2": ""
},
{ "Recipient": "recipient.two@example.com" },
{ "Recipient": "recipient.three@example.com" },
{ "Recipient": "recipient.four@example.com" }
],
"Files" :
[
{
"Name": "Sample1.pdf",
"Data": file_data
}
]
}
}
r = requests.post(url, data=json.dumps(data), headers=headers)
print(r)
print(r.text)
{
"Result": "Success",
"MessageID": "ID123456"
}
{
"Result": "Failed",
"ErrorMessage": [
"Missing or empty sender",
"Invalid sender format"
]
}
API URL: https://api.tnz.co.nz/api/v2.01/send/email
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?xml version="1.0" encoding="UTF-8"?>
<EmailRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageData>
<EmailSubject>Test Email Subject</EmailSubject>
<MessagePlain>Hello, This is a test message. Thank you.</MessagePlain>
<Destinations>
<Destination><Recipient>recipient.one@example.com</Recipient></Destination>
<Destination><Recipient>recipient.two@example.com</Recipient></Destination>
</Destinations>
</MessageData>
</EmailRequest>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/email
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?xml version="1.0" encoding="UTF-8"?>
<EmailRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageData>
<MessageID>ID123456</MessageID>
<Reference>Test1</Reference>
<WebhookCallbackURL>https://www.example.com/webhook</Reference>
<WebhookCallbackFormat>XML</Reference>
<SendTime>2021-08-01T09:00:00</SendTime>
<TimeZone>New Zealand</TimeZone>
<SubAccount>SubAccount01</SubAccount>
<Department>Department01</Department>
<ChargeCode>BillingGroup01</ChargeCode>
<EmailSubject>Test Email Subject</EmailSubject>
<SMTPFrom>noreply@example.com</SMTPFrom>
<From>noreply</From>
<FromEmail>noreply</FromEmail>
<ReplyTo>reply@example.com</ReplyTo>
<MessagePlain>Hello,\r\nThis is a test message.\r\nThank you.</MessagePlain>
<MessageHTML><![CDATA[<html>Hello,<br /><br />This is a test message.<br /><br />Thank you.</html>]]></MessageHTML>
<Destinations>
<Destination>
<Recipient>john.doe@example.com</Recipient>
<Attention>John Doe</Attention>
<FirstName>John</FirstName>
<LastName>Doe</LastName>
<Company>Example Corp</Company>
<Custom1></Custom1>
<Custom2></Custom2>
</Destination>
<Destination><Recipient>recipient.two@example.com</Recipient></Destination>
<Destination><Recipient>recipient.three@example.com</Recipient></Destination>
<Destination><Recipient>recipient.four@example.com</Recipient></Destination>
</Destinations>
<Files>
<File>
<Name>Sample.pdf</Name>
<Data>%%BASE-64 CONTENT%%</Data>
</File>
<File>
<Name>Sample2.pdf</Name>
<Data>%%BASE-64 CONTENT%%</Data>
</File>
</Files>
</MessageData>
</EmailRequest>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Missing or empty sender</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/email
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/send/email \
--header "Content-Type: text/xml" \
--header "Accept: text/xml" \
--header "encoding='utf-8'" \
--data '<?xml version="1.0" encoding="UTF-8"?>
<EmailRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageData>
<EmailSubject>Test Email Subject</EmailSubject>
<MessagePlain>Hello, This is a test message. Thank you.</MessagePlain>
<Destinations>
<Destination><Recipient>recipient.one@example.com</Recipient></Destination>
<Destination><Recipient>recipient.two@example.com</Recipient></Destination>
</Destinations>
</MessageData>
</EmailRequest>'
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/email
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/send/email \
--header "Content-Type: text/xml" \
--header "Accept: text/xml" \
--header "encoding='utf-8'" \
--data '<?xml version="1.0" encoding="UTF-8"?>
<EmailRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageData>
<MessageID>ID123456</MessageID>
<Reference>Test1</Reference>
<WebhookCallbackURL>https://www.example.com/webhook</WebhookCallbackURL>
<WebhookCallbackFormat>XML</WebhookCallbackFormat>
<SendTime>2021-08-01T09:00:00</SendTime>
<TimeZone>New Zealand</TimeZone>
<SubAccount>SubAccount01</SubAccount>
<Department>Department01</Department>
<ChargeCode>BillingGroup01</ChargeCode>
<EmailSubject>Test Email Subject</EmailSubject>
<SMTPFrom>noreply@domain.com</SMTPFrom>
<From>noreply</From>
<FromEmail>noreply@domain.com</FromEmail>
<ReplyTo>reply@domain.com</ReplyTo>
<MessagePlain>Hello,\r\nThis is a test message.\r\nThank you.</MessagePlain>
<MessageHTML><![CDATA[<html>Hello,<br /><br />This is a test message.<br /><br />Thank you.</html>]]></MessageHTML>
<Destinations>
<Destination>
<Recipient>john.doe@example.com</Recipient>
<Attention>John Doe</Attention>
<FirstName>John</FirstName>
<LastName>Doe</LastName>
<Company>Example Corp</Company>
<Custom1></Custom1>
<Custom2></Custom2>
</Destination>
<Destination><Recipient>recipient.two@example.com</Recipient></Destination>
<Destination><Recipient>recipient.three@example.com</Recipient></Destination>
<Destination><Recipient>recipient.four@example.com</Recipient></Destination>
</Destinations>
<Files>
<File>
<Name>Sample.pdf</Name>
<Data>%%BASE-64 CONTENT%%</Data>
</File>
<File>
<Name>Sample2.pdf</Name>
<Data>%%BASE-64 CONTENT%%</Data>
</File>
</Files>
</MessageData>
</EmailRequest>'
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Missing or empty sender</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/email
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?php
$data = new SimpleXMLExtended("<?xml version=\"1.0\" encoding=\"utf-8\"?><EmailRequest></EmailRequest>");
$data->addChild("Sender","application@domain.com");
$data->addChild("APIKey","ta8wr7ymd");
$data->addChild("MessageData");
$data->MessageData->addChild("EmailSubject","Test Email Subject");
$data->MessageData->addChild("MessagePlain","Hello, This is a test message. Thank you.");
$destinations = $data->MessageData->addChild("Destinations");
$destination1 = $destinations->addChild("Destination");
$destination1->addChild("Recipient","recipient.one@example.com");
$destination2 = $destinations->addChild("Destination");
$destination2->addChild("Recipient","recipient.two@example.com");
$headers = array(
"Content-Type: text/xml",
"Accept: text/xml",
"encoding='utf-8'",
"Content-length: ".strlen($data->asXML()),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/send/email");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "400": // error
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "500": // critical error
echo $response."\n";
echo $err;
break;
default:
echo $response."\n";
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/email
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?php
class SimpleXMLExtended extends SimpleXMLElement {
//
// this class extends SimplXMLElement to insert CDATA if necessary.
// for example, XML is not validated if HTML tag is inside XML Element,
// so we want to wrap inside CDATA, <![CDATA[<html>...</html>]]>
//
public function addCData($cdata_text) {
$node = dom_import_simplexml($this);
$no = $node->ownerDocument;
$node->appendChild($no->createCDATASection($cdata_text));
}
}
function GetBase64Contents($file_name)
{
// returns base64 encoded file data
if( file_exists($file_name) )
{
$fp = fopen($file_name,"r");
$file_content = fread($fp,filesize($file_name));
fclose($fp);
return base64_encode($file_content);
}
}
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$message_id = "ID123456"; //optional
$file1 = "D:\\file1.pdf";
$file2 = "D:\\file2.pdf";
$data = new SimpleXMLExtended("<?xml version=\"1.0\" encoding=\"utf-8\"?><EmailRequest></EmailRequest>");
$data->addChild("Sender",$sender);
$data->addChild("APIKey",$apikey);
$data->addChild("MessageData");
$data->MessageData->addChild("MessageID",$message_id);
$data->MessageData->addChild("Reference","Test1");
$data->MessageData->addChild("WebhookCallbackURL","https://www.example.com/webhook");
$data->MessageData->addChild("WebhookCallbackFormat","XML");
$data->MessageData->addChild("SendTime","2021-08-01T09:00:00");
$data->MessageData->addChild("TimeZone","New Zealand");
$data->MessageData->addChild("SubAccount","SubAccount01");
$data->MessageData->addChild("Department","Department01");
$data->MessageData->addChild("ChargeCode","BillingGroup01");
$data->MessageData->addChild("EmailSubject","Test Email Subject");
$data->MessageData->addChild("SMTPFrom","noreply@example.com");
$data->MessageData->addChild("From","noreply");
$data->MessageData->addChild("FromEmail","noreply@example.com");
$data->MessageData->addChild("ReplyTo","reply@example.com");
$data->MessageData->addChild("MessagePlain","Hello,\r\nThis is a test message.\r\nThank you.");
$data->MessageData->addChild("MessageHTML");
$data->MessageData->MessageHTML->addCData("<html>Hello,<br /><br />This is a test message.<br /><br />Thank you.</html>"); // wrap CDATA for HTML Tags
$destinations = $data->MessageData->addChild("Destinations");
$destination1 = $destinations->addChild("Destination");
$destination1->addChild("Recipient","john.doe@example.com");
$destination1->addChild("Attention","John Doe");
$destination1->addChild("FirstName","John");
$destination1->addChild("LastName","Doe");
$destination1->addChild("Company","Example Corp");
$destination1->addChild("Custom1","");
$destination1->addChild("Custom2","");
$destination2 = $destinations->addChild("Destination");
$destination2->addChild("Recipient","recipient.two@example.com");
$destination3 = $destinations->addChild("Destination");
$destination3->addChild("Recipient","recipient.three@example.com");
$destination4 = $destinations->addChild("Destination");
$destination4->addChild("Recipient","recipient.four@example.com");
if( file_exists($file1) || file_exists($file2) )
{
$fileElement = $data->MessageData->addChild("Files");
if( file_exists($file1) )
{
$fileElement1 = $fileElement->addChild("File");
$fileElement1->addChild("Name",basename($file1));
$fileElement1->addChild("Data",GetBase64Contents($file1));
}
if( file_exists($file2) )
{
$fileElement2 = $fileElement->addChild("File");
$fileElement2->addChild("Name",basename($file2));
$fileElement2->addChild("Data",GetBase64Contents($file2));
}
}
$headers = array(
"Content-Type: text/xml",
"Accept: text/xml",
"encoding='utf-8'",
"Content-length: ".strlen($data->asXML()),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/send/email");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "400": // error
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "500": // critical error
echo $response."\n";
echo $err;
break;
default:
echo $response."\n";
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Missing or empty sender</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/email
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Xml;
namespace TNZ
{
class Program
{
private static XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerText = val;
return workingNode;
}
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/send/email";
XmlDocument xmlDoc = new XmlDocument();
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null); // <?xml version="1.0" encoding="UTF-8"?>
xmlDoc.AppendChild(docNode);
XmlNode rootNode = xmlDoc.CreateElement("EmailRequest");
xmlDoc.AppendChild(rootNode);
rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com"));
rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd"));
XmlNode workingNode = xmlDoc.CreateElement("Sender");
//
// MessageData
//
XmlNode messageDataNode = xmlDoc.CreateElement("MessageData");
messageDataNode.AppendChild(addChildNode(xmlDoc, "EmailSubject", "Test Email Subject"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "MessagePlain", "Hello,\r\nThis is a test message.\r\nThank you."));
//
// Add Destinations
//
workingNode = xmlDoc.CreateElement("Destinations");
// Declare Single Destination
XmlNode destNode1 = xmlDoc.CreateElement("Destination");
destNode1.AppendChild(addChildNode(xmlDoc, "Recipient", "recipient.one@example.com"));
// Add Destination to Destinations object
workingNode.AppendChild(destNode1);
// Declare Single Destination
XmlNode destNode2 = xmlDoc.CreateElement("Destination");
destNode2.AppendChild(addChildNode(xmlDoc, "Recipient", "recipient.two@example.com"));
// Add Destination to Destinations object
workingNode.AppendChild(destNode2);
// Add Destinations to MessageData
messageDataNode.AppendChild(workingNode);
//
// Set MessageData into root(EmailRequest) node
//
rootNode.AppendChild(messageDataNode);
//
// Send HTTP Request to REST API
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "text/xml; encoding='utf-8'";
request.Accept = "text/xml; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
request.ContentLength = byteArray.Length;
Stream stream = request.GetRequestStream(); //open connection
stream.Write(byteArray, 0, byteArray.Length); // Send the data.
stream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/email
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Xml;
namespace TNZ
{
class Program
{
private static string GetFileName(string strFileLocation)
{
return System.IO.Path.GetFileName(strFileLocation);
}
private static string GetFileContents(string strFileLocation)
{
//
// Read files in bytes, convert to Base64String and return in string
//
using (FileStream reader = new FileStream(strFileLocation, FileMode.Open))
{
byte[] buffer = new byte[reader.Length];
reader.Read(buffer, 0, (int)reader.Length);
string strContent = Convert.ToBase64String(buffer);
ASCIIEncoding encoding = new ASCIIEncoding();
return Encoding.ASCII.GetString(encoding.GetBytes(strContent));
}
}
private static XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerText = val;
return workingNode;
}
private static XmlNode addChildNodeCDATA(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerXml = @"<![CDATA[" + val + "]]>";
return workingNode;
}
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/send/email";
string file1 = "[File Location]/Sample1.pdf";
string file2 = "[File Location]/Sample2.pdf";
XmlDocument xmlDoc = new XmlDocument();
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null); // <?xml version="1.0" encoding="UTF-8"?>
xmlDoc.AppendChild(docNode);
XmlNode rootNode = xmlDoc.CreateElement("EmailRequest");
xmlDoc.AppendChild(rootNode);
rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com"));
rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd"));
XmlNode workingNode = xmlDoc.CreateElement("Sender");
//
// MessageData
//
XmlNode messageDataNode = xmlDoc.CreateElement("MessageData");
messageDataNode.AppendChild(addChildNode(xmlDoc, "MessageID", "ID123456"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "Reference", "Test1"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "WebhookCallbackURL", "https://www.example.com/webhook"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "WebhookCallbackFormat", "XML"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "SendTime", "2021-08-01T09:00:00"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "TimeZone", "New Zealand"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "SubAccount", "SubAccount01"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "Department", "Department01"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "ChargeCode", "BillingGroup01"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "EmailSubject", "Test Email Subject"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "SMTPFrom", "noreply@example.com"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "From", "noreply"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "FromEmail", "noreply@example.com"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "ReplyTo", "reply@example.com"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "MessagePlain", "Hello,\r\nThis is a test message.\r\nThank you."));
messageDataNode.AppendChild(addChildNodeCDATA(xmlDoc, "MessageHTML", "<html>Hello,<br /><br />This is a test message.<br /><br />Thank you.</html>")); // wrap with <![CDATA[]]>
//
// Add Destinations 1 - Add with details
//
workingNode = xmlDoc.CreateElement("Destinations");
XmlNode destNode = xmlDoc.CreateElement("Destination");
destNode.AppendChild(addChildNode(xmlDoc, "Recipient", "john.doe@example.com"));
destNode.AppendChild(addChildNode(xmlDoc, "Attention", "John Doe"));
destNode.AppendChild(addChildNode(xmlDoc, "FirstName", "John"));
destNode.AppendChild(addChildNode(xmlDoc, "LastName", "Doe"));
destNode.AppendChild(addChildNode(xmlDoc, "Company", "Example Corp"));
destNode.AppendChild(addChildNode(xmlDoc, "Custom1", "Custom1"));
destNode.AppendChild(addChildNode(xmlDoc, "Custom2", "Custom2"));
workingNode.AppendChild(destNode);
//
// Add Destinations 2 - Add emails only
//
destNode = xmlDoc.CreateElement("Destination");
destNode.AppendChild(addChildNode(xmlDoc, "Recipient", "recipient.two@example.com"));
workingNode.AppendChild(destNode);
destNode = xmlDoc.CreateElement("Destination");
destNode.AppendChild(addChildNode(xmlDoc, "Recipient", "recipient.three@example.com"));
workingNode.AppendChild(destNode);
// Add Destinations to MessageData
messageDataNode.AppendChild(workingNode);
//
// Attach File 1
//
workingNode = xmlDoc.CreateElement("Files");
XmlNode fileNode1 = xmlDoc.CreateElement("File");
fileNode1.AppendChild(addChildNode(xmlDoc, "Name", GetFileName(file1)));
fileNode1.AppendChild(addChildNodeCDATA(xmlDoc, "Data", GetFileContents(file1)));
workingNode.AppendChild(fileNode1);
//
// Attach File 2
//
XmlNode fileNode2 = xmlDoc.CreateElement("File");
fileNode2.AppendChild(addChildNode(xmlDoc, "Name", GetFileName(file1)));
fileNode2.AppendChild(addChildNodeCDATA(xmlDoc, "Data", GetFileContents(file1)));
workingNode.AppendChild(fileNode2);
messageDataNode.AppendChild(workingNode);
//
// Set MessageData into root node
//
rootNode.AppendChild(messageDataNode);
//
// Send HTTP Request to REST API
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "text/xml; encoding='utf-8'";
request.Accept = "text/xml; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
request.ContentLength = byteArray.Length;
Stream stream = request.GetRequestStream(); //open connection
stream.Write(byteArray, 0, byteArray.Length); // Send the data.
stream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Missing or empty sender</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/email
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
import requests
import xml.etree.ElementTree as ET
url = "https://api.tnz.co.nz/api/v2.01/send/email"
headers = {
"Content-Type": "text/xml",
"Accept": "text/xml",
"encoding": "utf-8"
}
root = ET.Element('EmailRequest')
ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
message_data = ET.SubElement(root,"MessageData")
ET.SubElement(message_data, "EmailSubject").text = "Test Email Subject"
ET.SubElement(message_data, "MessagePlain").text = "Hello, This is a test message. Thank you."
destinations = ET.SubElement(message_data,"Destinations")
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination, "Recipient").text = "recipient.one@example.com"
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination, "Recipient").text = "recipient.two@example.com"
r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)
print(r)
print(r.text)
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/email
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
import requests
import base64
import xml.etree.ElementTree as ET
url = "https://api.tnz.co.nz/api/v2.01/send/email"
headers = {
"Content-Type": "text/xml",
"Accept": "text/xml",
"encoding": "utf-8"
}
file_data_1 = base64.b64encode(open("[File Location]/Sample1.pdf","rb").read()).decode("utf-8")
file_data_2 = base64.b64encode(open("[File Location]/Sample2.pdf","rb").read()).decode("utf-8")
root = ET.Element('EmailRequest')
ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
message_data = ET.SubElement(root,"MessageData")
ET.SubElement(message_data, "MessageID").text = "ID123456"
ET.SubElement(message_data, "Reference").text = "Test1"
ET.SubElement(message_data, "WebhookCallbackURL").text = "https://www.example.com/webhook"
ET.SubElement(message_data, "WebhookCallbackFormat").text = "XML"
ET.SubElement(message_data, "SendTime").text = "2021-08-01T09:00:00"
ET.SubElement(message_data, "TimeZone").text = "New Zealand"
ET.SubElement(message_data, "SubAccount").text = "SubAccount01"
ET.SubElement(message_data, "Department").text = "Department01"
ET.SubElement(message_data, "ChargeCode").text = "BillingGroup01"
ET.SubElement(message_data, "EmailSubject").text = "Test Email Subject"
ET.SubElement(message_data, "SMTPFrom").text = "noreply@example.com"
ET.SubElement(message_data, "From").text = "noreply"
ET.SubElement(message_data, "FromEmail").text = "noreply@example.com"
ET.SubElement(message_data, "ReplyTo").text = "reply@example.com"
ET.SubElement(message_data, "MessagePlain").text = "Hello,\r\nThis is a test message.\r\nThank you."
ET.SubElement(message_data, "MessageHTML").text = "<![CDATA[<html>Hello,<br /><br />This is a test message.<br /><br />Thank you.</html>]]>"
destinations = ET.SubElement(message_data,"Destinations")
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination,"Recipient").text = "john.doe@example.com"
ET.SubElement(destination,"Attention").text = "John Doe"
ET.SubElement(destination,"FirstName").text = "John"
ET.SubElement(destination,"LastName").text = "Doe"
ET.SubElement(destination,"Company").text = "Example Corp"
ET.SubElement(destination,"Custom1").text = ""
ET.SubElement(destination,"Custom2").text = ""
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination, "Recipient").text = "recipient.two@example.com"
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination, "Recipient").text = "recipient.three@example.com"
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination, "Recipient").text = "recipient.four@example.com"
files = ET.SubElement(message_data,"Files")
file = ET.SubElement(files,"File")
ET.SubElement(file,"Name").text = "Sample1.pdf"
ET.SubElement(file,"Data").text = file_data_1
file = ET.SubElement(files,"File")
ET.SubElement(file,"Name").text = "Sample2.pdf"
ET.SubElement(file,"Data").text = file_data_2
r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)
print(r)
print(r.text)
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Missing or empty sender</ErrorMessage>
</root>
| Parameter | Example Value | Description | |
|---|---|---|---|
| EmailSubject | Test Email Subject | Subject field used in the email | |
| SMTPFrom | noreply@example.com | Sets the email Sender/Return-Path at the SMTP level (this address receives bounce-back emails and is used for SPF/DKIM type authentication; 'FromEmail' is used if not specified) | |
| From | noreply | Sets the email sender's Friendly Name (seen by the email recipient) | |
| FromEmail | noreply@example.com | Sets the email sender's Email Address (seen by the email recipient; API 'Sender' is used if not specified) | |
| ReplyTo | reply@example.com | Sets the email sender's Reply-To Address (if the recipient replies, the Reply To will receive the reply) | |
| MessagePlain | Hello, This is a test message. Thank you. |
Content used for the message/plain section of the email (overrides 'Template') | |
| Destinations | > Recipient | john.doe@example.com recipient.three@example.com recipient.four@example.com |
Email address(es) to receive the message (for detailed formatting, see the Destinations parameter below) |
| Parameter | Example Value | Description | |
|---|---|---|---|
| MessageID | ID123456 | A message tracking identifier (maximum 40 characters, alphanumeric). If you do not supply this field, the API will return one for you in the response body (UUID v4 of 36 characters) | |
| Reference | Test1 | Tracking ID or message description | |
| WebhookCallbackURL | https://www.example.com/webhook | Overrides your Sender's default Webhook URL. Requires a default webhook to be configured. A full path including https:// is required. | |
| WebhookCallbackFormat | JSON | Overrides your Sender's default Webhook format ('JSON' or 'XML') | |
| SendTime | 2021-12-31T23:00 | Delay sending until the specified date/time, a single point of time in a combined date and time representation ({date}T{time}; for example, 2017-08-29T04:00 in your local timezone, specified by your Sender setting or overridden using the TimeZone command). | |
| TimeZone | New Zealand | User's local timezone (see Setting Timezones) | |
| SubAccount | SubAccount01 | Used for reporting, billing and Web Dashboard segmentation. See the TNZ API Structure guide's Cost Tracking & Rebilling section. | |
| Department | Department01 | Used for reporting, billing and Web Dashboard segmentation. See the TNZ API Structure guide's Cost Tracking & Rebilling section. | |
| ChargeCode | BillingGroup01 | Bespoke app cost allocation code (for invoice segmentation) | |
| TemplateLocation | Folder 01 | Directory/location of Template to use | |
| Template | Template File Name | Preloaded Template to use for email body (overridden by MessagePlain and/or MessageHTML parameters) | |
| MessageHTML | <html>Hello,<br /><br />This is a test message.<br /><br />Thank you.</html> | Content used for the message/html section of the email (overrides 'Template' and 'MessagePlain') | |
| Destinations | > Recipient | john.doe@example.com | Recipient of the email |
| > Attention | John Doe | Recipient's name | |
| > First Name | John | Recipient's first name | |
| > Last Name | Doe | Recipient's last name | |
| > Company | Example Corp | Recipient's company | |
| > Custom1 | Reference Number ABC123 | Customisable tracking and personalisation field | |
| > Custom2 | Reference Code WWW222 | Customisable tracking and personalisation field | |
| Files | > Name | Sample.pdf | Attachment's filename |
| > Data | %%Base-64%% | Base-64 encoded value of the attached file | |
API URL: https://api.tnz.co.nz/api/v2.01/send/sms
HTTP Header: Content-Type="application/json; encoding='utf-8'"
{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"Message": "Hello, this is a test message from Department01. Thank you.",
"Destinations" :
[
{ "Recipient": "+6421000001" },
{ "Recipient": "+6421000002" }
]
}
}
{
"Result": "Success",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/sms
HTTP Header: Content-Type="application/json; encoding='utf-8'"
{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"MessageID": "ID123456",
"Reference": "Test1",
"WebhookCallbackURL": "https://www.example.com/webhook",
"WebhookCallbackFormat": "JSON",
"SendTime": "2021-08-01T09:00:00",
"TimeZone": "New Zealand",
"SubAccount": "SubAccount01",
"Department": "Department01",
"ChargeCode": "BillingGroup01",
"FromNumber": "6422000001",
"SMSEmailReply": "person.one@domain.com",
"CharacterConversion": true,
"Message": "Hello, this is a test message. Click the link to download file1 [[File1]], and file2 [[File2]]",
"Destinations" :
[
{
"Recipient": "+6421000001",
"Attention": "John Doe",
"First Name": "John",
"Last Name": "Doe",
"Company": "Example Corp",
"Custom1": "",
"Custom2": ""
},
{ "Recipient": "+6421000002" },
{ "Recipient": "+6421000003" },
{ "Recipient": "+6421000004" }
],
"Files":
[
{
"Name": "Sample.pdf",
"Data": "%%BASE-64 CONTENT%%"
},
{
"Name": "Sample2.pdf",
"Data": "%%BASE-64 CONTENT%%"
}
]
}
}
{
"Result": "Success",
"MessageID": "ID123456"
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/sms
HTTP Header: Content-Type="application/json; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/send/sms \
--header "Content-Type: application/json" \
--header "encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"Message": "Hello, this is a test message from Department01. Thank you.",
"Destinations" :
[
{ "Recipient": "+6421000001" },
{ "Recipient": "+6421000002" }
]
}
}'
{
"Result": "Success",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/sms
HTTP Header: Content-Type="application/json; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/send/sms \
--header "Content-Type: application/json" \
--header "encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"MessageID": "ID123456",
"Reference": "Test1",
"WebhookCallbackURL": "https://www.example.com/webhook",
"WebhookCallbackFormat": "JSON",
"SendTime": "2021-08-01T09:00:00",
"TimeZone": "New Zealand",
"SubAccount": "SubAccount01",
"Department": "Department01",
"ChargeCode": "BillingGroup01",
"FromNumber": "6422000001",
"SMSEmailReply": "person.one@domain.com",
"CharacterConversion": true,
"Message": "Hello, this is a test message. Click the link to download file1 [[File1]], and file2 [[File2]]",
"Destinations" :
[
{
"Recipient": "+6421000001",
"Attention": "John Doe",
"First Name": "John",
"Last Name": "Doe",
"Company": "Example Corp",
"Custom1": "",
"Custom2": ""
},
{ "Recipient": "+6421000002" },
{ "Recipient": "+6421000003" },
{ "Recipient": "+6421000004" }
],
"Files":
[
{
"Name": "Sample.pdf",
"Data": "%%BASE-64 CONTENT%%"
},
{
"Name": "Sample2.pdf",
"Data": "%%BASE-64 CONTENT%%"
}
]
}
}'
{
"Result": "Success",
"MessageID": "ID123456"
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/sms
HTTP Header: Content-Type="application/json; encoding='utf-8'"
<?php
$data = array(
"Sender" => "application@domain.com",
"APIKey" => "ta8wr7ymd",
"MessageData" => array(
"Message" => "Hello, this is a test message from Department01. Thank you.",
"Destinations" => array(
array(
"Recipient" => "+6421000001"
),
array(
"Recipient" => "+6421000002"
),
),
)
);
$headers = array(
"Content-Type: application/json",
"encoding='utf-8'",
"Content-length: ".strlen(json_encode($data)),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/send/sms");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header('Content-Type: application/json');
echo $response;
break;
case "400": // error
header('Content-Type: application/json');
echo $response;
break;
case "500": // critical error
echo $response;
echo $err;
break;
default:
echo $response;
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
{
"Result": "Success",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/sms
HTTP Header: Content-Type="application/json; encoding='utf-8'"
<?php
function GetBase64Contents($file_name)
{
// returns base64 encoded file data
if( file_exists($file_name) )
{
$fp = fopen($file_name,"r");
$file_content = fread($fp,filesize($file_name));
fclose($fp);
return base64_encode($file_content);
}
}
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$message_id = "ID123456"; // optional
$file1 = "Sample.pdf";
$file2 = "Sample2.pdf";
$data = array(
"Sender" => $sender,
"APIKey" => $apikey,
"MessageData" => array(
"MessageID" => $message_id,
"Reference" => "Test1",
"WebhookCallbackURL" => "https://www.example.com/webhook",
"WebhookCallbackFormat" => "JSON",
"SendTime" => "2021-08-01T09:00:00",
"TimeZone" => "New Zealand",
"SubAccount" => "SubAccount01",
"Department" => "Department01",
"ChargeCode" => "BillingGroup01",
"FromNumber" => "6422000001",
"SMSEmailReply" => "person.one@domain.com",
"CharacterConversion" => true,
"Message" => "Hello, this is a test message. Click the link to download file1 [[File1]], and file2 [[File2]]",
"Destinations" => array(
array(
"Recipient" => "+6421000001",
"Attention" => "John Doe",
"First Name" => "John",
"Last Name" => "Doe",
"Company" => "Example Corp",
"Custom1" => "",
"Custom2" => ""
),
array( "Recipient" => "+6421000002" ),
array( "Recipient" => "+6421000003" ),
array( "Recipient" => "+6421000004" )
),
"Files" => array(
array(
"Name" => basename($file1),
"Data" => GetBase64Contents($file1)
),
array(
"Name" => basename($file2),
"Data" => GetBase64Contents($file2)
)
),
)
);
$headers = array(
"Content-Type: application/json",
"encoding='utf-8'",
"Content-length: ".strlen(json_encode($data)),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/send/sms");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header('Content-Type: application/json');
echo $response;
break;
case "400": // error
header('Content-Type: application/json');
echo $response;
break;
case "500": // critical error
echo $response;
echo $err;
break;
default:
echo $response;
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
{
"Result": "Success",
"MessageID": "ID123456"
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/sms
HTTP Header: Content-Type="application/json; encoding='utf-8'"
using System;
using System.IO;
using System.Text;
using System.Net;
namespace TNZ
{
class Program
{
private static string addslashes(string str)
{
string ret = "";
foreach (char c in str)
{
switch (c)
{
case '\'': ret += "\\\'"; break;
case '\"': ret += "\\\""; break;
case '\0': ret += "\\0"; break;
case '\r': ret += "\\r"; break;
case '\n': ret += "\\n"; break;
case '\\': ret += "\\\\"; break;
default: ret += c.ToString(); break;
}
}
return ret;
}
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/send/sms";
string strJSONData = $@"{{
""Sender"": ""application@domain.com"",
""APIKey"": ""ta8wr7ymd"",
""MessageData"": {{
""Message"": ""{addslashes("Hello, This is a test message. Thank you.")}"",
""Destinations"":
[
{{ ""Recipient"": ""+6421000001"" }},
{{ ""Recipient"": ""+6421000002"" }}
]
}}
}}";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/json; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
request.ContentLength = byteArray.Length;
Stream newStream = request.GetRequestStream(); //open connection
newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
newStream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
{
"Result": "Success",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/sms
HTTP Header: Content-Type="application/json; encoding='utf-8'"
using System;
using System.IO;
using System.Text;
using System.Net;
namespace TNZ
{
class Program
{
private static string GetFileContents(string strFileLocation)
{
//
// Read files in bytes, convert to Base64String and return in string
//
using (FileStream reader = new FileStream(strFileLocation, FileMode.Open))
{
byte[] buffer = new byte[reader.Length];
reader.Read(buffer, 0, (int)reader.Length);
string strContent = Convert.ToBase64String(buffer);
ASCIIEncoding encoding = new ASCIIEncoding();
return Encoding.ASCII.GetString(encoding.GetBytes(strContent));
}
}
private static string addslashes(string str)
{
string ret = "";
foreach (char c in str)
{
switch (c)
{
case '\'': ret += "\\\'"; break;
case '\"': ret += "\\\""; break;
case '\0': ret += "\\0"; break;
case '\r': ret += "\\r"; break;
case '\n': ret += "\\n"; break;
case '\\': ret += "\\\\"; break;
default: ret += c.ToString(); break;
}
}
return ret;
}
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/send/sms";
string sender = "application@domain.com";
string api_key = "ta8wr7ymd";
string file1 = "D:\\File1.pdf";
string file2 = "D:\\File2.pdf";
string file1_data = GetFileContents(file1);
string file2_data = GetFileContents(file2);
StringBuilder sb = new StringBuilder();
string strJSONData = $@"{{
""Sender"": ""{sender}"",
""APIKey"": ""{api_key}"",
""MessageData"": {{
""MessageID"": ""ID123456"",
""Reference"": ""Test1"",
""WebhookCallbackURL"":""https://www.example.com/webhook"",
""WebhookCallbackFormat"":""JSON"",
""SendTime"": ""2021-08-01T09:00:00"",
""TimeZone"": ""New Zealand"",
""SubAccount"": ""SubAccount01"",
""Department"": ""Department01"",
""ChargeCode"": """",
""FromNumber"": ""+61422000001"",
""SMSEmailReply"": ""reply@example.com"",
""CharacterConversion"": true,
""Message"": ""{addslashes("Hello,\r\nThis is a test message.\r\nThank you.\r\nClick [[File1]], [[File2]]")}"",
""Destinations"":
[
{{
""Recipient"": ""+6421000001"",
""Attention"": ""John Doe"",
""First Name"": ""John"",
""Last Name"": ""Doe"",
""Company"": ""Example Corp""
}},
{{ ""Recipient"": ""+6422000001"", ""Attention"": ""Recipient 2"" }},
{{ ""Recipient"": ""+6423000001"" }},
{{ ""Recipient"": ""+6424000001"" }}
],
""Files"":
[
{{
""Name"": ""File1.pdf"",
""Data"": ""{file1_data}""
}},
{{
""Name"": ""File2.pdf"",
""Data"": ""{file2_data}""
}}
]
}}
}}";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/json; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
request.ContentLength = byteArray.Length;
Stream newStream = request.GetRequestStream(); //open connection
newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
newStream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
{
"Result": "Success",
"MessageID": "ID123456"
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/sms
HTTP Header: Content-Type="application/json; encoding='utf-8'"
import requests
import json
url = "https://api.tnz.co.nz/api/v2.01/send/sms"
headers = {
"Content-Type": "application/json",
"encoding": "utf-8"
}
data = {
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"Message": "Hello, this is a test message from Department01. Thank you.",
"Destinations" :
[
{ "Recipient": "+6421000001" },
{ "Recipient": "+6421000002" },
]
}
}
r = requests.post(url, data=json.dumps(data), headers=headers)
print(r)
print(r.text)
{
"Result": "Success",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/sms
HTTP Header: Content-Type="application/json; encoding='utf-8'"
import requests
import json
import base64
url = "https://api.tnz.co.nz/api/v2.01/send/sms"
headers = {
"Content-Type": "application/json",
"encoding": "utf-8"
}
file_list = [
{
"name": "File1.pdf",
"path": "d:/File1.pdf"
},
{
"name": "File2.pdf",
"path": "d:/File2.pdf"
}
]
data = {
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"MessageID": "ID123456",
"Reference": "Test1",
"WebhookCallbackURL": "https://www.example.com/webhook",
"WebhookCallbackFormat": "JSON",
"SendTime": "2021-08-01T09:00:00",
"TimeZone": "New Zealand",
"SubAccount": "SubAccount01",
"Department": "Department01",
"ChargeCode": "BillingGroup01",
"FromNumber": "6422000001",
"SMSEmailReply": "person.one@domain.com",
"CharacterConversion": True,
"Message": "Hello, this is a test message. Click the link to download file1 [[File1]], and file2 [[File2]]",
"Destinations" :
[
{
"Recipient": "+6421000001",
"Attention": "John Doe",
"First Name": "John",
"Last Name": "Doe",
"Company": "Example Corp",
"Custom1": "",
"Custom2": ""
},
{ "Recipient": "+6421000002" },
{ "Recipient": "+6421000003" },
{ "Recipient": "+6421000004" }
],
"Files" :
[
{
"Name": file_list[0]["name"],
"Data": base64.b64encode(open(file_list[0]["path"],"rb").read()).decode("utf-8")
},
{
"Name": file_list[1]["name"],
"Data": base64.b64encode(open(file_list[1]["path"],"rb").read()).decode("utf-8")
},
]
}
}
r = requests.post(url, data=json.dumps(data), headers=headers)
print(r)
print(r.text)
{
"Result": "Success",
"MessageID": "ID123456"
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/sms
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?xml version="1.0" encoding="UTF-8"?>
<SMSRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageData>
<Message>Hello, this is a test message from Department01. Thank you.</Message>
<Destinations>
<Destination><Recipient>+6421000001</Recipient></Destination>
<Destination><Recipient>+6421000002</Recipient></Destination>
</Destinations>
</MessageData>
</SMSRequest>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/sms
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?xml version="1.0" encoding="UTF-8"?>
<SMSRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageData>
<MessageID>ID123456</MessageID>
<Reference>Test1</Reference>
<WebhookCallbackURL>https://www.example.com/webhook</WebhookCallbackURL>
<WebhookCallbackFormat>XML</WebhookCallbackFormat>
<SendTime>2021-08-01T09:00:00</SendTime>
<TimeZone>New Zealand</TimeZone>
<SubAccount>SubAccount01</SubAccount>
<Department>Department01</Department>
<ChargeCode>BillingGroup01</ChargeCode>
<FromNumber>6422000001</FromNumber>
<SMSEmailReply>person.one@domain.com</SMSEmailReply>
<CharacterConversion>true</CharacterConversion>
<Message>Hello, this is a test message. Click the link to download file1 [[File1]], and file2 [[File2]]</Message>
<Destinations>
<Destination>
<Recipient>+6421000001</Recipient>
<Attention>John Doe</Attention>
<FirstName>John</FirstName>
<LastName>Doe</LastName>
<Company>Example Corp</Company>
<Custom1></Custom1>
<Custom2></Custom2>
</Destination>
<Destination><Recipient>+6421000002</Recipient></Destination>
<Destination><Recipient>+6421000003</Recipient></Destination>
<Destination><Recipient>+6421000004</Recipient></Destination>
</Destinations>
<Files>
<File>
<Name>Sample.pdf</Name>
<Data>%%BASE-64 CONTENT%%</Data>
</File>
<File>
<Name>Sample2.pdf</Name>
<Data>%%BASE-64 CONTENT%%</Data>
</File>
</Files>
</MessageData>
</SMSRequest>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Missing or empty sender</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/sms
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/send/sms \
--header "Content-Type: text/xml" \
--header "Accept: text/xml" \
--header "encoding='utf-8'" \
--data '<?xml version="1.0" encoding="UTF-8"?>
<SMSRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageData>
<Message>Hello, this is a test message from Department01. Thank you.</Message>
<Destinations>
<Destination><Recipient>+6421000001</Recipient></Destination>
<Destination><Recipient>+6421000002</Recipient></Destination>
</Destinations>
</MessageData>
</SMSRequest>'
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/sms
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/send/sms \
--header "Content-Type: text/xml" \
--header "Accept: text/xml" \
--header "encoding='utf-8'" \
--data '<?xml version="1.0" encoding="UTF-8"?>
<SMSRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageData>
<MessageID>ID123456</MessageID>
<Reference>Test1</Reference>
<WebhookCallbackURL>https://www.example.com/webhook</WebhookCallbackURL>
<WebhookCallbackFormat>XML</WebhookCallbackFormat>
<SendTime>2021-08-01T09:00:00</SendTime>
<TimeZone>New Zealand</TimeZone>
<SubAccount>SubAccount01</SubAccount>
<Department>Department01</Department>
<ChargeCode>BillingGroup01</ChargeCode>
<FromNumber>6422000001</FromNumber>
<SMSEmailReply>person.one@domain.com</SMSEmailReply>
<CharacterConversion>true</CharacterConversion>
<Message>Hello, this is a test message. Click the link to download file1 [[File1]], and file2 [[File2]]</Message>
<Destinations>
<Destination>
<Recipient>+6421000001</Recipient>
<Attention>John Doe</Attention>
<FirstName>John</FirstName>
<LastName>Doe</LastName>
<Company>Example Corp</Company>
<Custom1></Custom1>
<Custom2></Custom2>
</Destination>
<Destination><Recipient>+6421000002</Recipient></Destination>
<Destination><Recipient>+6421000003</Recipient></Destination>
<Destination><Recipient>+6421000004</Recipient></Destination>
</Destinations>
<Files>
<File>
<Name>Sample.pdf</Name>
<Data>%%BASE-64 CONTENT%%</Data>
</File>
<File>
<Name>Sample2.pdf</Name>
<Data>%%BASE-64 CONTENT%%</Data>
</File>
</Files>
</MessageData>
</SMSRequest>'
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Missing or empty sender</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/sms
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?php
$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><SMSRequest></SMSRequest>");
$data->addChild("Sender","application@domain.com");
$data->addChild("APIKey","ta8wr7ymd");
$data->addChild("MessageData");
$data->MessageData->addChild("Message","Hello, this is a test message from Department01. Thank you.");
$destinations = $data->MessageData->addChild("Destinations");
$destination1 = $destinations->addChild("Destination");
$destination1->addChild("Recipient","+6421000001");
$destination2 = $destinations->addChild("Destination");
$destination2->addChild("Recipient","+6421000002");
$headers = array(
"Content-Type: text/xml",
"Accept: text/xml",
"encoding='utf-8'",
"Content-length: ".strlen($data->asXML()),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/send/sms");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "400": // error
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "500": // critical error
echo $response."\n";
echo $err;
break;
default:
echo $response."\n";
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/sms
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?php
function GetBase64Contents($file_name)
{
// returns base64 encoded file data
if( file_exists($file_name) )
{
$fp = fopen($file_name,"r");
$file_content = fread($fp,filesize($file_name));
fclose($fp);
return base64_encode($file_content);
}
}
$file1 = "Sample.pdf";
$file2 = "Sample2.pdf";
$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><SMSRequest></SMSRequest>");
$data->addChild("Sender","application@domain.com"); // API User
$data->addChild("APIKey","ta8wr7ymd"); // API Key
$data->addChild("MessageData");
$data->MessageData->addChild("MessageID","ID123456");
$data->MessageData->addChild("Reference","Test1");
$data->MessageData->addChild("WebhookCallbackURL","https://www.example.com/webhook");
$data->MessageData->addChild("WebhookCallbackFormat","XML");
$data->MessageData->addChild("SendTime","2021-08-01T09:00:00");
$data->MessageData->addChild("TimeZone","New Zealand");
$data->MessageData->addChild("SubAccount","SubAccount01");
$data->MessageData->addChild("Department","Department01");
$data->MessageData->addChild("ChargeCode","BillingGroup01");
$data->MessageData->addChild("FromNumber","6422000001");
$data->MessageData->addChild("SMSEmailReply","person.one@domain.com");
$data->MessageData->addChild("CharacterConversion",true);
$data->MessageData->addChild("Message","Hello, this is a test message. Click the link to download file1 [[File1]], and file2 [[File2]]");
$destinations = $data->MessageData->addChild("Destinations");
$destination1 = $destinations->addChild("Destination");
$destination1->addChild("Recipient","+6421000001");
$destination1->addChild("Attention","John Doe");
$destination1->addChild("FirstName","John");
$destination1->addChild("LastName","Doe");
$destination1->addChild("Company","Example Corp");
$destination1->addChild("Custom1","");
$destination1->addChild("Custom2","");
$destination2 = $destinations->addChild("Destination");
$destination2->addChild("Recipient","+6421000002");
$destination3 = $destinations->addChild("Destination");
$destination3->addChild("Recipient","+6421000003");
$destination4 = $destinations->addChild("Destination");
$destination4->addChild("Recipient","+6421000004");
if( file_exists($file_name1) || file_exists($file_name2) )
{
$fileElement = $data->MessageData->addChild("Files");
if( file_exists($file_name1) )
{
$fileElement1 = $fileElement->addChild("File");
$fileElement1->addChild("Name",basename($file1));
$fileElement1->addChild("Data",GetBase64Contents($file_content1));
}
if( file_exists($file_name2) )
{
$fileElement2 = $fileElement->addChild("File");
$fileElement2->addChild("Name",basename($file1));
$fileElement2->addChild("Data",GetBase64Contents($file_content2));
}
}
$headers = array(
"Content-Type: text/xml",
"Accept: text/xml",
"encoding='utf-8'",
"Content-length: ".strlen($data->asXML()),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/send/sms");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "400": // error
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "500": // critical error
echo $response."\n";
echo $err;
break;
default:
echo $response."\n";
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Missing or empty sender</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/sms
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Xml;
namespace TNZ
{
class Program
{
private static string addslashes(string str)
{
string ret = "";
foreach (char c in str)
{
switch (c)
{
case '\'': ret += "\\\'"; break;
case '\"': ret += "\\\""; break;
case '\0': ret += "\\0"; break;
case '\r': ret += "\\r"; break;
case '\n': ret += "\\n"; break;
case '\\': ret += "\\\\"; break;
default: ret += c.ToString(); break;
}
}
return ret;
}
private static XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerText = val;
return workingNode;
}
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/send/sms";
XmlDocument xmlDoc = new XmlDocument();
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null); // <?xml version="1.0" encoding="UTF-8"?>
xmlDoc.AppendChild(docNode);
XmlNode rootNode = xmlDoc.CreateElement("SMSRequest");
xmlDoc.AppendChild(rootNode);
rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com"));
rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd"));
XmlNode workingNode = xmlDoc.CreateElement("Sender");
//
// MessageData
//
XmlNode messageDataNode = xmlDoc.CreateElement("MessageData");
messageDataNode.AppendChild(addChildNode(xmlDoc, "Message", addslashes("Hello,\r\nThis is a test message.\r\nThank you.")));
//
// Add Destinations
//
workingNode = xmlDoc.CreateElement("Destinations");
// Declare Single Destination
XmlNode destNode1 = xmlDoc.CreateElement("Destination");
destNode1.AppendChild(addChildNode(xmlDoc, "Recipient", "+6421000001"));
// Add Destination to Destinations object
workingNode.AppendChild(destNode1);
// Declare Single Destination
XmlNode destNode2 = xmlDoc.CreateElement("Destination");
destNode2.AppendChild(addChildNode(xmlDoc, "Recipient", "+6421000002"));
// Add Destination to Destinations object
workingNode.AppendChild(destNode2);
// Add Destinations to MessageData
messageDataNode.AppendChild(workingNode);
//
// Set MessageData into root(EmailRequest) node
//
rootNode.AppendChild(messageDataNode);
//
// Send HTTP Request to REST API
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "text/xml; encoding='utf-8'";
request.Accept = "text/xml; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
request.ContentLength = byteArray.Length;
Stream stream = request.GetRequestStream(); //open connection
stream.Write(byteArray, 0, byteArray.Length); // Send the data.
stream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/sms
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Xml;
namespace TNZ
{
class Program
{
private static string addslashes(string str)
{
string ret = "";
foreach (char c in str)
{
switch (c)
{
case '\'': ret += "\\\'"; break;
case '\"': ret += "\\\""; break;
case '\0': ret += "\\0"; break;
case '\r': ret += "\\r"; break;
case '\n': ret += "\\n"; break;
case '\\': ret += "\\\\"; break;
default: ret += c.ToString(); break;
}
}
return ret;
}
private static string GetFileName(string strFileLocation)
{
return System.IO.Path.GetFileName(strFileLocation);
}
private static string GetFileContents(string strFileLocation)
{
//
// Read files in bytes, convert to Base64String and return in string
//
using (FileStream reader = new FileStream(strFileLocation, FileMode.Open))
{
byte[] buffer = new byte[reader.Length];
reader.Read(buffer, 0, (int)reader.Length);
string strContent = Convert.ToBase64String(buffer);
ASCIIEncoding encoding = new ASCIIEncoding();
return Encoding.ASCII.GetString(encoding.GetBytes(strContent)).Trim();
}
}
private static XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerText = val;
return workingNode;
}
private static XmlNode addChildNodeCDATA(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerXml = @"<![CDATA[" + val + "]]>";
return workingNode;
}
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/send/sms";
string file1 = "[File Location]/Sample1.pdf";
string file2 = "[File Location]/Sample2.pdf";
XmlDocument xmlDoc = new XmlDocument();
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null); // <?xml version="1.0" encoding="UTF-8"?>
xmlDoc.AppendChild(docNode);
XmlNode rootNode = xmlDoc.CreateElement("SMSRequest");
xmlDoc.AppendChild(rootNode);
rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com"));
rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd"));
XmlNode workingNode = xmlDoc.CreateElement("Sender");
//
// MessageData
//
XmlNode messageDataNode = xmlDoc.CreateElement("MessageData");
messageDataNode.AppendChild(addChildNode(xmlDoc, "MessageID", "ID123456"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "Reference", "Test1"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "WebhookCallbackURL", "https://www.example.com/webhook"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "WebhookCallbackFormat", "XML"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "SendTime", "2021-08-01T09:00:00"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "TimeZone", "New Zealand"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "SubAccount", "SubAccount01"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "Department", "Department01"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "ChargeCode", "BillingGroup01"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "FromNumber", "+6422000001"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "SMSEmailReply", "person.one@domain.com"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "CharacterConversion", "true"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "Message", addslashes("Hello,\r\nThis is a test message.\r\nThank you.")));
//
// Add Destinations 1 - Add with details
//
workingNode = xmlDoc.CreateElement("Destinations");
XmlNode destNode = xmlDoc.CreateElement("Destination");
destNode.AppendChild(addChildNode(xmlDoc, "Recipient", "+6421000001"));
destNode.AppendChild(addChildNode(xmlDoc, "Attention", "John Doe"));
destNode.AppendChild(addChildNode(xmlDoc, "FirstName", "John"));
destNode.AppendChild(addChildNode(xmlDoc, "LastName", "Doe"));
destNode.AppendChild(addChildNode(xmlDoc, "Company", "Example Corp"));
destNode.AppendChild(addChildNode(xmlDoc, "Custom1", "Custom1"));
destNode.AppendChild(addChildNode(xmlDoc, "Custom2", "Custom2"));
workingNode.AppendChild(destNode);
//
// Add Destinations 2 - Add emails only
//
destNode = xmlDoc.CreateElement("Destination");
destNode.AppendChild(addChildNode(xmlDoc, "Recipient", "+6422000001"));
workingNode.AppendChild(destNode);
destNode = xmlDoc.CreateElement("Destination");
destNode.AppendChild(addChildNode(xmlDoc, "Recipient", "+6423000001"));
workingNode.AppendChild(destNode);
// Add Destinations to MessageData
messageDataNode.AppendChild(workingNode);
//
// Attach File 1
//
workingNode = xmlDoc.CreateElement("Files");
XmlNode fileNode1 = xmlDoc.CreateElement("File");
fileNode1.AppendChild(addChildNode(xmlDoc, "Name", GetFileName(file1)));
fileNode1.AppendChild(addChildNodeCDATA(xmlDoc, "Data", GetFileContents(file1)));
workingNode.AppendChild(fileNode1);
//
// Attach File 2
//
XmlNode fileNode2 = xmlDoc.CreateElement("File");
fileNode2.AppendChild(addChildNode(xmlDoc, "Name", GetFileName(file2)));
fileNode2.AppendChild(addChildNodeCDATA(xmlDoc, "Data", GetFileContents(file2)));
workingNode.AppendChild(fileNode2);
messageDataNode.AppendChild(workingNode);
//
// Set MessageData into root node
//
rootNode.AppendChild(messageDataNode);
//
// Send HTTP Request to REST API
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "text/xml; encoding='utf-8'";
request.Accept = "text/xml; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
request.ContentLength = byteArray.Length;
Stream stream = request.GetRequestStream(); //open connection
stream.Write(byteArray, 0, byteArray.Length); // Send the data.
stream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Missing or empty sender</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/sms
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
import requests
import xml.etree.ElementTree as ET
url = "https://api.tnz.co.nz/api/v2.01/send/sms"
headers = {
"Content-Type": "text/xml",
"Accept": "text/xml",
"encoding": "utf-8"
}
root = ET.Element('SMSRequest')
ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
message_data = ET.SubElement(root,"MessageData")
ET.SubElement(message_data, "Message").text = "Hello, this is a call from test. This is relevant information."
destinations = ET.SubElement(message_data,"Destinations")
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination, "Recipient").text = "+6421000001"
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination, "Recipient").text = "+6421000002"
r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)
print(r)
print(r.text)
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/sms
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
import requests
import base64
import xml.etree.ElementTree as ET
url = "https://api.tnz.co.nz/api/v2.01/send/sms"
headers = {
"Content-Type": "text/xml",
"Accept": "text/xml",
"encoding": "utf-8"
}
file_data_1 = base64.b64encode(open("d:/File1.pdf","rb").read()).decode("utf-8")
file_data_2 = base64.b64encode(open("d:/File2.pdf","rb").read()).decode("utf-8")
root = ET.Element('SMSRequest')
ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
message_data = ET.SubElement(root,"MessageData")
ET.SubElement(message_data, "MessageID").text = "ID123456"
ET.SubElement(message_data, "Reference").text = "Test1"
ET.SubElement(message_data, "WebhookCallbackURL").text = "https://www.example.com/webhook"
ET.SubElement(message_data, "WebhookCallbackFormat").text = "XML"
ET.SubElement(message_data, "SendTime").text = "2021-08-01T09:00:00"
ET.SubElement(message_data, "TimeZone").text = "New Zealand"
ET.SubElement(message_data, "SubAccount").text = "SubAccount01"
ET.SubElement(message_data, "Department").text = "Department01"
ET.SubElement(message_data, "ChargeCode").text = "BillingGroup01"
ET.SubElement(message_data, "FromNumber").text = "6422000001"
ET.SubElement(message_data, "SMSEmailReply").text = "person.one@domain.com"
ET.SubElement(message_data, "CharacterConversion").text = "true"
ET.SubElement(message_data, "Message").text = "Hello, this is a test message. Click the link to download file1 [[File1]], and file2 [[File2]]"
destinations = ET.SubElement(message_data,"Destinations")
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination,"Recipient").text = "+6421000001"
ET.SubElement(destination,"Attention").text = "John Doe"
ET.SubElement(destination,"FirstName").text = "John"
ET.SubElement(destination,"LastName").text = "Doe"
ET.SubElement(destination,"Company").text = "Example Corp"
ET.SubElement(destination,"Custom1").text = ""
ET.SubElement(destination,"Custom2").text = ""
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination, "Recipient").text = "+6421000002"
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination, "Recipient").text = "+6421000003"
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination, "Recipient").text = "+6421000004"
files = ET.SubElement(message_data,"Files")
file = ET.SubElement(files,"File")
ET.SubElement(file,"Name").text = "File1.pdf"
ET.SubElement(file,"Data").text = file_data_1
file = ET.SubElement(files,"File")
ET.SubElement(file,"Name").text = "File2.pdf"
ET.SubElement(file,"Data").text = file_data_2
r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)
print(r)
print(r.text)
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Missing or empty sender</ErrorMessage>
</root>
| Parameter | Example Value | Description | |
|---|---|---|---|
| Message | Hello, this is a test message from Department01. Thank you. | Plain or UTF-8 formatted SMS message | |
| Destinations | > Recipient | +6421000002 +6421000003 +6421000004 |
Mobile number(s) to receive the message (for detailed formatting, see the Destinations parameter below) |
| Parameter | Example Value | Description | |
|---|---|---|---|
| MessageID | ID123456 | A message tracking identifier (maximum 40 characters, alphanumeric). If you do not supply this field, the API will return one for you in the response body (UUID v4 of 36 characters) | |
| Reference | Test1 | Tracking ID or message description | |
| WebhookCallbackURL | https://www.example.com/webhook | Overrides your Sender's default Webhook URL. Requires a default webhook to be configured. A full path including https:// is required. | |
| WebhookCallbackFormat | JSON | Overrides your Sender's default Webhook format ('JSON' or 'XML') | |
| SendTime | 2021-12-31T23:00 | Delay sending until the specified date/time, a single point of time in a combined date and time representation ({date}T{time}; for example, 2017-08-29T04:00 in your local timezone, specified by your Sender setting or overridden using the TimeZone command). | |
| TimeZone | New Zealand | User's local timezone (see Setting Timezones) | |
| SubAccount | SubAccount01 | Used for reporting, billing and Web Dashboard segmentation. See the TNZ API Structure guide's Cost Tracking & Rebilling section. | |
| Department | Department01 | Used for reporting, billing and Web Dashboard segmentation. See the TNZ API Structure guide's Cost Tracking & Rebilling section. | |
| ChargeCode | BillingGroup01 | Bespoke app cost allocation code (for invoice segmentation) | |
| FromNumber | 6421000001 | Setting SMS origination number, short code(s) will override in New Zealand - Not for New Zealand. | |
| SMSEmailReply | person.one@domain.com | For email (SMTP) reply receipt notifications | |
| CharacterConversion | true | Convert multi-byte characters into normalised GSM character format. ie. © to (C) | |
| Message | Hello, view the link at [[Link:https://www.example.com/path/to/page.html]] or view the file at [[File1]] or reply at [[REPLY]] or OptOut at [[STOP]] | An example Message that uses the URL Shortener, File Link, Reply Link and Unsubscribe functions | |
| Destinations | > Recipient | +6421000001 | Recipient of the SMS in E.164 internationalised format (for localized or friendly formatting, contact your account manager) |
| > Attention | John Doe | Recipient's name | |
| > First Name | John | Recipient's first name | |
| > Last Name | Doe | Recipient's last name | |
| > Company | Example Corp | Recipient's company | |
| > Custom1 | Customisable tracking and personalisation field | ||
| > Custom2 | Customisable tracking and personalisation field | ||
| Files | > Name | File Name.pdf | Files referenced in [[File1]] commands (for MessageLink) |
| > Data | %%Base-64%% | Base-64 encoded value of the attached file | |
API URL: https://api.tnz.co.nz/api/v2.01/send/fax
HTTP Header: Content-Type="application/json; encoding='utf-8'"
{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"Destinations" :
[
{ "Recipient" : "+6495005001" },
{ "Recipient" : "+6495005002" }
],
"Files":
[
{
"Name": "Sample.pdf",
"Data": "%%BASE-64 CONTENT%%"
}
]
}
}
{
"Result": "Success",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/fax
HTTP Header: Content-Type="application/json; encoding='utf-8'"
{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"MessageID": "ID123456",
"Reference": "Test1",
"WebhookCallbackURL": "https://www.example.com/webhook",
"WebhookCallbackFormat": "JSON",
"SendTime": "2021-08-01T09:00:00",
"TimeZone": "New Zealand",
"SubAccount": "SubAccount01",
"Department": "Department01",
"ChargeCode": "BillingGroup01",
"Resolution": "high",
"CSID": "Station ID",
"RetryAttempts": 3,
"RetryPeriod": 1,
"Message": "Hello,\r\nThis is a test message.\r\nThank you.",
"Destinations" :
[
{
"Recipient": "+6495005000",
"Attention": "John Doe",
"First Name": "John",
"Last Name": "Doe",
"Company": "Example Corp",
"Custom1": "",
"Custom2": ""
},
{ "Recipient": "+6495005001" },
{ "Recipient": "+6495005002" },
{ "Recipient": "+6495005003" }
],
"Files":
[
{
"Name": "Sample.pdf",
"Data": "%%BASE-64 CONTENT%%"
},
{
"Name": "Sample2.pdf",
"Data": "%%BASE-64 CONTENT%%"
}
]
}
}
{
"Result": "Success",
"MessageID": "ID123456"
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/fax
HTTP Header: Content-Type="application/json; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/send/fax \
--header "Content-Type: application/json" \
--header "encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"Destinations" :
[
{ "Recipient": "+6495005001" },
{ "Recipient": "+6495005002" }
],
"Files":
[
{
"Name": "Sample.pdf",
"Data": "%%BASE-64 CONTENT%%"
}
]
}
}'
{
"Result": "Success",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/fax
HTTP Header: Content-Type="application/json; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/send/fax \
--header "Content-Type: application/json" \
--header "encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"MessageID" : "ID123456",
"Reference": "Test1",
"WebhookCallbackURL": "https://www.example.com/webhook",
"WebhookCallbackFormat": "JSON",
"SendTime": "2021-08-01T09:00:00",
"TimeZone": "New Zealand",
"SubAccount": "SubAccount01",
"Department": "Department01",
"ChargeCode": "BillingGroup01",
"Resolution": "high",
"CSID": "Station ID",
"Destinations" :
[
{
"Recipient": "+6495005000",
"Attention": "John Doe",
"First Name": "John",
"Last Name": "Doe",
"Company": "Example Corp",
"Custom1": "",
"Custom2": ""
},
{ "Recipient": "+6495005001" },
{ "Recipient": "+6495005002" },
{ "Recipient": "+6495005003" }
],
"Files":
[
{
"Name": "Sample.pdf",
"Data": "%%BASE-64 CONTENT%%"
},
{
"Name": "Sample2.pdf",
"Data": "%%BASE-64 CONTENT%%"
}
]
}
}'
{
"Result": "Success",
"MessageID": "ID123456"
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/fax
HTTP Header: Content-Type="application/json; encoding='utf-8'"
<?php
$file1 = "Sample.pdf";
function GetBase64Contents($file_name)
{
// returns base64 encoded file data
if( file_exists($file_name) )
{
$fp = fopen($file_name,"r");
$file_content = fread($fp,filesize($file_name));
fclose($fp);
return base64_encode($file_content);
}
}
$data = array(
"Sender" => "application@domain.com",
"APIKey" => "ta8wr7ymd",
"MessageData" => array(
"Destinations" => array(
array(
"Recipient" => "+6495005001"
),
array(
"Recipient" => "+6495005002"
)
),
"Files" => array(
array(
"Name" => basename($file1),
"Data" => GetBase64Contents($file1)
)
),
)
);
$headers = array(
"Content-Type: application/json",
"encoding='utf-8'",
"Content-length: ".strlen(json_encode($data)),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/send/fax");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header('Content-Type: application/json');
echo $response;
break;
case "400": // error
header('Content-Type: application/json');
echo $response;
break;
case "500": // critical error
echo $response;
echo $err;
break;
default:
echo $response;
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
{
"Result": "Success",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/fax
HTTP Header: Content-Type="application/json; encoding='utf-8'"
<?php
function GetBase64Contents($file_name)
{
// returns base64 encoded file data
if( file_exists($file_name) )
{
$fp = fopen($file_name,"r");
$file_content = fread($fp,filesize($file_name));
fclose($fp);
return base64_encode($file_content);
}
}
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$message_id = "ID123456"; //optional
$file1 = "Sample1.pdf";
$file2 = "Sample2.pdf";
$data = array(
"Sender" => $sender,
"APIKey" => $apikey,
"MessageData" => array(
"MessageID" => $message_id,
"Reference" => "Test1",
"WebhookCallbackURL" => "https://www.example.com/webhook",
"WebhookCallbackFormat" => "JSON",
"SendTime" => "2021-08-01T09:00:00",
"TimeZone" => "New Zealand",
"SubAccount" => "SubAccount01",
"Department" => "Department01",
"ChargeCode" => "BillingGroup01",
"Resolution" => "high",
"CSID" => "Station ID",
"Destinations" => array(
array(
"Recipient" => "+6495005000",
"Attention" => "John Doe",
"First Name" => "John",
"Last Name" => "Doe",
"Company" => "Example Corp",
"Custom1" => "",
"Custom2" => ""
),
array( "Recipient" => "+6495005001" ),
array( "Recipient" => "+6495005002" ),
array( "Recipient" => "+6495005003" )
),
"Files" => array(
array(
"Name" => basename($file1),
"Data" => GetBase64Contents($file1)
),
array(
"Name" => basename($file2),
"Data" => GetBase64Contents($file2)
)
),
)
);
$headers = array(
"Content-Type: application/json",
"encoding='utf-8'",
"Content-length: ".strlen(json_encode($data)),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/send/fax");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header('Content-Type: application/json');
echo $response;
break;
case "400": // error
header('Content-Type: application/json');
echo $response;
break;
case "500": // critical error
echo $response;
echo $err;
break;
default:
echo $response;
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
{
"Result": "Success",
"MessageID": "ID123456"
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/fax
HTTP Header: Content-Type="application/json; encoding='utf-8'"
using System;
using System.IO;
using System.Text;
using System.Net;
namespace TNZ
{
class Program
{
private static string GetFileName(string strFileLocation)
{
return System.IO.Path.GetFileName(strFileLocation);
}
private static string GetFileContents(string strFileLocation)
{
//
// Read files in bytes, convert to Base64String and return in string
//
using (FileStream reader = new FileStream(strFileLocation, FileMode.Open))
{
byte[] buffer = new byte[reader.Length];
reader.Read(buffer, 0, (int)reader.Length);
string strContent = Convert.ToBase64String(buffer);
ASCIIEncoding encoding = new ASCIIEncoding();
return Encoding.ASCII.GetString(encoding.GetBytes(strContent));
}
}
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/send/fax";
string sender = "application@domain.com";
string api_key = "ta8wr7ymd";
string file1 = "D:\\File1.pdf";
string strJSONData = $@"{{
""Sender"": ""{sender}"",
""APIKey"": ""{api_key}"",
""MessageData"": {{
""Destinations"":
[
{{ ""Recipient"": ""+6495005001"" }},
{{ ""Recipient"": ""+6495005002"" }}
],
""Files"":
[
{{
""Name"": ""{GetFileName(file1)}"",
""Data"": ""{GetFileContents(file1)}""
}}
]
}}
}}";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/json; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
request.ContentLength = byteArray.Length;
Stream newStream = request.GetRequestStream(); //open connection
newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
newStream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
{
"Result": "Success",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/fax
HTTP Header: Content-Type="application/json; encoding='utf-8'"
using System;
using System.IO;
using System.Text;
using System.Net;
namespace TNZ
{
class Program
{
private static string GetFileName(string strFileLocation)
{
return System.IO.Path.GetFileName(strFileLocation);
}
private static string GetFileContents(string strFileLocation)
{
//
// Read files in bytes, convert to Base64String and return in string
//
using (FileStream reader = new FileStream(strFileLocation, FileMode.Open))
{
byte[] buffer = new byte[reader.Length];
reader.Read(buffer, 0, (int)reader.Length);
string strContent = Convert.ToBase64String(buffer);
ASCIIEncoding encoding = new ASCIIEncoding();
return Encoding.ASCII.GetString(encoding.GetBytes(strContent));
}
}
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/send/fax";
string sender = "application@domain.com";
string api_key = "ta8wr7ymd";
string file1 = "D:\\File1.pdf";
string file2 = "D:\\File2.pdf";
string strJSONData = $@"{{
""Sender"": ""{sender}"",
""APIKey"": ""{api_key}"",
""MessageData"": {{
""MessageID"": ""ID123456"",
""Reference"": ""Test1"",
""WebhookCallbackURL"": ""https://www.example.com/webhook"",
""WebhookCallbackFormat"": ""JSON"",
""SendTime"": ""2021-08-01T09:00:00"",
""TimeZone"": ""New Zealand"",
""SubAccount"": ""SubAccount01"",
""Department"": ""Department01"",
""ChargeCode"": ""BillingGroup01"",
""Resolution"": ""High"",
""CSID"": ""Station ID"",
""Destinations"":
[
{{
""Recipient"": ""+6495005000"",
""Attention"": ""John Doe"",
""First Name"": ""John"",
""Last Name"": ""Doe"",
""Company"": ""Example Corp"",
""Custom1"": """",
""Custom2"": """"
}},
{{ ""Recipient"": ""+6495005001"", ""Attention"": ""Recipient 2"" }},
{{ ""Recipient"": ""+6495005002"" }},
{{ ""Recipient"": ""+6495005003"" }}
],
""Files"":
[
{{
""Name"": ""{GetFileName(file1)}"",
""Data"": ""{GetFileContents(file1)}""
}},
{{
""Name"": ""{GetFileName(file2)}"",
""Data"": ""{GetFileContents(file2)}""
}}
]
}}
}}";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/json; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
request.ContentLength = byteArray.Length;
Stream newStream = request.GetRequestStream(); //open connection
newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
newStream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
{
"Result": "Success",
"MessageID": "ID123456"
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/fax
HTTP Header: Content-Type="application/json; encoding='utf-8'"
import requests
import base64
import json
url = "https://api.tnz.co.nz/api/v2.01/send/fax"
headers = {
"Content-Type": "application/json",
"encoding": "utf-8"
}
file_data = base64.b64encode(open("d:/File1.pdf","rb").read()).decode("utf-8")
data = {
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"Destinations" :
[
{ "Recipient": "+6495005001" },
{ "Recipient": "+6495005002" }
],
"Files" :
[
{
"Name": "File1.pdf",
"Data": file_data
}
]
}
}
r = requests.post(url, data=json.dumps(data), headers=headers)
print(r)
print(r.text)
{
"Result": "Success",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/fax
HTTP Header: Content-Type="application/json; encoding='utf-8'"
import requests
import base64
import json
url = "https://api.tnz.co.nz/api/v2.01/send/fax"
headers = {
"Content-Type": "application/json",
"encoding": "utf-8"
}
file_data = base64.b64encode(open("d:/File1.pdf","rb").read()).decode("utf-8")
data = {
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"MessageID": "ID123456",
"Reference": "Test1",
"WebhookCallbackURL": "https://www.example.com/webhook",
"WebhookCallbackFormat": "JSON",
"SendTime": "2021-08-01T09:00:00",
"TimeZone": "New Zealand",
"SubAccount": "SubAccount01",
"Department": "Department01",
"ChargeCode": "BillingGroup01",
"Resolution": "high",
"CSID": "Station ID",
"Destinations" :
[
{
"Recipient": "+6495005000",
"Attention": "John Doe",
"First Name": "John",
"Last Name": "Doe",
"Company": "Example Corp",
"Custom1": "",
"Custom2": ""
},
{ "Recipient": "+6495005001" },
{ "Recipient": "+6495005002" },
{ "Recipient": "+6495005003" }
],
"Files" :
[
{
"Name": "File1.pdf",
"Data": file_data
}
]
}
}
r = requests.post(url, data=json.dumps(data), headers=headers)
print(r)
print(r.text)
{
"Result": "Success",
"MessageID": "ID123456"
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/fax
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?xml version="1.0" encoding="UTF-8"?>
<FaxRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageData>
<Destinations>
<Destination><Recipient>+6495005001</Recipient></Destination>
<Destination><Recipient>+6495005002</Recipient></Destination>
</Destinations>
<Files>
<File>
<Name>Sample.pdf</Name>
<Data>%%BASE-64 CONTENT%%</Data>
</File>
</Files>
</MessageData>
</FaxRequest>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/fax
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?xml version="1.0" encoding="UTF-8"?>
<FaxRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageData>
<MessageID>ID123456</MessageID>
<Reference>Test1</Reference>
<WebhookCallbackURL>https://www.example.com/webhook</Reference>
<WebhookCallbackFormat>XML</Reference>
<SendTime>2021-08-01T09:00:00</SendTime>
<TimeZone>New Zealand</TimeZone>
<SubAccount>SubAccount01</SubAccount>
<Department>Department01</Department>
<ChargeCode>BillingGroup01</ChargeCode>
<Resolution>High</Resolution>
<CSID>Station ID</CSID>
<Destinations>
<Destination>
<Recipient>+6495005000</Recipient>
<Attention>John Doe</Attention>
<FirstName>John</FirstName>
<LastName>Doe</LastName>
<Company>Example Corp</Company>
<Custom1></Custom1>
<Custom2></Custom2>
</Destination>
<Destination><Recipient>+6495005001</Recipient></Destination>
<Destination><Recipient>+6495005002</Recipient></Destination>
<Destination><Recipient>+6495005003</Recipient></Destination>
</Destinations>
<Files>
<File>
<Name>Sample.pdf</Name>
<Data>%%BASE-64 CONTENT%%</Data>
</File>
<File>
<Name>Sample2.pdf</Name>
<Data>%%BASE-64 CONTENT%%</Data>
</File>
</Files>
</MessageData>
</FaxRequest>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/fax
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/send/fax \
--header "Content-Type: text/xml" \
--header "Accept: text/xml" \
--header "encoding='utf-8'" \
--data '<?xml version="1.0" encoding="UTF-8"?>
<FaxRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageData>
<Destinations>
<Destination><Recipient>+6495005001</Recipient></Destination>
<Destination><Recipient>+6495005002</Recipient></Destination>
</Destinations>
<Files>
<File>
<Name>Sample.pdf</Name>
<Data>%%BASE-64 CONTENT%%</Data>
</File>
</Files>
</MessageData>
</FaxRequest>'
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/fax
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/send/fax \
--header "Content-Type: text/xml" \
--header "Accept: text/xml" \
--header "encoding='utf-8'" \
--data '<?xml version="1.0" encoding="UTF-8"?>
<FaxRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageData>
<MessageID>ID123456</MessageID>
<WebhookCallbackURL>https://www.example.com/webhook</Reference>
<WebhookCallbackFormat>XML</Reference>
<Reference>Test1</Reference>
<SendTime>2021-08-01T09:00:00</SendTime>
<TimeZone>New Zealand</TimeZone>
<SubAccount>SubAccount01</SubAccount>
<Department>Department01</Department>
<ChargeCode>BillingGroup01</ChargeCode>
<Resolution>High</Resolution>
<CSID>Station ID</CSID>
<Destinations>
<Destination>
<Recipient>+6495005000</Recipient>
<Attention>John Doe</Attention>
<FirstName>John</FirstName>
<LastName>Doe</LastName>
<Company>Example Corp</Company>
<Custom1></Custom1>
<Custom2></Custom2>
</Destination>
<Destination><Recipient>+6495005001</Recipient></Destination>
<Destination><Recipient>+6495005002</Recipient></Destination>
<Destination><Recipient>+6495005003</Recipient></Destination>
</Destinations>
<Files>
<File>
<Name>Sample.pdf</Name>
<Data>%%BASE-64 CONTENT%%</Data>
</File>
<File>
<Name>Sample2.pdf</Name>
<Data>%%BASE-64 CONTENT%%</Data>
</File>
</Files>
</MessageData>
</FaxRequest>'
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/fax
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?php
function GetBase64Contents($file_name)
{
// returns base64 encoded file data
if( file_exists($file_name) )
{
$fp = fopen($file_name,"r");
$file_content = fread($fp,filesize($file_name));
fclose($fp);
return base64_encode($file_content);
}
}
$file1 = "[File Location]/Sample.pdf";
$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><FaxRequest></FaxRequest>");
$data->addChild("Sender","application@domain.com");
$data->addChild("APIKey","ta8wr7ymd");
$data->addChild("APIVersion","1.05");
$data->addChild("MessageType","Fax");
$data->addChild("MessageData");
$destinations = $data->MessageData->addChild("Destinations");
$destination1 = $destinations->addChild("Destination");
$destination1->addChild("Recipient","+6495005001");
$destination2 = $destinations->addChild("Destination");
$destination2->addChild("Recipient","+6495005002");
if( file_exists($file1) )
{
$files = $data->MessageData->addChild("Files");
$file = $files->addChild("File");
$file->addChild("Name",basename($file1));
$file->addChild("Data",GetBase64Contents($file1));
}
$headers = array(
"Content-Type: text/xml",
"Accept: text/xml",
"encoding='utf-8'",
"Content-length: ".strlen($data->asXML()),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/send/fax");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "400": // error
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "500": // critical error
echo $response."\n";
echo $err;
break;
default:
echo $response."\n";
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/fax
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?php
function GetBase64Contents($file_name)
{
// returns base64 encoded file data
if( file_exists($file_name) )
{
$fp = fopen($file_name,"r");
$file_content = fread($fp,filesize($file_name));
fclose($fp);
return base64_encode($file_content);
}
}
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$message_id = "ID123456"; // optional
$file1 = "[File Location]/Sample.pdf";
$file2 = "[File Location]/Sample2.pdf";
$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><FaxRequest></FaxRequest>");
$data->addChild("Sender",$sender);
$data->addChild("APIKey",$apikey);
$data->addChild("MessageData");
$data->MessageData->addChild("MessageID",$message_id);
$data->MessageData->addChild("Reference","Test1");
$data->MessageData->addChild("WebhookCallbackURL","https://www.example.com/webhook");
$data->MessageData->addChild("WebhookCallbackFormat","XML");
$data->MessageData->addChild("SendTime","2021-08-01T09:00:00");
$data->MessageData->addChild("TimeZone","New Zealand");
$data->MessageData->addChild("SubAccount","SubAccount01");
$data->MessageData->addChild("Department","Department01");
$data->MessageData->addChild("ChargeCode","BillingGroup01");
$data->MessageData->addChild("Resolution","high");
$data->MessageData->addChild("CSID","Station ID");
$destinations = $data->MessageData->addChild("Destinations");
$destination1 = $destinations->addChild("Destination");
$destination1->addChild("Recipient","+6495005000");
$destination1->addChild("Attention","John Doe");
$destination1->addChild("FirstName","John");
$destination1->addChild("LastName","Doe");
$destination1->addChild("Company","Example Corp");
$destination1->addChild("Custom1","");
$destination1->addChild("Custom2","");
$destination2 = $destinations->addChild("Destination");
$destination2->addChild("Recipient","+6495005001");
$destination3 = $destinations->addChild("Destination");
$destination3->addChild("Recipient","+6495005002");
$destination4 = $destinations->addChild("Destination");
$destination4->addChild("Recipient","+6495005003");
if( file_exists($file1) || file_exists($file2) )
{
$files = $data->MessageData->addChild("Files");
if( file_exists($file1) )
{
$file = $files->addChild("File");
$file->addChild("Name",basename($file1));
$file->addChild("Data",GetBase64Contents($file1));
}
if( file_exists($file2) )
{
$file = $files->addChild("File");
$file->addChild("Name",basename($file2));
$file->addChild("Data",GetBase64Contents($file2));
}
}
$headers = array(
"Content-Type: text/xml",
"Accept: text/xml",
"encoding='utf-8'",
"Content-length: ".strlen($data->asXML()),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/send/fax");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "400": // error
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "500": // critical error
echo $response."\n";
echo $err;
break;
default:
echo $response."\n";
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/fax
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Xml;
namespace TNZ
{
class Program
{
#region Functions (XML)
private static string GetFileName(string strFileLocation)
{
return System.IO.Path.GetFileName(strFileLocation);
}
private static string GetFileContents(string strFileLocation)
{
//
// Read files in bytes, convert to Base64String and return in string
//
using (FileStream reader = new FileStream(strFileLocation, FileMode.Open))
{
byte[] buffer = new byte[reader.Length];
reader.Read(buffer, 0, (int)reader.Length);
string strContent = Convert.ToBase64String(buffer);
ASCIIEncoding encoding = new ASCIIEncoding();
return Encoding.ASCII.GetString(encoding.GetBytes(strContent)).Trim();
}
}
private static XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerText = val;
return workingNode;
}
private static XmlNode addChildNodeCDATA(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerXml = @"<![CDATA[" + val + "]]>";
return workingNode;
}
#endregion
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/send/fax";
string file1 = "D:\\File1.pdf";
XmlDocument xmlDoc = new XmlDocument();
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null); // <?xml version="1.0" encoding="UTF-8"?>
xmlDoc.AppendChild(docNode);
XmlNode rootNode = xmlDoc.CreateElement("FaxRequest");
xmlDoc.AppendChild(rootNode);
rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com"));
rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd"));
XmlNode workingNode = xmlDoc.CreateElement("Sender");
//
// MessageData
//
XmlNode messageDataNode = xmlDoc.CreateElement("MessageData");
//
// Add Destinations
//
workingNode = xmlDoc.CreateElement("Destinations");
// Declare Single Destination
XmlNode destNode1 = xmlDoc.CreateElement("Destination");
destNode1.AppendChild(addChildNode(xmlDoc, "Recipient", "+6495005001"));
// Add Destination to Destinations object
workingNode.AppendChild(destNode1);
// Declare Single Destination
XmlNode destNode2 = xmlDoc.CreateElement("Destination");
destNode2.AppendChild(addChildNode(xmlDoc, "Recipient", "+6495005002"));
// Add Destination to Destinations object
workingNode.AppendChild(destNode2);
// Add Destinations to MessageData
messageDataNode.AppendChild(workingNode);
//
// Attach File
//
workingNode = xmlDoc.CreateElement("Files");
XmlNode fileNode = xmlDoc.CreateElement("File");
fileNode.AppendChild(addChildNode(xmlDoc, "Name", GetFileName(file1)));
fileNode.AppendChild(addChildNodeCDATA(xmlDoc, "Data", GetFileContents(file1)));
workingNode.AppendChild(fileNode);
messageDataNode.AppendChild(workingNode);
//
// Set MessageData into root(EmailRequest) node
//
rootNode.AppendChild(messageDataNode);
//
// Send HTTP Request to REST API
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "text/xml; encoding='utf-8'";
request.Accept = "text/xml; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
request.ContentLength = byteArray.Length;
Stream stream = request.GetRequestStream(); //open connection
stream.Write(byteArray, 0, byteArray.Length); // Send the data.
stream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/fax
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Xml;
namespace TNZ
{
class Program
{
#region Functions (XML)
private static string GetFileName(string strFileLocation)
{
return System.IO.Path.GetFileName(strFileLocation);
}
private static string GetFileContents(string strFileLocation)
{
//
// Read files in bytes, convert to Base64String and return in string
//
using (FileStream reader = new FileStream(strFileLocation, FileMode.Open))
{
byte[] buffer = new byte[reader.Length];
reader.Read(buffer, 0, (int)reader.Length);
string strContent = Convert.ToBase64String(buffer);
ASCIIEncoding encoding = new ASCIIEncoding();
return Encoding.ASCII.GetString(encoding.GetBytes(strContent)).Trim();
}
}
private static XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerText = val;
return workingNode;
}
private static XmlNode addChildNodeCDATA(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerXml = @"<![CDATA[" + val + "]]>";
return workingNode;
}
#endregion
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/send/fax";
string file1 = "D:\\File1.pdf";
string file2 = "D:\\File2.pdf";
XmlDocument xmlDoc = new XmlDocument();
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null); // <?xml version="1.0" encoding="UTF-8"?>
xmlDoc.AppendChild(docNode);
XmlNode rootNode = xmlDoc.CreateElement("FaxRequest");
xmlDoc.AppendChild(rootNode);
rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com"));
rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd"));
XmlNode workingNode = xmlDoc.CreateElement("Sender");
//
// MessageData
//
XmlNode messageDataNode = xmlDoc.CreateElement("MessageData");
messageDataNode.AppendChild(addChildNode(xmlDoc, "MessageID", "ID123456"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "Reference", "Test1"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "WebhookCallbackURL", "https://www.example.com/webhook"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "WebhookCallbackFormat", "XML"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "SendTime", "2021-08-01T09:00:00"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "TimeZone", "New Zealand"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "SubAccount", "SubAccount01"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "Department", "Department01"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "ChargeCode", "BillingGroup01"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "Resolution", "High"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "CSID", "Station ID"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "Message", addslashes("Hello,\r\nThis is a test message.\r\nThank you.")));
//
// Add Destinations 1 - Add with details
//
workingNode = xmlDoc.CreateElement("Destinations");
XmlNode destNode = xmlDoc.CreateElement("Destination");
destNode.AppendChild(addChildNode(xmlDoc, "Recipient", "+6495005000"));
destNode.AppendChild(addChildNode(xmlDoc, "Attention", "John Doe"));
destNode.AppendChild(addChildNode(xmlDoc, "FirstName", "John"));
destNode.AppendChild(addChildNode(xmlDoc, "LastName", "Doe"));
destNode.AppendChild(addChildNode(xmlDoc, "Company", "Example Corp"));
destNode.AppendChild(addChildNode(xmlDoc, "Custom1", "Custom1"));
destNode.AppendChild(addChildNode(xmlDoc, "Custom2", "Custom2"));
workingNode.AppendChild(destNode);
//
// Add Destinations 2 - Add emails only
//
destNode = xmlDoc.CreateElement("Destination");
destNode.AppendChild(addChildNode(xmlDoc, "Recipient", "+6495005001"));
workingNode.AppendChild(destNode);
destNode = xmlDoc.CreateElement("Destination");
destNode.AppendChild(addChildNode(xmlDoc, "Recipient", "+6495005002"));
workingNode.AppendChild(destNode);
// Add Destinations to MessageData
messageDataNode.AppendChild(workingNode);
//
// Attach File 1
//
workingNode = xmlDoc.CreateElement("Files");
XmlNode fileNode1 = xmlDoc.CreateElement("File");
fileNode1.AppendChild(addChildNode(xmlDoc, "Name", GetFileName(file1)));
fileNode1.AppendChild(addChildNodeCDATA(xmlDoc, "Data", GetFileContents(file1)));
workingNode.AppendChild(fileNode1);
//
// Attach File 2
//
XmlNode fileNode2 = xmlDoc.CreateElement("File");
fileNode2.AppendChild(addChildNode(xmlDoc, "Name", GetFileName(file2)));
fileNode2.AppendChild(addChildNodeCDATA(xmlDoc, "Data", GetFileContents(file2)));
workingNode.AppendChild(fileNode2);
messageDataNode.AppendChild(workingNode);
//
// Set MessageData into root node
//
rootNode.AppendChild(messageDataNode);
//
// Send HTTP Request to REST API
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "text/xml; encoding='utf-8'";
request.Accept = "text/xml; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
request.ContentLength = byteArray.Length;
Stream stream = request.GetRequestStream(); //open connection
stream.Write(byteArray, 0, byteArray.Length); // Send the data.
stream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/fax
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
import requests
import base64
import xml.etree.ElementTree as ET
url = "https://api.tnz.co.nz/api/v2.01/send/fax"
headers = {
"Content-Type": "text/xml",
"Accept": "text/xml",
"encoding": "utf-8"
}
headers = {
"Content-Type": "text/xml",
"Accept": "text/xml",
"encoding": "utf-8"
}
file_data = base64.b64encode(open("d:/File1.pdf","rb").read()).decode("utf-8")
root = ET.Element('FaxRequest')
ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
message_data = ET.SubElement(root,"MessageData")
destinations = ET.SubElement(message_data,"Destinations")
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination, "Recipient").text = "+6495005001"
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination, "Recipient").text = "+6495005002"
files = ET.SubElement(message_data,"Files")
file = ET.SubElement(files,"File")
ET.SubElement(file,"Name").text = "File1.pdf"
ET.SubElement(file,"Data").text = file_data
r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)
print(r)
print(r.text)
#print(ET.tostring(root))
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/fax
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
import requests
import base64
import xml.etree.ElementTree as ET
url = "https://api.tnz.co.nz/api/v2.01/send/fax"
headers = {
"Content-Type": "text/xml",
"Accept": "text/xml",
"encoding": "utf-8"
}
file_data_1 = base64.b64encode(open("d:/File1.pdf","rb").read()).decode("utf-8")
file_data_2 = base64.b64encode(open("d:/File2.pdf","rb").read()).decode("utf-8")
root = ET.Element('FaxRequest')
ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
message_data = ET.SubElement(root,"MessageData")
ET.SubElement(message_data, "MessageID").text = "ID123456"
ET.SubElement(message_data, "Reference").text = "Test1"
ET.SubElement(message_data, "WebhookCallbackURL").text = "https://www.example.com/webhook"
ET.SubElement(message_data, "WebhookCallbackFormat").text = "XML"
ET.SubElement(message_data, "SendTime").text = "2021-08-01T09:00:00"
ET.SubElement(message_data, "TimeZone").text = "New Zealand"
ET.SubElement(message_data, "SubAccount").text = "SubAccount01"
ET.SubElement(message_data, "Department").text = "Department01"
ET.SubElement(message_data, "ChargeCode").text = "BillingGroup01"
ET.SubElement(message_data, "Resolution").text = "High"
ET.SubElement(message_data, "CSID").text = "Station ID"
destinations = ET.SubElement(message_data,"Destinations")
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination,"Recipient").text = "+6495005000"
ET.SubElement(destination,"Attention").text = "John Doe"
ET.SubElement(destination,"FirstName").text = "John"
ET.SubElement(destination,"LastName").text = "Doe"
ET.SubElement(destination,"Company").text = "Example Corp"
ET.SubElement(destination,"Custom1").text = ""
ET.SubElement(destination,"Custom2").text = ""
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination, "Recipient").text = "+6495005001"
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination, "Recipient").text = "+6495005002"
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination, "Recipient").text = "+6495005003"
files = ET.SubElement(message_data,"Files")
file = ET.SubElement(files,"File")
ET.SubElement(file,"Name").text = "File1.pdf"
ET.SubElement(file,"Data").text = file_data_1
file = ET.SubElement(files,"File")
ET.SubElement(file,"Name").text = "File2.pdf"
ET.SubElement(file,"Data").text = file_data_2
r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)
print(r)
print(r.text)
#print(ET.tostring(root))
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
| Parameter | Example Value | Description | |
|---|---|---|---|
| Destinations | > Recipient | +6495005001 +6495005002 +6495005003 |
Fax number(s) to receive the message (for detailed formatting, see the Destinations parameter below) |
| Files | > Name | Sample.pdf | Fax document's filename |
| > Data | %%Base-64%% | Base-64 encoded value of the document | |
| Parameter | Example Value | Description | |
|---|---|---|---|
| MessageID | ID123456 | A message tracking identifier (maximum 40 characters, alphanumeric). If you do not supply this field, the API will return one for you in the response body (UUID v4 of 36 characters) | |
| Reference | Test1 | Tracking ID or message description | |
| WebhookCallbackURL | https://www.example.com/webhook | Overrides your Sender's default Webhook URL. Requires a default webhook to be configured. A full path including https:// is required. | |
| WebhookCallbackFormat | JSON | Overrides your Sender's default Webhook format ('JSON' or 'XML') | |
| SendTime | 2021-12-31T23:00 | Delay sending until the specified date/time, a single point of time in a combined date and time representation ({date}T{time}; for example, 2017-08-29T04:00 in your local timezone, specified by your Sender setting or overridden using the TimeZone command). | |
| TimeZone | New Zealand | User's local timezone (see Setting Timezones) | |
| SubAccount | SubAccount01 | Used for reporting, billing and Web Dashboard segmentation. See the TNZ API Structure guide's Cost Tracking & Rebilling section. | |
| Department | Department01 | Used for reporting, billing and Web Dashboard segmentation. See the TNZ API Structure guide's Cost Tracking & Rebilling section. | |
| ChargeCode | BillingGroup01 | Bespoke app cost allocation code (for invoice segmentation) | |
| WatermarkFolder | Folder01 | Directory/location of Watermark file to use | |
| WatermarkFirstPage | Watermark File Name | Watermark file to apply to the first page only | |
| WatermarkAllPages | Watermark File Name | Watermark file to apply to all pages | |
| Resolution | High | Quality of the fax image. High for better quality, low for lower quality (faster delivery speed) | |
| CSID | Station ID | Called Subscriber Identification - Maximum 30 characters | |
| Destinations | > Recipient | +6495005000 | Recipient of the Fax in E.164 internationalised format (for localized or friendly formatting, contact your account manager) |
| > Attention | John Doe | Recipient's name | |
| > First Name | John | Recipient's first name | |
| > Last Name | Doe | Recipient's last name | |
| > Company | Example Corp | Recipient's company | |
| > Custom1 | Customisable tracking and personalisation field | ||
| > Custom2 | Customisable tracking and personalisation field | ||
API URL: https://api.tnz.co.nz/api/v2.01/send/voice
HTTP Header: Content-Type="application/json; encoding='utf-8'"
{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"MessageToPeople": "[base64 encoded WAV audio data, 16-bit, 8000hz]",
"Destinations" :
[
{ "Recipient": "+6495005001" },
{ "Recipient": "+6495005002" }
]
}
}
{
"Result": "Success",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/voice
HTTP Header: Content-Type="application/json; encoding='utf-8'"
{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"MessageID": "ID123456",
"Reference": "Test1",
"WebhookCallbackURL": "https://www.example.com/webhook",
"WebhookCallbackFormat": "JSON",
"SendTime": "2021-08-01T09:00:00",
"TimeZone": "New Zealand",
"SubAccount": "SubAccount01",
"Department": "Department01",
"ChargeCode": "BillingGroup01",
"ReportTo": "report@example.com",
"RetryAttempts": 3,
"RetryPeriod": 1,
"MessageToPeople": "[base64 encoded WAV audio data, 16-bit, 8000hz]",
"MessageToAnswerphones": "[base64 encoded WAV audio data, 16-bit, 8000hz]",
"Keypads":
[
{
"Tone": "1",
"RouteNumber": "+64800123123"
},
{
"Tone": "2",
"PlayFile": "[base64 encoded WAV audio data, 16-bit, 8000hz]".
"RouteNumber": "+6498008000"
}
],
"CallRouteMessageToPeople": "[base64 encoded WAV audio data, 16-bit, 8000hz]",
"CallRouteMessageToOperators": "[base64 encoded WAV audio data, 16-bit, 8000hz]",
"CallRouteMessageOnWrongKey": "[base64 encoded WAV audio data, 16-bit, 8000hz]",
"NumberOfOperators": 5,
"Options": "",
"Destinations" :
[
{
"Recipient": "+6421000001",
"Attention": "John Doe",
"First Name": "John",
"Last Name": "Doe",
"Custom1": "",
"Custom2": ""
},
{ "Recipient": "+6495005002" },
{ "Recipient": "+6421000003" }
]
}
}
{
"Result": "Success",
"MessageID": "ID123456"
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/voice
HTTP Header: Content-Type="application/json; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/send/voice \
--header "Content-Type: application/json" \
--header "encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"MessageToPeople": "[base64 encoded WAV audio data, 16-bit, 8000hz]",
"Destinations" :
[
{ "Recipient": "+6495005001" },
{ "Recipient": "+6495005002" }
]
}
}'
{
"Result": "Success",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/voice
HTTP Header: Content-Type="application/json; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/send/voice \
--header "Content-Type: application/json" \
--header "encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"MessageID": "ID123456",
"Reference": "Test1",
"WebhookCallbackURL": "https://www.example.com/webhook",
"WebhookCallbackFormat": "JSON",
"SendTime": "2021-08-01T09:00:00",
"TimeZone": "New Zealand",
"SubAccount": "SubAccount01",
"Department": "Department01",
"ChargeCode": "BillingGroup01",
"ReportTo": "report@example.com",
"MessageToPeople": "[base64 encoded WAV audio data, 16-bit, 8000hz]",
"MessageToAnswerphones": "[base64 encoded WAV audio data, 16-bit, 8000hz]",
"Keypads":
[
{
"Tone": "1",
"RouteNumber": "+64800123123"
},
{
"Tone": "2",
"PlayFile": "[base64 encoded WAV audio data, 16-bit, 8000hz]"
}
],
"CallRouteMessageToPeople": "[base64 encoded WAV audio data, 16-bit, 8000hz]",
"CallRouteMessageToOperators": "[base64 encoded WAV audio data, 16-bit, 8000hz]",
"CallRouteMessageOnWrongKey": "[base64 encoded WAV audio data, 16-bit, 8000hz]",
"NumberOfOperators": "5",
"RetryAttempts": "3",
"RetryPeriod": "1",
"Options": "",
"Destinations" :
[
{
"Recipient": "+6421000001",
"Attention": "John Doe",
"First Name": "John",
"Last Name": "Doe",
"Custom1": "",
"Custom2": ""
},
{ "Recipient": "+6495005002" },
{ "Recipient": "+6421000003" }
]
}
}'
{
"Result": "Success",
"MessageID": "ID123456"
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/voice
HTTP Header: Content-Type="application/json; encoding='utf-8'"
<?php
function GetBase64Contents($file_name)
{
// returns base64 encoded file data
// WAV audio data, 16-bit, 8000hz
if( file_exists($file_name) )
{
$fp = fopen($file_name,"r");
$file_content = fread($fp,filesize($file_name));
fclose($fp);
return base64_encode($file_content);
}
}
$file = "Sample1.wav";
$data = array(
"Sender" => "application@domain.com",
"APIKey" => "ta8wr7ymd",
"MessageData" => array(
"MessageToPeople" => GetBase64Contents($file),
"Destinations" => array(
array( "Recipient" => "+6495005001" ),
array( "Recipient" => "+6495005002" )
),
)
);
$headers = array(
"Content-Type: application/json",
"encoding='utf-8'",
"Content-length: ".strlen(json_encode($data)),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/send/voice");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header('Content-Type: application/json');
echo $response;
break;
case "400": // error
header('Content-Type: application/json');
echo $response;
break;
case "500": // critical error
echo $response."\n";
echo $err;
break;
default:
echo $response."\n";
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
{
"Result": "Success",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/voice
HTTP Header: Content-Type="application/json; encoding='utf-8'"
<?php
function GetBase64Contents($file_name)
{
// returns base64 encoded file data
// WAV audio data, 16-bit, 8000hz
if( file_exists($file_name) )
{
$fp = fopen($file_name,"r");
$file_content = fread($fp,filesize($file_name));
fclose($fp);
return base64_encode($file_content);
}
}
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$message_id = "ID123456"; // optional
$data = array(
"Sender" => $sender,
"APIKey" => $apikey,
"MessageData" => array(
"MessageID" => $message_id,
"Reference" => "Test1",
"WebhookCallbackURL" => "https://www.example.com/webhook",
"WebhookCallbackFormat" => "JSON",
"SendTime" => "2021-08-01T09:00:00",
"TimeZone" => "New Zealand",
"SubAccount" => "SubAccount01",
"Department" => "Department01",
"ChargeCode" => "BillingGroup01",
"ReportTo" => "report@example.com",
"MessageToPeople" => GetBase64Contents("[File Location]/MessageToPeople.wav"),
"MessageToAnswerphones" => GetBase64Contents("[File Location]/MessageToAnswerphones.wav"),
"Keypads" => array(
array(
"Tone" => 1,
"RouteNumber" => "+64800123123"
),
array(
"Tone" => 2,
"PlayFile" => GetBase64Contents("Keypad2.wav")
)
),
"CallRouteMessageToPeople" => GetBase64Contents("[File Location]/CallRouteMessageToPeople.wav"),
"CallRouteMessageToOperators" => GetBase64Contents("[File Location]/CallRouteMessageToOperators.wav"),
"CallRouteMessageOnWrongKey" => GetBase64Contents("[File Location]/CallRouteMessageOnWrongKey.wav"),
"NumberOfOperators" => "5",
"RetryAttempts" => "3",
"RetryPeriod" => "1",
"Options" => "",
"Destinations" => array(
array(
"Recipient" => "+6421000001",
"Attention" => "John Doe",
"First Name" => "John",
"Last Name" => "Doe",
"Custom1" => "",
"Custom2" => ""
),
array( "Recipient" => "+6495005002" ),
array( "Recipient" => "+6495005003" )
),
)
);
$headers = array(
"Content-Type: application/json",
"encoding='utf-8'",
"Content-length: ".strlen(json_encode($data)),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/send/voice");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header('Content-Type: application/json');
echo $response;
break;
case "400": // error
header('Content-Type: application/json');
echo $response;
break;
case "500": // critical error
echo $response."\n";
echo $err;
break;
default:
echo $response."\n";
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
{
"Result": "Success",
"MessageID": "ID123456"
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/voice
HTTP Header: Content-Type="application/json; encoding='utf-8'"
using System;
using System.IO;
using System.Text;
using System.Net;
namespace TNZ
{
class Program
{
private static string GetFileContents(string strFileLocation)
{
//
// Read files in bytes, convert to Base64String and return in string
//
using (FileStream reader = new FileStream(strFileLocation, FileMode.Open))
{
byte[] buffer = new byte[reader.Length];
reader.Read(buffer, 0, (int)reader.Length);
string strContent = Convert.ToBase64String(buffer);
ASCIIEncoding encoding = new ASCIIEncoding();
return Encoding.ASCII.GetString(encoding.GetBytes(strContent));
}
}
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/send/voice";
string sender = "application@domain.com";
string api_key = "ta8wr7ymd";
string file1 = "D:\\File1.wav";
string strJSONData = $@"{{
""Sender"": ""{sender}"",
""APIKey"": ""{api_key}"",
""MessageData"": {{
""MessageToPeople"": ""{GetFileContents(file1)}"",
""Destinations"":
[
{{ ""Recipient"": ""+6495005001"" }},
{{ ""Recipient"": ""+6495005002"" }}
]
}}
}}";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/json; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
request.ContentLength = byteArray.Length;
Stream newStream = request.GetRequestStream(); //open connection
newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
newStream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
{
"Result": "Success",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/voice
HTTP Header: Content-Type="application/json; encoding='utf-8'"
using System;
using System.IO;
using System.Text;
using System.Net;
namespace TNZ
{
class Program
{
private static string GetFileContents(string strFileLocation)
{
//
// Read files in bytes, convert to Base64String and return in string
//
using (FileStream reader = new FileStream(strFileLocation, FileMode.Open))
{
byte[] buffer = new byte[reader.Length];
reader.Read(buffer, 0, (int)reader.Length);
string strContent = Convert.ToBase64String(buffer);
ASCIIEncoding encoding = new ASCIIEncoding();
return Encoding.ASCII.GetString(encoding.GetBytes(strContent));
}
}
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/send/voice";
string sender = "application@domain.com";
string api_key = "ta8wr7ymd";
string fileMessageToPeople = "D:\\File1.wav";
string fileMessageToAnswerPhones = "D:\\File2.wav";
string fileCallRouteMsgToPeople = "D:\\File3.wav";
string fileCallRouteMsgToOperators = "D:\\File4.wav";
string fileCallRouteMsgOnWrongKey = "D:\\File5.wav";
string strJSONData = $@"{{
""Sender"": ""{sender}"",
""APIKey"": ""{api_key}"",
""MessageData"": {{
""MessageID"": ""ID123456"",
""Reference"": ""Test1"",
""WebhookCallbackURL"":""https://www.example.com/webhook"",
""WebhookCallbackFormat"":""JSON"",
""SendTime"": ""2021-08-01T09:00:00"",
""TimeZone"": ""New Zealand"",
""SubAccount"": ""SubAccount01"",
""Department"": ""Department01"",
""ChargeCode"": """",
""CallerID"": ""+6495005000"",
""MessageToPeople"": ""{GetFileContents(fileMessageToPeople)}"",
""MessageToAnswerphones"": ""{GetFileContents(fileMessageToAnswerPhones)}"",
""CallRouteMessageToPeople"": ""{GetFileContents(fileCallRouteMsgToPeople)}"",
""CallRouteMessageToOperators"": ""{GetFileContents(fileCallRouteMsgToOperators)}"",
""CallRouteMessageOnWrongKey"": ""{GetFileContents(fileCallRouteMsgOnWrongKey)}"",
""NumberOfOperators"": 5,
""RetryAttempts"": 3,
""RetryPeriod"": 1,
""Options"": """",
""Keypads"":
[
{{ ""Tone"": 1, ""RouteNumber"": ""+64800123123"" }},
{{ ""Tone"": 2, ""RouteNumber"": ""+6498008000"" }},
],
""Destinations"":
[
{{
""Recipient"": ""+649000001"",
""Attention"": ""John Doe"",
""First Name"": ""John"",
""Last Name"": ""Doe"",
""Company"": ""Example Corp""
}},
{{ ""Recipient"": ""+647000001"", ""Attention"": ""Recipient 2"" }},
{{ ""Recipient"": ""+645000001"" }},
{{ ""Recipient"": ""+643000001"" }}
]
}}
}}";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/json; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
request.ContentLength = byteArray.Length;
Stream newStream = request.GetRequestStream(); //open connection
newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
newStream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
{
"Result": "Success",
"MessageID": "ID123456"
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/voice
HTTP Header: Content-Type="application/json; encoding='utf-8'"
import requests
import base64
import json
url = "https://api.tnz.co.nz/api/v2.01/send/voice"
headers = {
"Content-Type": "application/json",
"encoding": "utf-8"
}
file_data = base64.b64encode(open("d:/1.Intro.wav","rb").read()).decode("utf-8")
data = {
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"MessageToPeople": file_data,
"Destinations" :
[
{ "Recipient": "+6495005001" },
{ "Recipient": "+6495005002" }
]
}
}
r = requests.post(url, data=json.dumps(data), headers=headers)
print(r)
print(r.text)
{
"Result": "Success",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/voice
HTTP Header: Content-Type="application/json; encoding='utf-8'"
import requests
import base64
import json
url = "https://api.tnz.co.nz/api/v2.01/send/voice"
headers = {
"Content-Type": "application/json",
"encoding": "utf-8"
}
voice_files = {
"MessageToPeople": "[File Location]/MessageToPeople.wav",
"MessageToAnswerphones": "[File Location]/MessageToAnswerphones.wav",
"CallRouteMessageToPeople": "[File Location]/CallRouteMessageToPeople.wav",
"CallRouteMessageToOperators": "[File Location]/CallRouteMessageToOperators.wav",
"CallRouteMessageOnWrongKey": "[File Location]/CallRouteMessageOnWrongKey.wav",
"Keypad2Message": "[File Location]/Keypad2Message.wav"
}
data = {
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"MessageID": "ID123456",
"Reference": "Test1",
"WebhookCallbackURL": "https://www.example.com/webhook",
"WebhookCallbackFormat": "JSON",
"SendTime": "2021-08-01T09:00:00",
"TimeZone": "New Zealand",
"SubAccount": "SubAccount01",
"Department": "Department01",
"ChargeCode": "BillingGroup01",
"ReportTo": "report@example.com",
"MessageToPeople": base64.b64encode(open(voice_files["MessageToPeople"],"rb").read()).decode("utf-8"),
"MessageToAnswerphones": base64.b64encode(open(voice_files["MessageToAnswerphones"],"rb").read()).decode("utf-8"),
"Keypads" => [
{
"Tone": 1,
"RouteNumber": "+64800123123"
},
{
"Tone": 2,
"PlayFile": base64.b64encode(open(voice_files["Keypad2Message"],"rb").read()).decode("utf-8")
}
],
"CallRouteMessageToPeople": base64.b64encode(open(voice_files["CallRouteMessageToPeople"],"rb").read()).decode("utf-8"),
"CallRouteMessageToOperators": base64.b64encode(open(voice_files["CallRouteMessageToOperators"],"rb").read()).decode("utf-8"),
"CallRouteMessageOnWrongKey": base64.b64encode(open(voice_files["CallRouteMessageOnWrongKey"],"rb").read()).decode("utf-8"),
"NumberOfOperators": "5",
"RetryAttempts": "3",
"RetryPeriod": "1",
"Options": "",
"Destinations" :
[
{
"Recipient": "+6421000001",
"Attention": "John Doe",
"First Name": "John",
"Last Name": "Doe",
"Custom1": "",
"Custom2": ""
},
{ "Recipient": "+6495005002" },
{ "Recipient": "+6421000003" }
]
}
}
r = requests.post(url, data=json.dumps(data), headers=headers)
print(r)
print(r.text)
{
"Result": "Success",
"MessageID": "ID123456"
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/voice
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?xml version="1.0" encoding="UTF-8"?>
<VoiceRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageData>
<MessageToPeople>[base64 encoded WAV audio data, 16-bit, 8000hz]</MessageToPeople>
<Destinations>
<Destination><Recipient>+6495005001</Recipient></Destination>
<Destination><Recipient>+6495005002</Recipient></Destination>
</Destinations>
</MessageData>
</VoiceRequest>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/voice
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?xml version="1.0" encoding="UTF-8"?>
<VoiceRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageData>
<MessageID>ID123456</MessageID>
<Reference>Test1</Reference>
<WebhookCallbackURL>https://www.example.com/webhook</WebhookCallbackURL>
<WebhookCallbackFormat>XML</WebhookCallbackFormat>
<SendTime>2021-08-01T09:00:00</SendTime>
<TimeZone>New Zealand</TimeZone>
<SubAccount>SubAccount01</SubAccount>
<Department>Department01</Department>
<ChargeCode>BillingGroup01</ChargeCode>
<ReportTo>report@example.com</ReportTo>
<MessageToPeople>[base64 encoded WAV audio data, 16-bit, 8000hz]</MessageToPeople>
<MessageToAnswerphones>[base64 encoded WAV audio data, 16-bit, 8000hz]</MessageToAnswerphones>
<Keypads>
<Keypad>
<Tone>1</Tone>
<RouteNumber>+64800123123</RouteNumber>
</Keypad>
<Keypad>
<Tone>2</Tone>
<PlayFile>[base64 encoded WAV audio data, 16-bit, 8000hz]</PlayFile>
</Keypad>
</Keypads>
<CallRouteMessageToPeople>[base64 encoded WAV audio data, 16-bit, 8000hz]</CallRouteMessageToPeople>
<CallRouteMessageToOperators>[base64 encoded WAV audio data, 16-bit, 8000hz]</CallRouteMessageToOperators>
<CallRouteMessageOnWrongKey>[base64 encoded WAV audio data, 16-bit, 8000hz]</CallRouteMessageOnWrongKey>
<NumberOfOperators>5</NumberOfOperators>
<RetryAttempts>5</RetryAttempts>
<RetryPeriod>5</RetryPeriod>
<Options></Options>
<Destinations>
<Destination>
<Recipient>+6421000001</Recipient>
<Attention>John Doe</Attention>
<FirstName>John</FirstName>
<LastName>Doe</LastName>
<Company>Example Corp</Company>
<Custom1></Custom1>
<Custom2></Custom2>
</Destination>
<Destination><Recipient>+6495005002</Recipient></Destination>
<Destination><Recipient>+6421000003</Recipient></Destination>
</Destinations>
</MessageData>
</VoiceRequest>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/voice
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/send/voice \
--header "Content-Type: text/xml" \
--header "Accept: text/xml" \
--header "encoding='utf-8'" \
--data '<?xml version="1.0" encoding="UTF-8"?>
<VoiceRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageData>
<MessageToPeople>[base64 encoded WAV audio data, 16-bit, 8000hz]</MessageToPeople>
<Destinations>
<Destination><Recipient>+6495005001</Recipient></Destination>
<Destination><Recipient>+6495005002</Recipient></Destination>
</Destinations>
</MessageData>
</VoiceRequest>'
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/voice
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/send/voice \
--header "Content-Type: text/xml" \
--header "Accept: text/xml" \
--header "encoding='utf-8'" \
--data '<?xml version="1.0" encoding="UTF-8"?>
<VoiceRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageData>
<MessageID>ID123456</MessageID>
<Reference>Test1</Reference>
<WebhookCallbackURL>https://www.example.com/webhook</WebhookCallbackURL>
<WebhookCallbackFormat>XML</WebhookCallbackFormat>
<SendTime>2021-08-01T09:00:00</SendTime>
<TimeZone>New Zealand</TimeZone>
<SubAccount>SubAccount01</SubAccount>
<Department>Department01</Department>
<ChargeCode>BillingGroup01</ChargeCode>
<ReportTo>report@example.com</ReportTo>
<MessageToPeople>[base64 encoded WAV audio data, 16-bit, 8000hz]</MessageToPeople>
<MessageToAnswerphones>[base64 encoded WAV audio data, 16-bit, 8000hz]</MessageToAnswerphones>
<Keypads>
<Keypad>
<Tone>1</Tone>
<RouteNumber>+64800123123</RouteNumber>
</Keypad>
<Keypad>
<Tone>2</Tone>
<PlayFile>[base64 encoded WAV audio data, 16-bit, 8000hz]</PlayFile>
</Keypad>
</Keypads>
<CallRouteMessageToPeople>[base64 encoded WAV audio data, 16-bit, 8000hz]</CallRouteMessageToPeople>
<CallRouteMessageToOperators>[base64 encoded WAV audio data, 16-bit, 8000hz]</CallRouteMessageToOperators>
<CallRouteMessageOnWrongKey>[base64 encoded WAV audio data, 16-bit, 8000hz]</CallRouteMessageOnWrongKey>
<NumberOfOperators>5</NumberOfOperators>
<RetryAttempts>5</RetryAttempts>
<RetryPeriod>5</RetryPeriod>
<Options></Options>
<Destinations>
<Destination>
<Recipient>+6421000001</Recipient>
<Attention>John Doe</Attention>
<FirstName>John</FirstName>
<LastName>Doe</LastName>
<Company>Example Corp</Company>
<Custom1></Custom1>
<Custom2></Custom2>
</Destination>
<Destination><Recipient>+6495005002</Recipient></Destination>
<Destination><Recipient>+6421000003</Recipient></Destination>
</Destinations>
</MessageData>
</VoiceRequest>'
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/voice
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?php
function GetBase64Contents($file_name)
{
// returns base64 encoded WAV audio data
// recommended wave format is 16-bit, 8000hz
if( file_exists($file_name) )
{
$fp = fopen($file_name,"r");
$file_content = fread($fp,filesize($file_name));
fclose($fp);
return base64_encode($file_content);
}
}
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><VoiceRequest></VoiceRequest>");
$data->addChild("Sender",$sender);
$data->addChild("APIKey",$apikey);
$data->addChild("MessageData");
$data->MessageData->addChild("MessageToPeople",GetBase64Contents("[File Location]/MessageToPeople.wav"));
// Add Destinations Element
$destinations = $data->MessageData->addChild("Destinations");
// Add Destination in Destinations
$destination1 = $destinations->addChild("Destination");
$destination1->addChild("Recipient","+6495005001");
// Add Destination in Destinations
$destination2 = $destinations->addChild("Destination");
$destination2->addChild("Recipient","+6495005002");
$headers = array(
"Content-Type: text/xml",
"Accept: text/xml",
"encoding='utf-8'",
"Content-length: ".strlen($data->asXML()),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/send/voice");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "400": // error
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "500": // critical error
echo $response."\n";
echo $err;
break;
default:
echo $response."\n";
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/voice
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?php
function GetBase64Contents($file_name)
{
// returns base64 encoded WAV audio data
// recommended wave format is 16-bit, 8000hz
if( file_exists($file_name) )
{
$fp = fopen($file_name,"r");
$file_content = fread($fp,filesize($file_name));
fclose($fp);
return base64_encode($file_content);
}
}
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$message_id = "ID123456";
$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><VoiceRequest></VoiceRequest>");
$data->addChild("Sender",$sender);
$data->addChild("APIKey",$apikey);
$data->addChild("MessageData");
$data->MessageData->addChild("MessageID",$message_id);
$data->MessageData->addChild("Reference","Test1");
$data->MessageData->addChild("WebhookCallbackURL","https://www.example.com/webhook");
$data->MessageData->addChild("WebhookCallbackFormat","XML");
$data->MessageData->addChild("SendTime","2021-08-01T09:00:00");
$data->MessageData->addChild("TimeZone","New Zealand");
$data->MessageData->addChild("SubAccount","SubAccount01");
$data->MessageData->addChild("Department","Department01");
$data->MessageData->addChild("ChargeCode","BillingGroup01");
$data->MessageData->addChild("ReportTo","report@example.com");
$data->MessageData->addChild("MessageToPeople",GetBase64Contents("[File Location]/MessageToPeople.wav"));
$data->MessageData->addChild("MessageToAnswerphones",GetBase64Contents("[File Location]/MessageToAnswerphones.wav"));
$keypads = $data->MessageData->addChild("Keypads");
$keypad = $keypads->addChild("Keypad");
$keypad->addChild("Tone",1);
$keypad->addChild("RouteNumber","+64800123123");
$keypad = $keypads->addChild("Keypad");
$keypad->addChild("Tone",2);
$keypad->addChild("PlayFile",GetBase64Contents("[File Location]/Play2.wav"));
$data->MessageData->addChild("CallRouteMessageToPeople",GetBase64Contents("[File Location]/CallRouteMessageToPeople.wav"));
$data->MessageData->addChild("CallRouteMessageToOperators",GetBase64Contents("[File Location]/CallRouteMessageToOperators.wav"));
$data->MessageData->addChild("CallRouteMessageOnWrongKey",GetBase64Contents("[File Location]/CallRouteMessageOnWrongKey.wav"));
$data->MessageData->addChild("NumberOfOperators",5);
$data->MessageData->addChild("RetryAttempts",3);
$data->MessageData->addChild("RetryPeriod",5);
$data->MessageData->addChild("Options","");
$destinations = $data->MessageData->addChild("Destinations");
$destination1 = $destinations->addChild("Destination");
$destination1->addChild("Recipient","+6421000001");
$destination1->addChild("Attention","John Doe");
$destination1->addChild("FirstName","John");
$destination1->addChild("LastName","Doe");
$destination1->addChild("Company","Example Corp");
$destination1->addChild("Custom1","");
$destination1->addChild("Custom2","");
$destination2 = $destinations->addChild("Destination");
$destination2->addChild("Recipient","+6495005002");
$destination3 = $destinations->addChild("Destination");
$destination3->addChild("Recipient","+6421000003");
$destination4 = $destinations->addChild("Destination");
$destination4->addChild("Recipient","+6422000004");
$headers = array(
"Content-Type: text/xml",
"Accept: text/xml",
"encoding='utf-8'",
"Content-length: ".strlen($data->asXML()),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/send/voice");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "400": // error
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "500": // critical error
echo $response."\n";
echo $err;
break;
default:
echo $response."\n";
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/voice
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
namespace SendVoiceXml
{
class Program
{
#region Functions (XML)
private static string GetFileContents(string strFileLocation)
{
//
// Read files in bytes, convert to Base64String and return in string
//
using (FileStream reader = new FileStream(strFileLocation, FileMode.Open))
{
byte[] buffer = new byte[reader.Length];
reader.Read(buffer, 0, (int)reader.Length);
string strContent = Convert.ToBase64String(buffer);
ASCIIEncoding encoding = new ASCIIEncoding();
return Encoding.ASCII.GetString(encoding.GetBytes(strContent)).Trim();
}
}
private static XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerText = val;
return workingNode;
}
#endregion
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/send/voice";
string strSender = "application@domain.com";
string strAPIKey = "ta8wr7ymd";
//
// Send Voice by XML API Interface
//
XmlDocument xmlDoc = new XmlDocument();
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null); // <?xml version="1.0" encoding="UTF-8"?>
xmlDoc.AppendChild(docNode);
XmlNode rootNode = xmlDoc.CreateElement("VoiceRequest");
xmlDoc.AppendChild(rootNode);
rootNode.AppendChild(addChildNode(xmlDoc, "Sender", strSender));
rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", strAPIKey));
XmlNode workingNode = xmlDoc.CreateElement("Sender");
//
// MessageData
//
XmlNode messageDataNode = xmlDoc.CreateElement("MessageData");
messageDataNode.AppendChild(addChildNode(xmlDoc, "MessageToPeople", GetFileContents("[File Location]/MessageToPeople.wav")));
workingNode = xmlDoc.CreateElement("Destinations");
//
// Add Destinations 1 - Add with details
//
XmlNode destNode1 = xmlDoc.CreateElement("Destination");
destNode1.AppendChild(addChildNode(xmlDoc, "Recipient", "+6495005001"));
workingNode.AppendChild(destNode1);
//
// Add Destinations 2 - Add with details
//
XmlNode destNode2 = xmlDoc.CreateElement("Destination");
destNode2.AppendChild(addChildNode(xmlDoc, "Recipient", "+6495005002"));
workingNode.AppendChild(destNode2);
messageDataNode.AppendChild(workingNode);
//
// Set MessageData into root node
//
rootNode.AppendChild(messageDataNode);
//
// Send Raw XML API Request to REST API
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "text/xml; encoding='utf-8'";
request.Accept = "text/xml; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
request.ContentLength = byteArray.Length;
Stream newStream = request.GetRequestStream(); //open connection
newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
newStream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/voice
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
namespace SendVoiceXmlAdvanced
{
class Program
{
#region Functions (XML)
private static string GetFileContents(string strFileLocation)
{
//
// Read files in bytes, convert to Base64String and return in string
//
using (FileStream reader = new FileStream(strFileLocation, FileMode.Open))
{
byte[] buffer = new byte[reader.Length];
reader.Read(buffer, 0, (int)reader.Length);
string strContent = Convert.ToBase64String(buffer);
ASCIIEncoding encoding = new ASCIIEncoding();
return Encoding.ASCII.GetString(encoding.GetBytes(strContent)).Trim();
}
}
private static XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerText = val;
return workingNode;
}
#endregion
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/send/voice";
string strSender = "application@domain.com";
string strAPIKey = "ta8wr7ymd";
//
// Send Voice by XML API Interface
//
XmlDocument xmlDoc = new XmlDocument();
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null); // <?xml version="1.0" encoding="UTF-8"?>
xmlDoc.AppendChild(docNode);
XmlNode rootNode = xmlDoc.CreateElement("VoiceRequest");
xmlDoc.AppendChild(rootNode);
rootNode.AppendChild(addChildNode(xmlDoc, "Sender", strSender));
rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", strAPIKey));
XmlNode workingNode = xmlDoc.CreateElement("Sender");
//
// MessageData
//
XmlNode messageDataNode = xmlDoc.CreateElement("MessageData");
messageDataNode.AppendChild(addChildNode(xmlDoc, "MessageID", "ID123456"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "Reference", "Test1"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "WebhookCallbackURL", "https://www.example.com/webhook"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "WebhookCallbackFormat", "XML"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "SendTime", "2021-08-01T09:00:00"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "TimeZone", "New Zealand"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "SubAccount", "SubAccount01"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "Department", "Department01"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "ChargeCode", "BillingGroup01"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "MessageToPeople", GetFileContents("[File Location]/MessageToPeople.wav")));
messageDataNode.AppendChild(addChildNode(xmlDoc, "MessageToAnswerphones", GetFileContents("[File Location]/MessageToAnswerphones.wav")));
//
// Add Keypad 1 - RouteNumber
//
workingNode = xmlDoc.CreateElement("Keypads");
XmlNode keypadNode1 = xmlDoc.CreateElement("Keypad");
keypadNode1.AppendChild(addChildNode(xmlDoc, "Tone", "1"));
keypadNode1.AppendChild(addChildNode(xmlDoc, "RouteNumber", "+64800123123"));
workingNode.AppendChild(keypadNode1);
//
// Add Keypad 2 - RouteNumber + Play
//
XmlNode keypadNode2 = xmlDoc.CreateElement("Keypad");
keypadNode2.AppendChild(addChildNode(xmlDoc, "Tone", "2"));
keypadNode2.AppendChild(addChildNode(xmlDoc, "PlayFile", GetFileContents("[File Location]/Play2.wav")));
keypadNode2.AppendChild(addChildNode(xmlDoc, "RouteNumber", "+6498008000"));
workingNode.AppendChild(keypadNode2);
messageDataNode.AppendChild(workingNode);
messageDataNode.AppendChild(addChildNode(xmlDoc, "CallRouteMessageToPeople", GetFileContents("[File Location]/CallRouteMessageToPeople.wav")));
messageDataNode.AppendChild(addChildNode(xmlDoc, "CallRouteMessageToOperators", GetFileContents("[File Location]/CallRouteMessageToOperators.wav")));
messageDataNode.AppendChild(addChildNode(xmlDoc, "CallRouteMessageOnWrongKey", GetFileContents("[File Location]/CallRouteMessageOnWrongKey.wav")));
messageDataNode.AppendChild(addChildNode(xmlDoc, "NumberOfOperators", "5"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "RetryAttempts", "3"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "RetryPeriod", "1"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "Options", ""));
workingNode = xmlDoc.CreateElement("Destinations");
XmlNode destNode = xmlDoc.CreateElement("Destination");
destNode.AppendChild(addChildNode(xmlDoc, "Recipient", "+6421000001"));
destNode.AppendChild(addChildNode(xmlDoc, "Attention", "John Doe"));
destNode.AppendChild(addChildNode(xmlDoc, "FirstName", "John"));
destNode.AppendChild(addChildNode(xmlDoc, "LastName", "Doe"));
destNode.AppendChild(addChildNode(xmlDoc, "Company", "Example Corp"));
destNode.AppendChild(addChildNode(xmlDoc, "Custom1", "Custom1"));
destNode.AppendChild(addChildNode(xmlDoc, "Custom2", "Custom2"));
workingNode.AppendChild(destNode);
//
// Add Destinations - Add numbers only
//
destNode = xmlDoc.CreateElement("Destination");
destNode.AppendChild(addChildNode(xmlDoc, "Recipient", "+6495005002"));
workingNode.AppendChild(destNode);
destNode = xmlDoc.CreateElement("Destination");
destNode.AppendChild(addChildNode(xmlDoc, "Recipient", "+6421000003"));
workingNode.AppendChild(destNode);
// Add Destinations to MessageData
messageDataNode.AppendChild(workingNode);
//
// Set MessageData into root node
//
rootNode.AppendChild(messageDataNode);
//
// Send Raw XML API Request to REST API
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "text/xml; encoding='utf-8'";
request.Accept = "text/xml; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
request.ContentLength = byteArray.Length;
Stream newStream = request.GetRequestStream(); //open connection
newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
newStream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/voice
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
import requests
import base64
import xml.etree.ElementTree as ET
url = "https://api.tnz.co.nz/api/v2.01/send/voice"
headers = {
"Content-Type": "text/xml",
"Accept": "text/xml",
"encoding": "utf-8"
}
file_data = base64.b64encode(open("d:/file1.wav","rb").read()).decode("utf-8")
root = ET.Element('VoiceRequest')
ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
message_data = ET.SubElement(root,"MessageData")
ET.SubElement(message_data, "MessageToPeople").text = file_data
destinations = ET.SubElement(message_data,"Destinations")
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination, "Recipient").text = "+6495005001"
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination, "Recipient").text = "+6421000002"
r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)
print(r)
print(r.text)
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/voice
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
import requests
import base64
import xml.etree.ElementTree as ET
url = "https://api.tnz.co.nz/api/v2.01/send/voice"
headers = {
"Content-Type": "text/xml",
"Accept": "text/xml",
"encoding": "utf-8"
}
voice_files = {
"MessageToPeople": "d:/file1.wav",
"MessageToAnswerphones": "d:/file2.wav",
"CallRouteMessageToPeople": "d:/file3.wav",
"CallRouteMessageToOperators": "d:/file4.wav",
"CallRouteMessageOnWrongKey": "d:/file5.wav",
"Keypad2Message": "d:/file6.wav",
}
root = ET.Element('VoiceRequest')
ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
message_data = ET.SubElement(root,"MessageData")
ET.SubElement(message_data, "MessageID").text = "ID123456"
ET.SubElement(message_data, "Reference").text = "Test1"
ET.SubElement(message_data, "WebhookCallbackURL").text = "https://www.example.com/webhook"
ET.SubElement(message_data, "WebhookCallbackFormat").text = "XML"
ET.SubElement(message_data, "SendTime").text = "2021-08-01T09:00:00"
ET.SubElement(message_data, "TimeZone").text = "New Zealand"
ET.SubElement(message_data, "SubAccount").text = "SubAccount01"
ET.SubElement(message_data, "Department").text = "Department01"
ET.SubElement(message_data, "ChargeCode").text = "BillingGroup01"
ET.SubElement(message_data, "ReportTo").text = "report@example.com"
ET.SubElement(message_data, "MessageToPeople").text = base64.b64encode(open(voice_files["MessageToPeople"],"rb").read()).decode("utf-8")
ET.SubElement(message_data, "MessageToAnswerphones").text = base64.b64encode(open(voice_files["MessageToAnswerphones"],"rb").read()).decode("utf-8")
keypads = ET.SubElement(message_data,"Keypads")
keypad = ET.SubElement(keypads,"Keypad")
ET.SubElement(keypad,"Tone").text = "1"
ET.SubElement(keypad,"RouteNumber").text = "+64800123123"
keypad = ET.SubElement(keypads,"Keypad")
ET.SubElement(keypad,"Tone").text = "2"
ET.SubElement(keypad,"PlayFile").text = base64.b64encode(open(voice_files["Keypad2Message"],"rb").read()).decode("utf-8")
ET.SubElement(message_data, "CallRouteMessageToPeople").text = base64.b64encode(open(voice_files["CallRouteMessageToPeople"],"rb").read()).decode("utf-8")
ET.SubElement(message_data, "CallRouteMessageToOperators").text = base64.b64encode(open(voice_files["CallRouteMessageToOperators"],"rb").read()).decode("utf-8")
ET.SubElement(message_data, "CallRouteMessageOnWrongKey").text = base64.b64encode(open(voice_files["CallRouteMessageOnWrongKey"],"rb").read()).decode("utf-8")
ET.SubElement(message_data, "NumberOfOperators").text = "5"
ET.SubElement(message_data, "RetryAttempts").text = "5"
ET.SubElement(message_data, "RetryPeriod").text = "1"
ET.SubElement(message_data, "Options").text = "5"
destinations = ET.SubElement(message_data,"Destinations")
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination,"Recipient").text = "+6421000001"
ET.SubElement(destination,"Attention").text = "John Doe"
ET.SubElement(destination,"FirstName").text = "John"
ET.SubElement(destination,"LastName").text = "Doe"
ET.SubElement(destination,"Company").text = "Example Corp"
ET.SubElement(destination,"Custom1").text = ""
ET.SubElement(destination,"Custom2").text = ""
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination, "Recipient").text = "+6495005002"
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination, "Recipient").text = "+6421000003"
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination, "Recipient").text = "+6495005004"
r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)
print(r)
print(r.text)
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
| Parameter | Example Value | Description | |
|---|---|---|---|
| MessageToPeople | [Base64 encoded data] | The audio data played if the call is answered by a human (WAV format, 16-bit, 8000hz) | |
| Destinations | > Recipient | +6495005001 +6495005002 +6495005003 |
Telephone number(s) to receive the message (for detailed formatting, see the Destinations parameter below) |
| Parameter | Example Value | Description | |
|---|---|---|---|
| MessageID | ID123456 | A message tracking identifier (maximum 40 characters, alphanumeric). If you do not supply this field, the API will return one for you in the response body (UUID v4 of 36 characters) | |
| Reference | Test1 | Tracking ID or message description | |
| WebhookCallbackURL | https://www.example.com/webhook | Overrides your Sender's default Webhook URL. Requires a default webhook to be configured. A full path including https:// is required. | |
| WebhookCallbackFormat | JSON | Overrides your Sender's default Webhook format ('JSON' or 'XML') | |
| SendTime | 2021-12-31T23:00 | Delay sending until the specified date/time, a single point of time in a combined date and time representation ({date}T{time}; for example, 2017-08-29T04:00 in your local timezone, specified by your Sender setting or overridden using the TimeZone command). | |
| TimeZone | New Zealand | User's local timezone (see Setting Timezones) | |
| SubAccount | SubAccount01 | Used for reporting, billing and Web Dashboard segmentation. See the TNZ API Structure guide's Cost Tracking & Rebilling section. | |
| Department | Department01 | Used for reporting, billing and Web Dashboard segmentation. See the TNZ API Structure guide's Cost Tracking & Rebilling section. | |
| ChargeCode | BillingGroup01 | Bespoke app cost allocation code (for invoice segmentation) | |
| ReportTo | report@example.com | For email (SMTP) message delivery report notifications. | |
| MessageToAnswerphones | [Base64 encoded data] | The audio data played when the call is answered by an answering machine/voicemail service (WAV format, 16-bit, 8000hz) | |
| Keypads | > Tone | 1 | Keypad for call connection (supports buttons 1-9) |
| > RouteNumber | +64800123123 | Telephone number for call routing in dialling format | |
| > Play | [Base64 encoded data] | Audio data played to B-Party when a keypad option is pressed (WAV format, 16-bit, 8000hz), eg "Thank you. You have pressed keypad 1." | |
| CallRouteMessageToPeople | [Base64 encoded data] | Audio data played when a keypad option is pressed (WAV format, 16-bit, 8000hz), eg "Connecting you now." | |
| CallRouteMessageToOperators | [Base64 encoded data] | Audio data played to the call centre representative answering the connected call (WAV format, 16-bit, 8000hz), eg "Incoming Text To Speech call." | |
| CallRouteMessageOnWrongKey | [Base64 encoded data] | Audio data played when an unregistered keypad button is pressed (WAV format, 16-bit, 8000hz), eg "Sorry, you have pressed an invalid key. Please try again" | |
| NumberOfOperators | 5 | Limits the maximum simultaneous calls (where multiple 'Destinations' are listed) | |
| RetryAttempts | 3 | Number of retry attempts if the recipients line is busy or unavailable | |
| RetryPeriod | 1 | Minutes apart when performing retries | |
| CallerID | +6495005000 | Sets the Caller ID used on the call (must be E.164 format) | |
| Options | Customisable field that allows advanced voice options including recording survey responses, recording phone numbers, playing IVR options, capturing DTMF tones for account numbers or credit card numbers, etc. | ||
| Destinations | > Recipient | +6495005000 | Recipient of the call in E.164 internationalised format (for localized or friendly formatting, contact your account manager) |
| > Attention | John Doe | Recipient's name | |
| > First Name | John | Recipient's first name | |
| > Last Name | Doe | Recipient's last name | |
| > Company | Example Corp | Recipient's company | |
| > Custom1 | Customisable tracking and personalisation field | ||
| > Custom2 | Customisable tracking and personalisation field | ||
API URL: https://api.tnz.co.nz/api/v2.01/send/tts
HTTP Header: Content-Type="application/json; encoding='utf-8'"
{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"MessageToPeople": "Hello, this is a call from test. This is relevant information.",
"Destinations" :
[
{ "Recipient": "+6495005001" },
{ "Recipient": "+6495005002" }
]
}
}
{
"Result": "Success",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/tts
HTTP Header: Content-Type="application/json; encoding='utf-8'"
{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"MessageID": "ID123456",
"Reference": "Test1",
"WebhookCallbackURL": "https://www.example.com/webhook",
"WebhookCallbackFormat": "JSON",
"SendTime": "2021-08-01T09:00:00",
"TimeZone": "New Zealand",
"SubAccount": "SubAccount01",
"Department": "Department01",
"ChargeCode": "BillingGroup01",
"ReportTo": "report@example.com",
"RetryAttempts": 3,
"RetryPeriod": 1,
"MessageToPeople": "Hello, this is a call from Department01. This is relevant information. Press one to be connected to our call centre.",
"MessageToAnswerphones": "Hello, sorry we missed you. This is a call from Department 01. Please contact us on 0800 123123.",
"Keypads":
[
{
"Tone": "1",
"RouteNumber": "+64800123123"
},
{
"Tone": "2",
"Play": "You pressed Keypad 2",
"RouteNumber": "+6498008000"
}
],
"CallRouteMessageToPeople": "Connecting you now.",
"CallRouteMessageToOperators": "Incoming Text To Speech call.",
"CallRouteMessageOnWrongKey": "Sorry, you have pressed an invalid key. Please try again.",
"NumberOfOperators": 5,
"Voice": "Female1",
"Options": "",
"Destinations" :
[
{
"Recipient": "+6421000001",
"Attention": "John Doe",
"First Name": "John",
"Last Name": "Doe",
"Custom1": "",
"Custom2": ""
},
{ "Recipient": "+6495005002" },
{ "Recipient": "+6421000003" }
]
}
}
{
"Result": "Success",
"MessageID": "ID123456"
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/tts
HTTP Header: Content-Type="application/json; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/send/tts \
--header "Content-Type: application/json" \
--header "encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"MessageToPeople": "Hello, this is a call from test. This is relevant information.",
"Destinations" :
[
{ "Recipient": "+6495005001" },
{ "Recipient": "+6495005002" }
]
}
}'
{
"Result": "Success",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/tts
HTTP Header: Content-Type="application/json; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/send/tts \
--header "Content-Type: application/json" \
--header "encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"MessageID": "ID123456",
"Reference": "Test1",
"SendTime": "2021-08-01T09:00:00",
"TimeZone": "New Zealand",
"SubAccount": "SubAccount01",
"Department": "Department01",
"ChargeCode": "BillingGroup01",
"ReportTo": "report@example.com",
"MessageToPeople": "Hello, this is a call from Department01. This is relevant information. Press one to be connected to our call centre.",
"MessageToAnswerphones": "Hello, sorry we missed you. This is a call from Department 01. Please contact us on 0800 123123.",
"Keypads":
[
{
"Tone": "1",
"RouteNumber": "+64800123123"
},
{
"Tone": "2",
"Play": "You pressed Keypad 2",
"RouteNumber": "+6498008000"
}
],
"CallRouteMessageToPeople": "Connecting you now.",
"CallRouteMessageToOperators": "Incoming Text To Speech call.",
"CallRouteMessageOnWrongKey": "Sorry, you have pressed an invalid key. Please try again.",
"NumberOfOperators": "5",
"RetryAttempts": "3",
"RetryPeriod": "1",
"Voice": "Female1",
"Options": "",
"Destinations" :
[
{
"Recipient": "+6421000001",
"Attention": "John Doe",
"First Name": "John",
"Last Name": "Doe",
"Custom1": "",
"Custom2": ""
},
{ "Recipient": "+6495005002" },
{ "Recipient": "+6421000003" }
]
}
}'
{
"Result": "Success",
"MessageID": "ID123456"
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/tts
HTTP Header: Content-Type="application/json; encoding='utf-8'"
<?php
$data = array(
"Sender" => "application@domain.com",
"APIKey" => "ta8wr7ymd",
"MessageData" => array(
"MessageToPeople" => "Hello, this is a call from test. This is relevant information.",
"Destinations" => array(
array( "Recipient" => "+6495005001" ),
array( "Recipient" => "+6495005002" )
),
)
);
$headers = array(
"Content-Type: application/json",
"encoding='utf-8'",
"Content-length: ".strlen(json_encode($data)),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/send/tts");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header('Content-Type: application/json');
echo $response;
break;
case "400": // error
header('Content-Type: application/json');
echo $response;
break;
case "500": // critical error
echo $response."\n";
echo $err;
break;
default:
echo $response."\n";
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
{
"Result": "Success",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/tts
HTTP Header: Content-Type="application/json; encoding='utf-8'"
<?php
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$message_id = "ID123456"; // optional
$data = array(
"Sender" => $sender,
"APIKey" => $apikey,
"MessageData" => array(
"MessageID" => $message_id,
"Reference" => "Test1",
"SendTime" => "2021-08-01T09:00:00",
"TimeZone" => "New Zealand",
"SubAccount" => "SubAccount01",
"Department" => "Department01",
"ChargeCode" => "BillingGroup01",
"ReportTo" => "report@example.com",
"MessageToPeople" => "Hello, this is a call from Department01. This is relevant information. Press one to be connected to our call centre.",
"MessageToAnswerphones" => "Hello, sorry we missed you. This is a call from Department 01. Please contact us on 0800 123123.",
"Keypads" => array(
array(
"Tone" => 1,
"RouteNumber" => "+64800123123"
),
array(
"Tone" => 2,
"Play" => "You pressed Keypad 2",
"RouteNumber" => "+6498008000"
)
),
"CallRouteMessageToPeople" => "Connecting you now.",
"CallRouteMessageToOperators" => "Incoming Text To Speech call.",
"CallRouteMessageOnWrongKey" => "Sorry, you have pressed an invalid key. Please try again.",
"NumberOfOperators" => "5",
"RetryAttempts" => "3",
"RetryPeriod" => "1",
"Voice" => "Female1",
"Options" => "",
"Destinations" => array(
array(
"Recipient" => "+6421000001",
"Attention" => "John Doe",
"First Name" => "John",
"Last Name" => "Doe",
"Custom1" => "",
"Custom2" => ""
),
array( "Recipient" => "+6495005002" ),
array( "Recipient" => "+6495005003" )
),
)
);
$headers = array(
"Content-Type: application/json",
"encoding='utf-8'",
"Content-length: ".strlen(json_encode($data)),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/send/tts");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header('Content-Type: application/json');
echo $response;
break;
case "400": // error
header('Content-Type: application/json');
echo $response;
break;
case "500": // critical error
echo $response."\n";
echo $err;
break;
default:
echo $response."\n";
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
{
"Result": "Success",
"MessageID": "ID123456"
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/tts
HTTP Header: Content-Type="application/json; encoding='utf-8'"
using System;
using System.Text;
using System.IO;
using System.Net;
namespace TNZ
{
class Program
{
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/send/tts";
//
// Send TTS by REST API Interface
//
string strJSONData = @"{
""Sender"": ""application@domain.com"",
""APIKey"": ""ta8wr7ymd"",
""MessageData"": {
""MessageToPeople"": ""Hello, this is a call from test. This is relevant information."",
""Destinations"":
[
{ ""Recipient"": ""+6495005001"" },
{ ""Recipient"": ""+6495005002"" }
]
}
}";
//
// Send API Request to REST API
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/json; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
request.ContentLength = byteArray.Length;
Stream stream = request.GetRequestStream(); //open connection
stream.Write(byteArray, 0, byteArray.Length); // Send the data.
stream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
{
"Result": "Success",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/tts
HTTP Header: Content-Type="application/json; encoding='utf-8'"
using System;
using System.Text;
using System.IO;
using System.Net;
namespace TTSAdvanced
{
class Program
{
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/send/tts";
//
// Send TTS by REST API Interface
//
string strJSONData = $@"{{
""Sender"": ""application@domain.com"",
""APIKey"": ""ta8wr7ymd"",
""MessageData"": {{
""MessageID"": ""ID123456"",
""Reference"": ""Test1"",
""SendTime"": ""2021-08-01T09:00:00"",
""TimeZone"": ""New Zealand"",
""SubAccount"": ""SubAccount01"",
""Department"": ""Department01"",
""ChargeCode"": ""BillingGroup01"",
""ReportTo"": ""report@example.com"",
""MessageToPeople"": ""Hello, this is a call from Department01. This is relevant information. Press one to be connected to our call centre."",
""MessageToAnswerphones"": ""Hello, sorry we missed you. This is a call from Department 01. Please contact us on 0800 123123."",
""Keypads"":
[
{{
""Tone"": ""1"",
""RouteNumber"": ""+64800123123""
}},
{{
""Tone"": ""2"",
""Play"": ""You pressed Keypad 2"",
""RouteNumber"": ""+6498008000""
}}
],
""CallRouteMessageToPeople"": ""Connecting you now."",
""CallRouteMessageToOperators"": ""Incoming Text To Speech call."",
""CallRouteMessageOnWrongKey"": ""Sorry, you have pressed an invalid key. Please try again."",
""NumberOfOperators"": ""5"",
""RetryAttempts"": ""3"",
""RetryPeriod"": ""1"",
""Voice"": ""Female1"",
""Options"": """",
""Destinations"":
[
{{
""Recipient"": ""+6421000001"",
""Attention"": ""John Doe"",
""First Name"": ""John"",
""Last Name"": ""Doe"",
""Custom1"": """",
""Custom2"": """"
}},
{{ ""Recipient"" : ""+6495005002"" }},
{{ ""Recipient"" : ""+6421000003"" }}
]
}}
}}";
//
// Send API Request to REST API
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/json; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
request.ContentLength = byteArray.Length;
Stream stream = request.GetRequestStream(); //open connection
stream.Write(byteArray, 0, byteArray.Length); // Send the data.
stream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
{
"Result": "Success",
"MessageID": "ID123456"
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/tts
HTTP Header: Content-Type="application/json; encoding='utf-8'"
import requests
import json
url = "https://api.tnz.co.nz/api/v2.01/send/tts"
headers = {
"Content-Type": "application/json",
"encoding": "utf-8"
}
data = {
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"MessageToPeople": "Hello, this is a call from test. This is relevant information.",
"Destinations" :
[
{ "Recipient": "+6495005001" },
{ "Recipient": "+6495005002" }
]
}
}
r = requests.post(url, data=json.dumps(data), headers=headers)
print(r)
print(r.text)
{
"Result": "Success",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/tts
HTTP Header: Content-Type="application/json; encoding='utf-8'"
import requests
import json
url = "https://api.tnz.co.nz/api/v2.01/send/tts"
headers = {
"Content-Type": "application/json",
"encoding": "utf-8"
}
data = {
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageData" :
{
"MessageID": "ID123456",
"Reference": "Test1",
"SendTime": "2021-08-01T09:00:00",
"TimeZone": "New Zealand",
"SubAccount": "SubAccount01",
"Department": "Department01",
"ChargeCode": "BillingGroup01",
"ReportTo": "report@example.com",
"MessageToPeople": "Hello, this is a call from Department01. This is relevant information. Press one to be connected to our call centre.",
"MessageToAnswerphones": "Hello, sorry we missed you. This is a call from Department 01. Please contact us on 0800 123123.",
"Keypads":
[
{
"Tone": "1",
"RouteNumber": "+64800123123"
},
{
"Tone": "2",
"Play": "You pressed Keypad 2",
"RouteNumber": "+6498008000"
}
],
"CallRouteMessageToPeople": "Connecting you now.",
"CallRouteMessageToOperators": "Incoming Text To Speech call.",
"CallRouteMessageOnWrongKey": "Sorry, you have pressed an invalid key. Please try again.",
"NumberOfOperators": "5",
"RetryAttempts": "3",
"RetryPeriod": "1",
"Voice": "Female1",
"Options": "",
"Destinations" :
[
{
"Recipient": "+6421000001",
"Attention": "John Doe",
"First Name": "John",
"Last Name": "Doe",
"Custom1": "",
"Custom2": ""
},
{ "Recipient": "+6495005002" },
{ "Recipient": "+6421000003" }
]
}
}
r = requests.post(url, data=json.dumps(data), headers=headers)
print(r)
print(r.text)
{
"Result": "Success",
"MessageID": "ID123456"
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/send/tts
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?xml version="1.0" encoding="UTF-8"?>
<TTSRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageData>
<MessageToPeople>Hello, this is a call from test. This is relevant information.</MessageToPeople>
<Destinations>
<Destination><Recipient>+6495005001</Recipient></Destination>
<Destination><Recipient>+6495005002</Recipient></Destination>
</Destinations>
</MessageData>
</TTSRequest>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/tts
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?xml version="1.0" encoding="UTF-8"?>
<TTSRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageData>
<MessageID>ID123456</MessageID>
<Reference>Test1</Reference>
<SendTime>2021-08-01T09:00:00</SendTime>
<TimeZone>New Zealand</TimeZone>
<SubAccount>SubAccount01</SubAccount>
<Department>Department01</Department>
<ChargeCode>BillingGroup01</ChargeCode>
<ReportTo>report@example.com</ReportTo>
<MessageToPeople>Hello, this is a call from Department01. This is relevant information. Press one to be connected to our call centre.</MessageToPeople>
<MessageToAnswerphones>Hello, sorry we missed you. This is a call from Department 01. Please contact us on 0800 123123.</MessageToAnswerphones>
<Keypads>
<Keypad>
<Tone>1</Tone>
<RouteNumber>+64800123123</RouteNumber>
</Keypad>
<Keypad>
<Tone>2</Tone>
<Play>You pressed Keypad 2</Play>
<RouteNumber>+6498008000</RouteNumber>
</Keypad>
</Keypads>
<CallRouteMessageToPeople>Connecting you now.</CallRouteMessageToPeople>
<CallRouteMessageToOperators>Incoming Text To Speech call.</CallRouteMessageToOperators>
<CallRouteMessageOnWrongKey>Sorry, you have pressed an invalid key. Please try again.</CallRouteMessageOnWrongKey>
<NumberOfOperators>5</NumberOfOperators>
<RetryAttempts>3</RetryAttempts>
<RetryPeriod>1</RetryPeriod>
<Voice>Female1</Voice>
<Options></Options>
<Destinations>
<Destination>
<Recipient>+6421000001</Recipient>
<Attention>John Doe</Attention>
<FirstName>John</FirstName>
<LastName>Doe</LastName>
<Company>Example Corp</Company>
<Custom1></Custom1>
<Custom2></Custom2>
</Destination>
<Destination><Recipient>+6495005002</Recipient></Destination>
<Destination><Recipient>+6421000003</Recipient></Destination>
</Destinations>
</MessageData>
</TTSRequest>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/tts
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/send/tts \
--header "Content-Type: text/xml" \
--header "Accept: text/xml" \
--header "encoding='utf-8'" \
--data '<?xml version="1.0" encoding="UTF-8"?>
<TTSRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageData>
<MessageToPeople>Hello, this is a call from test. This is relevant information.</MessageToPeople>
<Destinations>
<Destination><Recipient>+6495005001</Recipient></Destination>
<Destination><Recipient>+6495005002</Recipient></Destination>
</Destinations>
</MessageData>
</TTSRequest>'
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/tts
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/send/tts \
--header "Content-Type: text/xml" \
--header "Accept: text/xml" \
--header "encoding='utf-8'" \
--data '<?xml version="1.0" encoding="UTF-8"?>
<TTSRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageData>
<MessageID>ID123456</MessageID>
<Reference>Test1</Reference>
<SendTime>2021-08-01T09:00:00</SendTime>
<TimeZone>New Zealand</TimeZone>
<SubAccount>SubAccount01</SubAccount>
<Department>Department01</Department>
<ChargeCode>BillingGroup01</ChargeCode>
<ReportTo>report@example.com</ReportTo>
<MessageToPeople>Hello, this is a call from Department01. This is relevant information. Press one to be connected to our call centre.</MessageToPeople>
<MessageToAnswerphones>Hello, sorry we missed you. This is a call from Department 01. Please contact us on 0800 123123.</MessageToAnswerphones>
<Keypads>
<Keypad>
<Tone>1</Tone>
<RouteNumber>+64800123123</RouteNumber>
</Keypad>
<Keypad>
<Tone>2</Tone>
<Play>You pressed Keypad 2</Play>
<RouteNumber>+6498008000</RouteNumber>
</Keypad>
</Keypads>
<CallRouteMessageToPeople>Connecting you now.</CallRouteMessageToPeople>
<CallRouteMessageToOperators>Incoming Text To Speech call.</CallRouteMessageToOperators>
<CallRouteMessageOnWrongKey>Sorry, you have pressed an invalid key. Please try again.</CallRouteMessageOnWrongKey>
<NumberOfOperators>5</NumberOfOperators>
<RetryAttempts>5</RetryAttempts>
<RetryPeriod>5</RetryPeriod>
<Voice>Female1</Voice>
<Options></Options>
<Destinations>
<Destination>
<Recipient>+6421000001</Recipient>
<Attention>John Doe</Attention>
<FirstName>John</FirstName>
<LastName>Doe</LastName>
<Company>Example Corp</Company>
<Custom1></Custom1>
<Custom2></Custom2>
</Destination>
<Destination><Recipient>+6495005002</Recipient></Destination>
<Destination><Recipient>+6421000003</Recipient></Destination>
</Destinations>
</MessageData>
</TTSRequest>'
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/tts
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?php
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><TTSRequest></TTSRequest>");
$data->addChild("Sender",$sender);
$data->addChild("APIKey",$apikey);
$data->addChild("MessageData");
$data->MessageData->addChild("MessageToPeople","Hello, this is a call from test. This is relevant information.");
$destinations = $data->MessageData->addChild("Destinations");
$destination1 = $destinations->addChild("Destination");
$destination1->addChild("Recipient","+6495005001");
$destination2 = $destinations->addChild("Destination");
$destination2->addChild("Recipient","+6495005002");
$headers = array(
"Content-Type: text/xml",
"Accept: text/xml",
"encoding='utf-8'",
"Content-length: ".strlen($data->asXML()),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/send/tts");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "400": // error
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "500": // critical error
echo $response."\n";
echo $err;
break;
default:
echo $response."\n";
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/tts
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?php
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$message_id = "ID123456";
$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><TTSRequest></TTSRequest>");
$data->addChild("Sender",$sender);
$data->addChild("APIKey",$apikey);
$data->addChild("MessageData");
$data->MessageData->addChild("MessageID",$message_id);
$data->MessageData->addChild("Reference","Test1");
$data->MessageData->addChild("WebhookCallbackURL","https://www.example.com/webhook");
$data->MessageData->addChild("WebhookCallbackFormat","XML");
$data->MessageData->addChild("SendTime","2021-08-01T09:00:00");
$data->MessageData->addChild("TimeZone","New Zealand");
$data->MessageData->addChild("SubAccount","SubAccount01");
$data->MessageData->addChild("Department","Department01");
$data->MessageData->addChild("ChargeCode","BillingGroup01");
$data->MessageData->addChild("ReportTo","report@example.com");
$data->MessageData->addChild("MessageToPeople","Hello, this is a call from Department01. This is relevant information. Press one to be connected to our call centre.");
$data->MessageData->addChild("MessageToAnswerphones","Hello, sorry we missed you. This is a call from Department 01. Please contact us on 0800 123123.");
$keypads = $data->MessageData->addChild("Keypads");
$keypad = $keypads->addChild("Keypad");
$keypad->addChild("Tone",1);
$keypad->addChild("RouteNumber","+64800123123");
$keypad = $keypads->addChild("Keypad");
$keypad->addChild("Tone",2);
$keypad->addChild("Play","You pressed Keypad 2");
$keypad->addChild("RouteNumber","+6498008000");
$data->MessageData->addChild("CallRouteMessageToPeople","Connecting you now.");
$data->MessageData->addChild("CallRouteMessageToOperators","Incoming Text To Speech call.");
$data->MessageData->addChild("CallRouteMessageOnWrongKey","Sorry, you have pressed an invalid key. Please try again.");
$data->MessageData->addChild("NumberOfOperators",5);
$data->MessageData->addChild("RetryAttempts",3);
$data->MessageData->addChild("RetryPeriod",1);
$data->MessageData->addChild("Voice","Female1");
$data->MessageData->addChild("Options","");
$destinations = $data->MessageData->addChild("Destinations");
$destination = $destinations->addChild("Destination");
$destination->addChild("Recipient","+6421000001");
$destination->addChild("Attention","John Doe");
$destination->addChild("FirstName","John");
$destination->addChild("LastName","Doe");
$destination->addChild("Company","Example Corp");
$destination->addChild("Custom1","");
$destination->addChild("Custom2","");
$destination = $destinations->addChild("Destination");
$destination->addChild("Recipient","+6495005002");
$destination = $destinations->addChild("Destination");
$destination->addChild("Recipient","+6421000003");
$destination = $destinations->addChild("Destination");
$destination->addChild("Recipient","+6422000004");
$headers = array(
"Content-Type: text/xml",
"Accept: text/xml",
"encoding='utf-8'",
"Content-length: ".strlen($data->asXML()),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/send/tts");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "400": // error
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "500": // critical error
echo $response."\n";
echo $err;
break;
default:
echo $response."\n";
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/tts
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
using System;
using System.Text;
using System.Xml;
using System.IO;
using System.Net;
namespace TTSSimple
{
class Program
{
private static XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerText = val;
return workingNode;
}
static void Main(string[] args)
{
//
// Populating values from frmMain
//
string apiURL = "https://api.tnz.co.nz/api/v2.01/send/tts";
//
// Send TTS by XML API Interface
//
XmlDocument xmlDoc = new XmlDocument();
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null); // <?xml version="1.0" encoding="UTF-8"?>
xmlDoc.AppendChild(docNode);
XmlNode rootNode = xmlDoc.CreateElement("TTSRequest");
xmlDoc.AppendChild(rootNode);
rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com"));
rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd"));
XmlNode workingNode = xmlDoc.CreateElement("Sender");
//
// MessageData
//
XmlNode messageDataNode = xmlDoc.CreateElement("MessageData");
messageDataNode.AppendChild(addChildNode(xmlDoc, "MessageToPeople", "Hello, this is a call from test. This is relevant information."));
workingNode = xmlDoc.CreateElement("Destinations");
//
// Add Destinations 1 - Add with details
//
XmlNode destNode1 = xmlDoc.CreateElement("Destination");
destNode1.AppendChild(addChildNode(xmlDoc, "Recipient", "+6495005001"));
workingNode.AppendChild(destNode1);
//
// Add Destinations 2 - Add with details
//
XmlNode destNode2 = xmlDoc.CreateElement("Destination");
destNode2.AppendChild(addChildNode(xmlDoc, "Recipient", "+6495005002"));
//
// Set MessageData into root node
//
rootNode.AppendChild(messageDataNode);
//
// Send API Request to REST API
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "text/xml; encoding='utf-8'";
request.Accept = "text/xml; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
request.ContentLength = byteArray.Length;
Stream stream = request.GetRequestStream(); //open connection
stream.Write(byteArray, 0, byteArray.Length); // Send the data.
stream.Close();
string strResponse = "";
HttpWebResponse getResponse = (HttpWebResponse)request.GetResponse();
using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
{
strResponse = sr.ReadToEnd();
}
Console.WriteLine(strResponse);
}
}
}
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/tts
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
using System;
using System.Text;
using System.Xml;
using System.IO;
using System.Net;
namespace TTSAdvanced
{
class Program
{
private static XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerText = val;
return workingNode;
}
static void Main(string[] args)
{
//
// Populating values from frmMain
//
string apiURL = "https://api.tnz.co.nz/api/v2.01/send/tts";
//
// Send TTS by XML API Interface
//
XmlDocument xmlDoc = new XmlDocument();
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null); // <?xml version="1.0" encoding="UTF-8"?>
xmlDoc.AppendChild(docNode);
XmlNode rootNode = xmlDoc.CreateElement("TTSRequest");
xmlDoc.AppendChild(rootNode);
rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com"));
rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd"));
XmlNode workingNode = xmlDoc.CreateElement("Sender");
//
// MessageData
//
XmlNode messageDataNode = xmlDoc.CreateElement("MessageData");
messageDataNode.AppendChild(addChildNode(xmlDoc, "MessageID", "ID123456"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "Reference", "Test1"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "SendTime", DateTime.Now.ToString("yyyy-MM-ddThh:mm:ss")));
messageDataNode.AppendChild(addChildNode(xmlDoc, "TimeZone", "New Zealand"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "SubAccount", "SubAccount01"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "Department", "Department01"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "ChargeCode", "BillingGroup01"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "ReportTo", "report@example.com"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "MessageToPeople", "Hello, this is a call from Department01. This is relevant information. Press one to be connected to our call centre."));
messageDataNode.AppendChild(addChildNode(xmlDoc, "MessageToAnswerphones", "Hello, sorry we missed you. This is a call from Department 01. Please contact us on 0800 123123."));
//
// Add Keypad 1 - RouteNumber
//
workingNode = xmlDoc.CreateElement("Keypads");
XmlNode keypadNode1 = xmlDoc.CreateElement("Keypad");
keypadNode1.AppendChild(addChildNode(xmlDoc, "Tone", "1"));
keypadNode1.AppendChild(addChildNode(xmlDoc, "RouteNumber", "+64800123123"));
workingNode.AppendChild(keypadNode1);
//
// Add Keypad 2 - RouteNumber + Play
//
XmlNode keypadNode2 = xmlDoc.CreateElement("Keypad");
keypadNode2.AppendChild(addChildNode(xmlDoc, "Tone", "2"));
keypadNode2.AppendChild(addChildNode(xmlDoc, "Play", "You pressed Keypad 2"));
keypadNode2.AppendChild(addChildNode(xmlDoc, "RouteNumber", "+6498008000"));
workingNode.AppendChild(keypadNode2);
messageDataNode.AppendChild(workingNode);
messageDataNode.AppendChild(addChildNode(xmlDoc, "CallRouteMessageToPeople", "Connecting you now."));
messageDataNode.AppendChild(addChildNode(xmlDoc, "CallRouteMessageToOperators", "Incoming Text To Speech call."));
messageDataNode.AppendChild(addChildNode(xmlDoc, "CallRouteMessageOnWrongKey", "Sorry, you have pressed an invalid key. Please try again."));
messageDataNode.AppendChild(addChildNode(xmlDoc, "Voice", "Female1"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "Options", ""));
messageDataNode.AppendChild(addChildNode(xmlDoc, "NumberOfOperators", "5"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "RetryAttempts", "3"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "RetryPeriod", "1"));
//
// Add Destinations 1 - Add with details
//
workingNode = xmlDoc.CreateElement("Destinations");
workingNode.AppendChild(addChildNode(xmlDoc, "Recipient", "+6421000001"));
workingNode.AppendChild(addChildNode(xmlDoc, "Attention", "John Doe"));
workingNode.AppendChild(addChildNode(xmlDoc, "FirstName", "John"));
workingNode.AppendChild(addChildNode(xmlDoc, "LastName", "Doe"));
workingNode.AppendChild(addChildNode(xmlDoc, "Custom1", "Custom1"));
workingNode.AppendChild(addChildNode(xmlDoc, "Custom2", "Custom2"));
messageDataNode.AppendChild(workingNode);
//
// Add Destinations 2 - Add numbers only
//
messageDataNode.AppendChild(addChildNode(xmlDoc, "Destinations", "+6495005002"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "Destinations", "+6421000003"));
//
// Set MessageData into root node
//
rootNode.AppendChild(messageDataNode);
//
// Send API Request to REST API
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "text/xml; encoding='utf-8'";
request.Accept = "text/xml; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
request.ContentLength = byteArray.Length;
Stream stream = request.GetRequestStream(); //open connection
stream.Write(byteArray, 0, byteArray.Length); // Send the data.
stream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
}
}
}
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/tts
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
import requests
import xml.etree.ElementTree as ET
url = "https://api.tnz.co.nz/api/v2.01/send/tts"
headers = {
"Content-Type": "text/xml",
"Accept": "text/xml",
"encoding": "utf-8"
}
root = ET.Element('TTSRequest')
ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
message_data = ET.SubElement(root,"MessageData")
ET.SubElement(message_data, "MessageToPeople").text = "Hello, this is a call from test. This is relevant information."
destinations = ET.SubElement(message_data,"Destinations")
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination, "Recipient").text = "+6495005001"
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination, "Recipient").text = "+6421000002"
r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)
print(r)
print(r.text)
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/send/tts
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
import requests
import xml.etree.ElementTree as ET
url = "https://api.tnz.co.nz/api/v2.01/send/tts"
headers = {
"Content-Type": "text/xml",
"Accept": "text/xml",
"encoding": "utf-8"
}
root = ET.Element('TTSRequest')
ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
message_data = ET.SubElement(root,"MessageData")
ET.SubElement(message_data, "MessageID").text = "ID123456"
ET.SubElement(message_data, "Reference").text = "Test1"
ET.SubElement(message_data, "SendTime").text = "2021-08-01T09:00:00"
ET.SubElement(message_data, "TimeZone").text = "New Zealand"
ET.SubElement(message_data, "SubAccount").text = "SubAccount01"
ET.SubElement(message_data, "Department").text = "Department01"
ET.SubElement(message_data, "ChargeCode").text = "BillingGroup01"
ET.SubElement(message_data, "ReportTo").text = "report@example.com"
ET.SubElement(message_data, "MessageToPeople").text = "Hello, this is a call from Department01. This is relevant information. Press one to be connected to our call centre."
ET.SubElement(message_data, "MessageToAnswerphones").text = "Hello, sorry we missed you. This is a call from Department 01. Please contact us on 0800 123123."
keypads = ET.SubElement(message_data,"Keypads")
keypad = ET.SubElement(keypads,"Keypad")
ET.SubElement(keypad,"Tone").text = "1"
ET.SubElement(keypad,"RouteNumber").text = "+64800123123"
keypad = ET.SubElement(keypads,"Keypad")
ET.SubElement(keypad,"Tone").text = "2"
ET.SubElement(keypad,"Play").text = "You pressed Keypad 2"
ET.SubElement(keypad,"RouteNumber").text = "+6498008000"
ET.SubElement(message_data, "CallRouteMessageToPeople").text = "Connecting you now."
ET.SubElement(message_data, "CallRouteMessageToOperators").text = "Incoming Text To Speech call."
ET.SubElement(message_data, "CallRouteMessageOnWrongKey").text = "Sorry, you have pressed an invalid key. Please try again."
ET.SubElement(message_data, "NumberOfOperators").text = "5"
ET.SubElement(message_data, "RetryAttempts").text = "3"
ET.SubElement(message_data, "RetryPeriod").text = "1"
ET.SubElement(message_data, "Voice").text = "Female1"
ET.SubElement(message_data, "Options").text = ""
destinations = ET.SubElement(message_data,"Destinations")
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination,"Recipient").text = "+6421000001"
ET.SubElement(destination,"Attention").text = "John Doe"
ET.SubElement(destination,"FirstName").text = "John"
ET.SubElement(destination,"LastName").text = "Doe"
ET.SubElement(destination,"Company").text = "Example Corp"
ET.SubElement(destination,"Custom1").text = ""
ET.SubElement(destination,"Custom2").text = ""
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination, "Recipient").text = "+6495005002"
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination, "Recipient").text = "+6421000003"
destination = ET.SubElement(destinations,"Destination")
ET.SubElement(destination, "Recipient").text = "+6495005004"
r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)
print(r)
print(r.text)
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
| Parameter | Example Value | Description | |
|---|---|---|---|
| MessageToPeople | Hello, this is a call from Department01. This is relevant information. Press one to be connected to our call centre. | The text-to-speech message played if the call is answered by a human (may optionally include SSML commands) | |
| Destinations | > Recipient | +6495005001 +6495005002 +6495005003 |
Telephone number(s) to receive the message (for detailed formatting, see the Destinations parameter below) |
| Parameter | Example Value | Description | |
|---|---|---|---|
| MessageID | ID123456 | A message tracking identifier (maximum 40 characters, alphanumeric). If you do not supply this field, the API will return one for you in the response body (UUID v4 of 36 characters) | |
| Reference | Test1 | Tracking ID or message description | |
| WebhookCallbackURL | https://www.example.com/webhook | Overrides your Sender's default Webhook URL. Requires a default webhook to be configured. A full path including https:// is required. | |
| WebhookCallbackFormat | JSON | Overrides your Sender's default Webhook format ('JSON' or 'XML') | |
| SendTime | 2021-12-31T23:00 | Delay sending until the specified date/time, a single point of time in a combined date and time representation ({date}T{time}; for example, 2017-08-29T04:00 in your local timezone, specified by your Sender setting or overridden using the TimeZone command). | |
| TimeZone | New Zealand | User's local timezone (see Setting Timezones) | |
| SubAccount | SubAccount01 | Used for reporting, billing and Web Dashboard segmentation. See the TNZ API Structure guide's Cost Tracking & Rebilling section. | |
| Department | Department01 | Used for reporting, billing and Web Dashboard segmentation. See the TNZ API Structure guide's Cost Tracking & Rebilling section. | |
| ChargeCode | BillingGroup01 | Bespoke app cost allocation code (for invoice segmentation) | |
| ReportTo | report@example.com | For email (SMTP) message delivery report notifications. | |
| MessageToAnswerphones | Hello, sorry we missed you. This is a call from Department 01. Please contact us on 0800 123123. | The text-to-speech message played when the call is answered by an answering machine/voicemail service (may optionally include SSML commands) | |
| Keypads | > Tone | 1 | Keypad for call connection (supports buttons 1-9) |
| > RouteNumber | +64800123123 | Telephone number for call routing in dialling format | |
| > Play | You pressed Keypad 1 | Message played to B-Party when a keypad option is pressed | |
| CallRouteMessageToPeople | Connecting you now. | Text-to-speech message played when a keypad option is pressed | |
| CallRouteMessageToOperators | Incoming Text To Speech call. | Text-to-speech message played to the call centre representative answering the connected call | |
| CallRouteMessageOnWrongKey | Sorry, you have pressed an invalid key. Please try again. | Text-to-speech message played when an unregistered keypad button is pressed | |
| NumberOfOperators | 5 | Limits the maximum simultaneous calls (where multiple 'Destinations' are listed) | |
| RetryAttempts | 3 | Number of retry attempts if the recipients line is busy or unavailable | |
| RetryPeriod | 1 | Minutes apart when performing retries | |
| CallerID | +6495005000 | Sets the Caller ID used on the call (must be E.164 format) | |
| Voice | Female1 | Text-to-Speech voice to use (Male1, Female1, Nicole, Russell, Amy, Brian, Emma) | |
| Options | Customisable field that allows advanced voice options including recording survey responses, recording phone numbers, playing IVR options, capturing DTMF tones for account numbers or credit card numbers, etc. | ||
| Destinations | > Recipient | +6495005000 | Recipient of the call in E.164 internationalised format (for localized or friendly formatting, contact your account manager) |
| > Attention | John Doe | Recipient's name | |
| > First Name | John | Recipient's first name | |
| > Last Name | Doe | Recipient's last name | |
| > Company | Example Corp | Recipient's company | |
| > Custom1 | Customisable tracking and personalisation field | ||
| > Custom2 | Customisable tracking and personalisation field | ||
Under MessageData you can specify an additional Mode=Test parameter.
Mode=Test means any messages will be handled by the API, instantly called a SUCCESS and the success report will be delivered to you. This is a useful way to end-to-end test without sending a live message.
...
"MessageData" :
{
...
"Mode": "Test"
}
...
Once a message has been sent, you can retry a failed message, reschedule a delayed message, abort a delayed message and edit the NumberOfOperators value on Voice/TTS messages.
If your message is 'Failed' (sending completed and was unsuccessful), you can use this API module to retry sending.
The Retry is applied to a specific MessageID. If you use common MessageID values across multiple messages, it will apply to the most recent message and only if the Status was Failed.
API URL: https://api.tnz.co.nz/api/v2.01/set/resubmit
HTTP Header: Content-Type="application/json; encoding='utf-8'"
{
"Sender":"application@domain.com",
"APIKey":"ta8wr7ymd",
"MessageID":"ID123456",
"SendTime":"2021-08-01T09:00:00" // optional
}
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Transmit",
"JobNum": "ABCD1234",
"Action": "Resubmit"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/resubmit
HTTP Header: Content-Type="application/json; encoding='utf-8'"
{
"Sender":"application@domain.com",
"APIKey":"ta8wr7ymd",
"MessageID":"ID123456",
"SendTime":"2021-08-01T09:00:00" // optional
}
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Transmit",
"JobNum": "ABCD1234",
"Action": "Resubmit"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/resubmit
HTTP Header: Content-Type="application/json; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/set/resubmit \
--header "Content-Type: application/json; encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageID": "ID123456",
"SendTime": "2021-08-01 09:00:00" // Optional
}'
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Transmit",
"JobNum": "ABCD1234",
"Action": "Resubmit"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/resubmit
HTTP Header: Content-Type="application/json; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/set/resubmit \
--header "Content-Type: application/json; encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageID": "ID123456",
"SendTime": "2021-08-01 09:00:00" // Optional
}'
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Transmit",
"JobNum": "ABCD1234",
"Action": "Resubmit"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/resubmit
HTTP Header: Content-Type="application/json; encoding='utf-8'"
<?php
$data = array(
"Sender" => "application@domain.com", // required
"APIKey" => "ta8wr7ymd", // required
"MessageID" => "ID123456", // required
"SendTime" => "2021-08-01 09:00:00", // optional
);
$headers = array(
"Content-Type: application/json",
"encoding='utf-8'",
"Content-length: ".strlen(json_encode($data)),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/set/resubmit");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header('Content-Type: application/json');
echo $response;
break;
case "400": // error
header('Content-Type: application/json');
echo $response;
break;
case "500": // critical error
echo $response;
echo $err;
break;
default:
echo $response;
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Transmit",
"JobNum": "ABCD1234",
"Action": "Resubmit"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/resubmit
HTTP Header: Content-Type="application/json; encoding='utf-8'"
<?php
$data = array(
"Sender" => "application@domain.com", // required
"APIKey" => "ta8wr7ymd", // required
"MessageID" => "ID123456", // required
"SendTime" => "2021-08-01 09:00:00", // optional
);
$headers = array(
"Content-Type: application/json",
"encoding='utf-8'",
"Content-length: ".strlen(json_encode($data)),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/set/resubmit");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header('Content-Type: application/json');
echo $response;
break;
case "400": // error
header('Content-Type: application/json');
echo $response;
break;
case "500": // critical error
echo $response;
echo $err;
break;
default:
echo $response;
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Transmit",
"JobNum": "ABCD1234",
"Action": "Resubmit"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/resubmit
HTTP Header: Content-Type="application/json; encoding='utf-8'"
using System;
using System.Text;
using System.IO;
using System.Net;
namespace TNZ
{
class Program
{
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/set/resubmit";
//
// Send TTS by REST API Interface
//
string strJSONData = $@"{{
""Sender"": ""application@domain.com"",
""APIKey"": ""ta8wr7ymd"",
""MessageID"": ""ID123456"",
""SendTime"": ""2021-08-01 09:00:00"" // Send Time (Your local date/time) - Optional
}}";
//
// Send API Request to REST API
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/json; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
request.ContentLength = byteArray.Length;
Stream stream = request.GetRequestStream(); //open connection
stream.Write(byteArray, 0, byteArray.Length); // Send the data.
stream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Transmit",
"JobNum": "ABCD1234",
"Action": "Resubmit"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/resubmit
HTTP Header: Content-Type="application/json; encoding='utf-8'"
using System;
using System.Text;
using System.IO;
using System.Net;
namespace TNZ
{
class Program
{
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/set/resubmit";
//
// Send TTS by REST API Interface
//
string strJSONData = $@"{{
""Sender"": ""application@domain.com"",
""APIKey"": ""ta8wr7ymd"",
""MessageID"": ""ID123456"",
""SendTime"": ""2021-08-01 09:00:00"" // Send Time (Your local date/time) - Optional
}}";
//
// Send API Request to REST API
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/json; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
request.ContentLength = byteArray.Length;
Stream stream = request.GetRequestStream(); //open connection
stream.Write(byteArray, 0, byteArray.Length); // Send the data.
stream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Transmit",
"JobNum": "ABCD1234",
"Action": "Resubmit"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/resubmit
HTTP Header: Content-Type="application/json; encoding='utf-8'"
import requests
import json
url = "https://api.tnz.co.nz/api/v2.01/set/resubmit"
headers = {
"Content-Type": "application/json",
"encoding": "utf-8"
}
data = {
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageID" : "ID123456",
"SendTime": "2021-08-01 09:00:00" #optional
}
r = requests.post(url, data=json.dumps(data), headers=headers)
print(r)
print(r.text)
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Transmit",
"JobNum": "ABCD1234",
"Action": "Resubmit"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/resubmit
HTTP Header: Content-Type="application/json; encoding='utf-8'"
import requests
import json
url = "https://api.tnz.co.nz/api/v2.01/set/resubmit"
headers = {
"Content-Type": "application/json",
"encoding": "utf-8"
}
data = {
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageID" : "ID123456",
"SendTime": "2021-08-01 09:00:00" #optional
}
r = requests.post(url, data=json.dumps(data), headers=headers)
print(r)
print(r.text)
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Transmit",
"JobNum": "ABCD1234",
"Action": "Resubmit"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/resubmit
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?xml version="1.0" encoding="UTF-8"?>
<ResubmitRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageID>ID123456</MessageID>
<SendTime>2021-08-01T09:00:00</MessageID> <!-- Optional -->
</ResubmitRequest>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Transmit</Status>
<JobNum>ABCD1234</JobNum>
<Action>Resubmit</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/resubmit
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?xml version="1.0" encoding="UTF-8"?>
<ResubmitRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageID>ID123456</MessageID>
<SendTime>2021-08-01T09:00:00</MessageID> <!-- Optional -->
</ResubmitRequest>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Transmit</Status>
<JobNum>ABCD1234</JobNum>
<Action>Resubmit</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/resubmit
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/set/resubmit \
--header "Content-Type: text/xml; encoding='utf-8'" "Accept: text/xml; encoding='utf-8'" \
--data '
<?xml version="1.0" encoding="UTF-8"?>
<root>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageID>ID123456</MessageID>
<SendTime>2021-08-01 09:00:00</SendTime>
</root>
'
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Transmit</Status>
<JobNum>ABCD1234</JobNum>
<Action>Resubmit</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/resubmit
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/set/resubmit \
--header "Content-Type: text/xml; encoding='utf-8'" "Accept: text/xml; encoding='utf-8'" \
--data '
<?xml version="1.0" encoding="UTF-8"?>
<root>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageID>ID123456</MessageID>
<SendTime>2021-08-01 09:00:00</SendTime>
</root>
'
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Transmit</Status>
<JobNum>ABCD1234</JobNum>
<Action>Resubmit</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/resubmit
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?php
$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><ResubmitRequest></ResubmitRequest>");
$data->addChild("Sender","application@domain.com"); // required
$data->addChild("APIKey","ta8wr7ymd"); // required
$data->addChild("MessageID","ID123456"); // required
$data->addChild("SendTime","2021-08-01 09:00:00"); // optional
$headers = array(
"Content-Type: text/xml",
"Accept: text/xml",
"encoding='utf-8'",
"Content-length: ".strlen($data->asXML()),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/set/resubmit");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "400": // error
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "500": // critical error
echo $response."\n";
echo $err;
break;
default:
echo $response."\n";
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Transmit</Status>
<JobNum>ABCD1234</JobNum>
<Action>Resubmit</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/resubmit
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?php
$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><ResubmitRequest></ResubmitRequest>");
$data->addChild("Sender","application@domain.com"); // required
$data->addChild("APIKey","ta8wr7ymd"); // required
$data->addChild("MessageID","ID123456"); // required
$data->addChild("SendTime","2021-08-01 09:00:00"); // optional
$headers = array(
"Content-Type: text/xml",
"Accept: text/xml",
"encoding='utf-8'",
"Content-length: ".strlen($data->asXML()),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/set/resubmit");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "400": // error
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "500": // critical error
echo $response."\n";
echo $err;
break;
default:
echo $response."\n";
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Transmit</Status>
<JobNum>ABCD1234</JobNum>
<Action>Resubmit</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/resubmit
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
namespace SetResubmit
{
class Program
{
private static XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerText = val;
return workingNode;
}
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/set/resubmit";
XmlDocument xmlDoc = new XmlDocument();
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null); // <?xml version="1.0" encoding="UTF-8"?>
xmlDoc.AppendChild(docNode);
XmlNode rootNode = xmlDoc.CreateElement("ResubmitRequest");
xmlDoc.AppendChild(rootNode);
rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com")); // required
rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd")); // required
rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", "ID123456")); // required
rootNode.AppendChild(addChildNode(xmlDoc, "SendTime", "2021-08-01T09:00:00")); // optional
//
// Send Raw XML Request
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "text/xml; encoding='utf-8'";
request.Accept = "text/xml; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
request.ContentLength = byteArray.Length;
Stream newStream = request.GetRequestStream(); //open connection
newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
newStream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Transmit</Status>
<JobNum>ABCD1234</JobNum>
<Action>Resubmit</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/resubmit
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
namespace SetResubmit
{
class Program
{
private static XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerText = val;
return workingNode;
}
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/set/resubmit";
XmlDocument xmlDoc = new XmlDocument();
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null); // <?xml version="1.0" encoding="UTF-8"?>
xmlDoc.AppendChild(docNode);
XmlNode rootNode = xmlDoc.CreateElement("ResubmitRequest");
xmlDoc.AppendChild(rootNode);
rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com")); // required
rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd")); // required
rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", "ID123456")); // required
rootNode.AppendChild(addChildNode(xmlDoc, "SendTime", "2021-08-01T09:00:00")); // optional
//
// Send Raw XML Request
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "text/xml; encoding='utf-8'";
request.Accept = "text/xml; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
request.ContentLength = byteArray.Length;
Stream newStream = request.GetRequestStream(); //open connection
newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
newStream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Transmit</Status>
<JobNum>ABCD1234</JobNum>
<Action>Resubmit</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/resubmit
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
import requests
import xml.etree.ElementTree as ET
url = "https://api.tnz.co.nz/api/v2.01/set/resubmit"
headers = {
"Content-Type": "text/xml",
"Accept": "text/xml",
"encoding": "utf-8"
}
root = ET.Element('ResubmitRequest')
ET.SubElement(root, "Sender").text = "application@domain.com" #required
ET.SubElement(root, "APIKey").text = "ta8wr7ymd" #required
ET.SubElement(root, "MessageID").text = "ID123456" #required
ET.SubElement(root, "SendTime").text = "2021-08-01 09:00:00" #optional
r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)
print(r)
print(r.text)
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Transmit</Status>
<JobNum>ABCD1234</JobNum>
<Action>Resubmit</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/resubmit
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
import requests
import xml.etree.ElementTree as ET
url = "https://api.tnz.co.nz/api/v2.01/set/resubmit"
headers = {
"Content-Type": "text/xml",
"Accept": "text/xml",
"encoding": "utf-8"
}
root = ET.Element('ResubmitRequest')
ET.SubElement(root, "Sender").text = "application@domain.com" #required
ET.SubElement(root, "APIKey").text = "ta8wr7ymd" #required
ET.SubElement(root, "MessageID").text = "ID123456" #required
ET.SubElement(root, "SendTime").text = "2021-08-01 09:00:00" #optional
r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)
print(r)
print(r.text)
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Transmit</Status>
<JobNum>ABCD1234</JobNum>
<Action>Resubmit</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</ErrorMessage>
</root>
| Parameter | Example Value | Description | |
|---|---|---|---|
| Sender | application@domain.com | Sender value set up in Create a new API user token | |
| APIKey | ta8wr7ymd | APIKey value set up in Create a new API user token | |
| MessageID | ID123456 | MessageID the Action should apply to | |
| SendTime (Optional) | 2021-12-31T23:00 | Delay sending until the specified date/time, a single point of time in a combined date and time representation ({date}T{time}; for example, 2017-08-29T04:00 in your local timezone, specified by your Sender setting or overridden using the TimeZone command). | |
| Parameter | Example Value | Description | |
|---|---|---|---|
| Result | Success | Result of your API call (not the result of the message) | |
| MessageID | ID123456 | MessageID the Action was applied to | |
| Status | Transmit | State of the message prior to performing the Action ('Transmit', 'Pending', 'Delayed', 'CreditHold', 'Deleted') | |
| JobNum | ABCD1234 | Eight digit alphanumeric tracking number (our internal Job Number) | |
| Action | Resubmit | The Action performed | |
| Parameter | Example Value | Description | |
|---|---|---|---|
| Result | Failed | Result of your API call (not the result of the message) | |
| MessageID | ID123456 | MessageID provided in your request | |
| Message | Message not found | Reason for the API call failure (see a list of possible values: TNZ API Errors) | |
If you have an existing Delayed message (scheduled for sending at a future date/time), you can use this API module to adjust the sending date/time.
The adjustment is applied to a specific MessageID. If you use common MessageID values across multiple messages, it will apply to the most recent message.
API URL: https://api.tnz.co.nz/api/v2.01/set/reschedule
HTTP Header: Content-Type="application/json; encoding='utf-8'"
{
"Sender":"application@domain.com",
"APIKey":"ta8wr7ymd",
"MessageID":"ID123456",
"SendTime":"2021-08-12T12:00:00"
}
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Transmit",
"JobNum": "ABCD1234",
"Action": "Reschedule"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/reschedule
HTTP Header: Content-Type="application/json; encoding='utf-8'"
{
"Sender":"application@domain.com",
"APIKey":"ta8wr7ymd",
"MessageID":"ID123456",
"SendTime":"2021-08-12T12:00:00"
}
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Transmit",
"JobNum": "ABCD1234",
"Action": "Reschedule"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/reschedule
HTTP Header: Content-Type="application/json; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/set/reschedule \
--header "Content-Type: application/json; encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageID": "ID123456",
"SendTime":"2021-08-12 12:00:00"
}'
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Transmit",
"JobNum": "ABCD1234",
"Action": "Reschedule"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/reschedule
HTTP Header: Content-Type="application/json; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/set/reschedule \
--header "Content-Type: application/json; encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageID": "ID123456",
"SendTime":"2021-08-12 12:00:00"
}'
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Transmit",
"JobNum": "ABCD1234",
"Action": "Reschedule"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/reschedule
HTTP Header: Content-Type="application/json; encoding='utf-8'"
<?php
$data = array(
"Sender" => "application@domain.com", // required
"APIKey" => "ta8wr7ymd", // required
"MessageID" => "ID123456", // required
"SendTime" => "2021-08-12 12:00:00" // required
);
$headers = array(
"Content-Type: application/json",
"encoding='utf-8'",
"Content-length: ".strlen(json_encode($data)),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/set/reschedule");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header('Content-Type: application/json');
echo $response;
break;
case "400": // error
header('Content-Type: application/json');
echo $response;
break;
case "500": // critical error
echo $response;
echo $err;
break;
default:
echo $response;
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Transmit",
"JobNum": "ABCD1234",
"Action": "Reschedule"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/reschedule
HTTP Header: Content-Type="application/json; encoding='utf-8'"
<?php
$data = array(
"Sender" => "application@domain.com", // required
"APIKey" => "ta8wr7ymd", // required
"MessageID" => "ID123456", // required
"SendTime" => "2021-08-12 12:00:00" // required
);
$headers = array(
"Content-Type: application/json",
"encoding='utf-8'",
"Content-length: ".strlen(json_encode($data)),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/set/reschedule");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header('Content-Type: application/json');
echo $response;
break;
case "400": // error
header('Content-Type: application/json');
echo $response;
break;
case "500": // critical error
echo $response;
echo $err;
break;
default:
echo $response;
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Transmit",
"JobNum": "ABCD1234",
"Action": "Reschedule"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/reschedule
HTTP Header: Content-Type="application/json; encoding='utf-8'"
using System;
using System.Text;
using System.IO;
using System.Net;
namespace TNZ
{
class Program
{
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/set/reschedule";
//
// Send TTS by REST API Interface
//
string strJSONData = $@"{{
""Sender"": ""application@domain.com"",
""APIKey"": ""ta8wr7ymd"",
""MessageID"": ""ID123456"",
""SendTime"": ""2021-08-01 17:00:00"" // Send Time (Your local date/time) - Optional
}}";
//
// Send API Request to REST API
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/json; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
request.ContentLength = byteArray.Length;
Stream stream = request.GetRequestStream(); //open connection
stream.Write(byteArray, 0, byteArray.Length); // Send the data.
stream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Transmit",
"JobNum": "ABCD1234",
"Action": "Reschedule"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/reschedule
HTTP Header: Content-Type="application/json; encoding='utf-8'"
using System;
using System.Text;
using System.IO;
using System.Net;
namespace TNZ
{
class Program
{
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/set/reschedule";
//
// Send TTS by REST API Interface
//
string strJSONData = $@"{{
""Sender"": ""application@domain.com"",
""APIKey"": ""ta8wr7ymd"",
""MessageID"": ""ID123456"",
""SendTime"": ""2021-08-01 17:00:00"" // Send Time (Your local date/time) - Optional
}}";
//
// Send API Request to REST API
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/json; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
request.ContentLength = byteArray.Length;
Stream stream = request.GetRequestStream(); //open connection
stream.Write(byteArray, 0, byteArray.Length); // Send the data.
stream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Transmit",
"JobNum": "ABCD1234",
"Action": "Reschedule"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/reschedule
HTTP Header: Content-Type="application/json; encoding='utf-8'"
import requests
import json
url = "https://api.tnz.co.nz/api/v2.01/set/reschedule"
headers = {
"Content-Type": "application/json",
"encoding": "utf-8"
}
data = {
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"Type": "Reschedule",
"SendTime": "2021-08-12 12:00:00"
}
r = requests.post(url, data=json.dumps(data), headers=headers)
print(r)
print(r.text)
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Transmit",
"JobNum": "ABCD1234",
"Action": "Reschedule"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/reschedule
HTTP Header: Content-Type="application/json; encoding='utf-8'"
import requests
import json
url = "https://api.tnz.co.nz/api/v2.01/set/reschedule"
headers = {
"Content-Type": "application/json",
"encoding": "utf-8"
}
data = {
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"Type": "Reschedule",
"SendTime": "2021-08-12 12:00:00"
}
r = requests.post(url, data=json.dumps(data), headers=headers)
print(r)
print(r.text)
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Transmit",
"JobNum": "ABCD1234",
"Action": "Reschedule"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/reschedule
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?xml version="1.0" encoding="UTF-8"?>
<RescheduleRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageID>ID123456</MessageID>
<SendTime>2021-08-12T12:00:00</SendTime>
</RescheduleRequest>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Transmit</Status>
<JobNum>ABCD1234</JobNum>
<Action>Reschedule</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/reschedule
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?xml version="1.0" encoding="UTF-8"?>
<RescheduleRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageID>ID123456</MessageID>
<SendTime>2021-08-12T12:00:00</SendTime>
</RescheduleRequest>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Transmit</Status>
<JobNum>ABCD1234</JobNum>
<Action>Reschedule</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/reschedule
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/set/reschedule \
--header "Content-Type: text/xml; encoding='utf-8'" "Accept: text/xml; encoding='utf-8'" \
--data '
<?xml version="1.0" encoding="UTF-8"?>
<RescheduleRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageID>ID123456</MessageID>
<SendTime>2021-08-12 12:00:00</SendTime>
</RescheduleRequest>
'
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Transmit</Status>
<JobNum>ABCD1234</JobNum>
<Action>Reschedule</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/reschedule
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/set/reschedule \
--header "Content-Type: text/xml; encoding='utf-8'" "Accept: text/xml; encoding='utf-8'" \
--data '
<?xml version="1.0" encoding="UTF-8"?>
<RescheduleRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageID>ID123456</MessageID>
<SendTime>2021-08-12 12:00:00</SendTime>
</RescheduleRequest>
'
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Transmit</Status>
<JobNum>ABCD1234</JobNum>
<Action>Reschedule</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/reschedule
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?php
$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><root></root>");
$data->addChild("Sender","application@domain.com"); // required
$data->addChild("APIKey","ta8wr7ymd"); // required
$data->addChild("MessageID","ID123456"); // required
$data->addChild("SendTime","2021-08-12 12:00:00"); // required
$headers = array(
"Content-Type: text/xml",
"Accept: text/xml",
"encoding='utf-8'",
"Content-length: ".strlen($data->asXML()),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/set/reschedule");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "400": // error
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "500": // critical error
echo $response."\n";
echo $err;
break;
default:
echo $response."\n";
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Transmit</Status>
<JobNum>ABCD1234</JobNum>
<Action>Reschedule</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/reschedule
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?php
$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><root></root>");
$data->addChild("Sender","application@domain.com"); // required
$data->addChild("APIKey","ta8wr7ymd"); // required
$data->addChild("MessageID","ID123456"); // required
$data->addChild("SendTime","2021-08-12 12:00:00"); // required
$headers = array(
"Content-Type: text/xml",
"Accept: text/xml",
"encoding='utf-8'",
"Content-length: ".strlen($data->asXML()),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/set/reschedule");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "400": // error
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "500": // critical error
echo $response."\n";
echo $err;
break;
default:
echo $response."\n";
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Transmit</Status>
<JobNum>ABCD1234</JobNum>
<Action>Reschedule</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/reschedule
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
namespace SetRescheduleXml
{
class Program
{
private static XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerText = val;
return workingNode;
}
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/set/reschedule";
XmlDocument xmlDoc = new XmlDocument();
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null); // <?xml version="1.0" encoding="UTF-8"?>
xmlDoc.AppendChild(docNode);
XmlNode rootNode = xmlDoc.CreateElement("RescheduleRequest");
xmlDoc.AppendChild(rootNode);
rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com")); // required
rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd")); // required
rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", "ID123456")); // required
rootNode.AppendChild(addChildNode(xmlDoc, "SendTime", "2021-08-12 12:00:00")); // required
//
// Send Raw XML Request
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "text/xml; encoding='utf-8'";
request.Accept = "text/xml; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
request.ContentLength = byteArray.Length;
Stream newStream = request.GetRequestStream(); //open connection
newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
newStream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Transmit</Status>
<JobNum>ABCD1234</JobNum>
<Action>Reschedule</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/reschedule
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
namespace SetRescheduleXml
{
class Program
{
private static XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerText = val;
return workingNode;
}
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/set/reschedule";
XmlDocument xmlDoc = new XmlDocument();
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null); // <?xml version="1.0" encoding="UTF-8"?>
xmlDoc.AppendChild(docNode);
XmlNode rootNode = xmlDoc.CreateElement("RescheduleRequest");
xmlDoc.AppendChild(rootNode);
rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com")); // required
rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd")); // required
rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", "ID123456")); // required
rootNode.AppendChild(addChildNode(xmlDoc, "SendTime", "2021-08-12 12:00:00")); // required
//
// Send Raw XML Request
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "text/xml; encoding='utf-8'";
request.Accept = "text/xml; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
request.ContentLength = byteArray.Length;
Stream newStream = request.GetRequestStream(); //open connection
newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
newStream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Transmit</Status>
<JobNum>ABCD1234</JobNum>
<Action>Reschedule</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/reschedule
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
import requests
import xml.etree.ElementTree as ET
url = "https://api.tnz.co.nz/api/v2.01/set/reschedule"
headers = {
"Content-Type": "text/xml",
"Accept": "text/xml",
"encoding": "utf-8"
}
root = ET.Element('RescheduleRequest')
ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "MessageID").text = "ID123456"
ET.SubElement(root, "SendTime").text = "2021-08-12 12:00:00"
r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)
print(r)
print(r.text)
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Transmit</Status>
<JobNum>ABCD1234</JobNum>
<Action>Reschedule</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/reschedule
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
import requests
import xml.etree.ElementTree as ET
url = "https://api.tnz.co.nz/api/v2.01/set/reschedule"
headers = {
"Content-Type": "text/xml",
"Accept": "text/xml",
"encoding": "utf-8"
}
root = ET.Element('RescheduleRequest')
ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "MessageID").text = "ID123456"
ET.SubElement(root, "SendTime").text = "2021-08-12 12:00:00"
r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)
print(r)
print(r.text)
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Transmit</Status>
<JobNum>ABCD1234</JobNum>
<Action>Reschedule</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</ErrorMessage>
</root>
| Parameter | Example Value | Description | |
|---|---|---|---|
| Sender | application@domain.com | Sender value set up in Create a new API user token | |
| APIKey | ta8wr7ymd | APIKey value set up in Create a new API user token | |
| MessageID | ID123456 | MessageID the Action should apply to | |
| SendTime | 2021-12-31T23:00 | Reschedule sending for the specified date/time, a single point of time in a combined date and time representation ({date}T{time}; for example, 2017-08-29T04:00 in your local timezone, specified by your Sender setting or overridden using the TimeZone command). | |
| Parameter | Example Value | Description | |
|---|---|---|---|
| Result | Success | Result of your API call (not the result of the message) | |
| MessageID | ID123456 | MessageID the Action was applied to | |
| Status | Transmit | State of the message prior to performing the Action ('Transmit', 'Pending', 'Delayed', 'CreditHold', 'Deleted') | |
| JobNum | ABCD1234 | Eight digit alphanumeric tracking number (our internal Job Number) | |
| Action | Reschedule | The Action performed | |
| Parameter | Example Value | Description | |
|---|---|---|---|
| Result | Failed | Result of your API call (not the result of the message) | |
| MessageID | ID123456 | MessageID provided in your request | |
| Message | Message not found | Reason for the API call failure (see a list of possible values: TNZ API Errors) | |
If you have an existing Delayed message (scheduled for sending at a future date/time) you can use this API module to Cancel sending of the message.
The cancellation is applied to a specific MessageID. If you use common MessageID values across multiple messages, it will apply to the most recent message.
API URL: https://api.tnz.co.nz/api/v2.01/set/abort
HTTP Header: Content-Type="application/json; encoding='utf-8'"
{
"Sender":"application@domain.com",
"APIKey":"ta8wr7ymd",
"MessageID":"ID123456"
}
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Pending",
"JobNum": "ABCD1234",
"Action": "Abort"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/abort
HTTP Header:
HTTP Header: Content-Type="application/json; encoding='utf-8'"
{
"Sender":"application@domain.com",
"APIKey":"ta8wr7ymd",
"MessageID":"ID123456"
}
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Pending",
"JobNum": "ABCD1234",
"Action": "Abort"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/abort
HTTP Header: Content-Type="application/json; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/set/abort \
--header "Content-Type: application/json; encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageID": "ID123456"
}'
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Pending",
"JobNum": "ABCD1234",
"Action": "Abort"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/abort
HTTP Header: Content-Type="application/json; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/set/abort \
--header "Content-Type: application/json; encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageID": "ID123456"
}'
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Pending",
"JobNum": "ABCD1234",
"Action": "Abort"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/abort
HTTP Header: Content-Type="application/json; encoding='utf-8'"
<?php
$data = array(
"Sender" => "application@domain.com", // required
"APIKey" => "ta8wr7ymd", // required
"MessageID" => "ID123456" // required
);
$headers = array(
"Content-Type: application/json",
"encoding='utf-8'",
"Content-length: ".strlen(json_encode($data)),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/set/abort");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header('Content-Type: application/json');
echo $response;
break;
case "400": // error
header('Content-Type: application/json');
echo $response;
break;
case "500": // critical error
echo $response;
echo $err;
break;
default:
echo $response;
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Pending",
"JobNum": "ABCD1234",
"Action": "Abort"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/abort
HTTP Header: Content-Type="application/json; encoding='utf-8'"
<?php
$data = array(
"Sender" => "application@domain.com", // required
"APIKey" => "ta8wr7ymd", // required
"MessageID" => "ID123456" // required
);
$headers = array(
"Content-Type: application/json",
"encoding='utf-8'",
"Content-length: ".strlen(json_encode($data)),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/set/abort");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header('Content-Type: application/json');
echo $response;
break;
case "400": // error
header('Content-Type: application/json');
echo $response;
break;
case "500": // critical error
echo $response;
echo $err;
break;
default:
echo $response;
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Pending",
"JobNum": "ABCD1234",
"Action": "Abort"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/abort
HTTP Header: Content-Type="application/json; encoding='utf-8'"
using System;
using System.Text;
using System.IO;
using System.Net;
namespace TNZ
{
class Program
{
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/set/abort";
//
// Send TTS by REST API Interface
//
string strJSONData = $@"{{
""Sender"": ""application@domain.com"",
""APIKey"": ""ta8wr7ymd"",
""MessageID"": ""ID123456"",
}}";
//
// Send API Request to REST API
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/json; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
request.ContentLength = byteArray.Length;
Stream stream = request.GetRequestStream(); //open connection
stream.Write(byteArray, 0, byteArray.Length); // Send the data.
stream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Pending",
"JobNum": "ABCD1234",
"Action": "Abort"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/abort
HTTP Header: Content-Type="application/json; encoding='utf-8'"
using System;
using System.Text;
using System.IO;
using System.Net;
namespace TNZ
{
class Program
{
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/set/abort";
//
// Send TTS by REST API Interface
//
string strJSONData = $@"{{
""Sender"": ""application@domain.com"",
""APIKey"": ""ta8wr7ymd"",
""MessageID"": ""ID123456"",
}}";
//
// Send API Request to REST API
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/json; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
request.ContentLength = byteArray.Length;
Stream stream = request.GetRequestStream(); //open connection
stream.Write(byteArray, 0, byteArray.Length); // Send the data.
stream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Pending",
"JobNum": "ABCD1234",
"Action": "Abort"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/abort
HTTP Header: Content-Type="application/json; encoding='utf-8'"
import requests
import json
url = "https://api.tnz.co.nz/api/v2.01/set/abort"
headers = {
"Content-Type": "application/json",
"encoding": "utf-8"
}
data = {
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageID" : "ID123456"
}
r = requests.post(url, data=json.dumps(data), headers=headers)
print(r)
print(r.text)
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Pending",
"JobNum": "ABCD1234",
"Action": "Abort"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/abort
HTTP Header: Content-Type="application/json; encoding='utf-8'"
import requests
import json
url = "https://api.tnz.co.nz/api/v2.01/set/abort"
headers = {
"Content-Type": "application/json",
"encoding": "utf-8"
}
data = {
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageID" : "ID123456"
}
r = requests.post(url, data=json.dumps(data), headers=headers)
print(r)
print(r.text)
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Pending",
"JobNum": "ABCD1234",
"Action": "Abort"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/abort
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?xml version="1.0" encoding="UTF-8"?>
<AbortRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageID>ID123456</MessageID>
</AbortRequest>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Pending</Status>
<JobNum>ABCD1234</JobNum>
<Action>Abort</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/abort
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?xml version="1.0" encoding="UTF-8"?>
<AbortRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageID>ID123456</MessageID>
</AbortRequest>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Pending</Status>
<JobNum>ABCD1234</JobNum>
<Action>Abort</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/abort
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/set/abort \
--header "Content-Type: text/xml; encoding='utf-8'" \
--data '
<?xml version="1.0" encoding="UTF-8"?>
<AbortRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageID>ID123456</MessageID>
</AbortRequest>
'
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Pending</Status>
<JobNum>ABCD1234</JobNum>
<Action>Abort</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/abort
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/set/abort \
--header "Content-Type: text/xml; encoding='utf-8'" \
--data '
<?xml version="1.0" encoding="UTF-8"?>
<AbortRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageID>ID123456</MessageID>
</AbortRequest>
'
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Pending</Status>
<JobNum>ABCD1234</JobNum>
<Action>Abort</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/abort
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?php
$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><AbortRequest></AbortRequest>");
$data->addChild("Sender","application@domain.com"); // required
$data->addChild("APIKey","ta8wr7ymd"); // required
$data->addChild("MessageID","ID123456"); // required
$headers = array(
"Content-Type: text/xml",
"Accept: text/xml",
"encoding='utf-8'",
"Content-length: ".strlen($data->asXML()),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/set/abort");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "400": // error
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "500": // critical error
echo $response."\n";
echo $err;
break;
default:
echo $response."\n";
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Pending</Status>
<JobNum>ABCD1234</JobNum>
<Action>Abort</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/abort
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?php
$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><AbortRequest></AbortRequest>");
$data->addChild("Sender","application@domain.com"); // required
$data->addChild("APIKey","ta8wr7ymd"); // required
$data->addChild("MessageID","ID123456"); // required
$headers = array(
"Content-Type: text/xml",
"Accept: text/xml",
"encoding='utf-8'",
"Content-length: ".strlen($data->asXML()),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/set/abort");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "400": // error
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "500": // critical error
echo $response."\n";
echo $err;
break;
default:
echo $response."\n";
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Pending</Status>
<JobNum>ABCD1234</JobNum>
<Action>Abort</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/abort
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
namespace SetAbortXml
{
class Program
{
private static XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerText = val;
return workingNode;
}
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/set/abort";
XmlDocument xmlDoc = new XmlDocument();
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null); // <?xml version="1.0" encoding="UTF-8"?>
xmlDoc.AppendChild(docNode);
XmlNode rootNode = xmlDoc.CreateElement("AbortRequest");
xmlDoc.AppendChild(rootNode);
rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com")); // required
rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd")); // required
rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", "ID123456")); // required
//
// Send Raw XML Request
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "text/xml; encoding='utf-8'";
request.Accept = "text/xml; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
request.ContentLength = byteArray.Length;
Stream newStream = request.GetRequestStream(); //open connection
newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
newStream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Pending</Status>
<JobNum>ABCD1234</JobNum>
<Action>Abort</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/abort
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
namespace SetAbortXml
{
class Program
{
private static XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerText = val;
return workingNode;
}
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/set/abort";
XmlDocument xmlDoc = new XmlDocument();
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null); // <?xml version="1.0" encoding="UTF-8"?>
xmlDoc.AppendChild(docNode);
XmlNode rootNode = xmlDoc.CreateElement("AbortRequest");
xmlDoc.AppendChild(rootNode);
rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com")); // required
rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd")); // required
rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", "ID123456")); // required
//
// Send Raw XML Request
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "text/xml; encoding='utf-8'";
request.Accept = "text/xml; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
request.ContentLength = byteArray.Length;
Stream newStream = request.GetRequestStream(); //open connection
newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
newStream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Pending</Status>
<JobNum>ABCD1234</JobNum>
<Action>Abort</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/abort
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
import requests
import xml.etree.ElementTree as ET
url = "https://api.tnz.co.nz/api/v2.01/set/abort"
headers = {
"Content-Type": "text/xml",
"Accept": "text/xml",
"encoding": "utf-8"
}
root = ET.Element('AbortRequest')
ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "MessageID").text = "ID123456"
r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)
print(r)
print(r.text)
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Pending</Status>
<JobNum>ABCD1234</JobNum>
<Action>Abort</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/abort
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
import requests
import xml.etree.ElementTree as ET
url = "https://api.tnz.co.nz/api/v2.01/set/abort"
headers = {
"Content-Type": "text/xml",
"Accept": "text/xml",
"encoding": "utf-8"
}
root = ET.Element('AbortRequest')
ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "MessageID").text = "ID123456"
r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)
print(r)
print(r.text)
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Pending</Status>
<JobNum>ABCD1234</JobNum>
<Action>Abort</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</Message>
</root>
| Parameter | Example Value | Description | |
|---|---|---|---|
| Sender | application@domain.com | Sender value set up in Create a new API user token | |
| APIKey | ta8wr7ymd | APIKey value set up in Create a new API user token | |
| MessageID | ID123456 | MessageID the Action should apply to | |
| Parameter | Example Value | Description | |
|---|---|---|---|
| Result | Success | Result of your API call (not the result of the message) | |
| MessageID | ID123456 | MessageID the Action was applied to | |
| Status | Delayed | State of the message prior to performing the Action ('Transmit', 'Pending', 'Delayed', 'CreditHold', 'Deleted') | |
| JobNum | ABCD1234 | Eight digit alphanumeric tracking number (our internal Job Number) | |
| Action | Abort | The Action performed | |
| Parameter | Example Value | Description | |
|---|---|---|---|
| Result | Failed | Result of your API call (not the result of the message) | |
| MessageID | ID123456 | MessageID provided in your request | |
| Message | Message not found | Reason for the API call failure (see a list of possible values: TNZ API Errors) | |
When sending a Voice/Text-to-Speech message, you may specify the NumberOfOperators value (limits the quantity of simultaneous/concurrent calls). You can use this API module to adjust the NumberOfOperators value in real-time.
The cancellation is applied to a specific MessageID. If you use common MessageID values across multiple messages, it will apply to the most recent message.
API URL: https://api.tnz.co.nz/api/v2.01/set/pacing
HTTP Header: Content-Type="application/json; encoding='utf-8'"
{
"Sender":"application@domain.com",
"APIKey":"ta8wr7ymd",
"MessageID":"ID123456",
"NumberOfOperators": 1
}
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Pending",
"JobNum": "ABCD1234",
"Action": "Pacing"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/pacing
HTTP Header: Content-Type="application/json; encoding='utf-8'"
{
"Sender":"application@domain.com",
"APIKey":"ta8wr7ymd",
"MessageID":"ID123456",
"NumberOfOperators": 1
}
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Pending",
"JobNum": "ABCD1234",
"Action": "Pacing"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/pacing
HTTP Header: Content-Type="application/json; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/set/pacing \
--header "Content-Type: application/json; encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"Type": "Pacing",
"NumberOfOperators": 1
}'
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Pending",
"JobNum": "ABCD1234",
"Action": "Pacing"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/pacing
HTTP Header: Content-Type="application/json; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/set/pacing \
--header "Content-Type: application/json; encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"Type": "Pacing",
"NumberOfOperators": 1
}'
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Pending",
"JobNum": "ABCD1234",
"Action": "Pacing"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/pacing
HTTP Header: Content-Type="application/json; encoding='utf-8'"
<?php
$data = array(
"Sender" => "application@domain.com", // required
"APIKey" => "ta8wr7ymd", // required
"Type" => "Pacing", // required
"NumberOfOperators" => 1 // required
);
$headers = array(
"Content-Type: application/json",
"encoding='utf-8'",
"Content-length: ".strlen(json_encode($data)),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/set/pacing");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header('Content-Type: application/json');
echo $response;
break;
case "400": // error
header('Content-Type: application/json');
echo $response;
break;
case "500": // critical error
echo $response;
echo $err;
break;
default:
echo $response;
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Pending",
"JobNum": "ABCD1234",
"Action": "Pacing"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/pacing
HTTP Header: Content-Type="application/json; encoding='utf-8'"
<?php
$data = array(
"Sender" => "application@domain.com", // required
"APIKey" => "ta8wr7ymd", // required
"Type" => "Pacing", // required
"NumberOfOperators" => 1 // required
);
$headers = array(
"Content-Type: application/json",
"encoding='utf-8'",
"Content-length: ".strlen(json_encode($data)),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/set/pacing");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header('Content-Type: application/json');
echo $response;
break;
case "400": // error
header('Content-Type: application/json');
echo $response;
break;
case "500": // critical error
echo $response;
echo $err;
break;
default:
echo $response;
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Pending",
"JobNum": "ABCD1234",
"Action": "Pacing"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/pacing
HTTP Header: Content-Type="application/json; encoding='utf-8'"
using System;
using System.Text;
using System.IO;
using System.Net;
namespace TNZ
{
class Program
{
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/set/pacing";
//
// Send TTS by REST API Interface
//
string strJSONData = $@"{{
""Sender"": ""application@domain.com"",
""APIKey"": ""ta8wr7ymd"",
""MessageID"" : ""ID123456"",
""NumberOfOperators"": 1,
}}";
//
// Send API Request to REST API
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/json; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
request.ContentLength = byteArray.Length;
Stream stream = request.GetRequestStream(); //open connection
stream.Write(byteArray, 0, byteArray.Length); // Send the data.
stream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Pending",
"JobNum": "ABCD1234",
"Action": "Pacing"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/pacing
HTTP Header: Content-Type="application/json; encoding='utf-8'"
using System;
using System.Text;
using System.IO;
using System.Net;
namespace TNZ
{
class Program
{
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/set/pacing";
//
// Send TTS by REST API Interface
//
string strJSONData = $@"{{
""Sender"": ""application@domain.com"",
""APIKey"": ""ta8wr7ymd"",
""MessageID"" : ""ID123456"",
""NumberOfOperators"": 1,
}}";
//
// Send API Request to REST API
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/json; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
request.ContentLength = byteArray.Length;
Stream stream = request.GetRequestStream(); //open connection
stream.Write(byteArray, 0, byteArray.Length); // Send the data.
stream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Pending",
"JobNum": "ABCD1234",
"Action": "Pacing"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/pacing
HTTP Header: Content-Type="application/json; encoding='utf-8'"
import requests
import json
url = "https://api.tnz.co.nz/api/v2.01/set/pacing"
headers = {
"Content-Type": "application/json",
"encoding": "utf-8"
}
data = {
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageID" : "ID123456",
"NumberOfOperators" : 1
}
r = requests.post(url, data=json.dumps(data), headers=headers)
print(r)
print(r.text)
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Pending",
"JobNum": "ABCD1234",
"Action": "Pacing"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/pacing
HTTP Header: Content-Type="application/json; encoding='utf-8'"
import requests
import json
url = "https://api.tnz.co.nz/api/v2.01/set/pacing"
headers = {
"Content-Type": "application/json",
"encoding": "utf-8"
}
data = {
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageID" : "ID123456",
"NumberOfOperators" : 1
}
r = requests.post(url, data=json.dumps(data), headers=headers)
print(r)
print(r.text)
{
"Result": "Success",
"MessageID": "ID123456",
"Data": {
"Status": "Pending",
"JobNum": "ABCD1234",
"Action": "Pacing"
}
}
{
"Result": "Failed",
"MessageID": "ID123456",
"ErrorMessage": "Message not found"
}
API URL: https://api.tnz.co.nz/api/v2.01/set/pacing
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?xml version="1.0" encoding="UTF-8"?>
<PacingRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageID>ID123456</MessageID>
<NumberOfOperators>1</NumberOfOperators>
</PacingRequest>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Pending</Status>
<JobNum>ABCD1234</JobNum>
<Action>Pacing</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/pacing
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?xml version="1.0" encoding="UTF-8"?>
<PacingRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageID>ID123456</MessageID>
<NumberOfOperators>1</NumberOfOperators>
</PacingRequest>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Pending</Status>
<JobNum>ABCD1234</JobNum>
<Action>Pacing</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/pacing
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/set/pacing \
--header "Content-Type: text/xml; encoding='utf-8'" "Accept: text/xml; encoding='utf-8'" \
--data '
<?xml version="1.0" encoding="UTF-8"?>
<PacingRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageID>ID123456</MessageID>
<NumberOfOperators>1</NumberOfOperators>
</PacingRequest>
'
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Pending</Status>
<JobNum>ABCD1234</JobNum>
<Action>Pacing</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/pacing
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/set/pacing \
--header "Content-Type: text/xml; encoding='utf-8'" "Accept: text/xml; encoding='utf-8'" \
--data '
<?xml version="1.0" encoding="UTF-8"?>
<PacingRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageID>ID123456</MessageID>
<NumberOfOperators>1</NumberOfOperators>
</PacingRequest>
'
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Pending</Status>
<JobNum>ABCD1234</JobNum>
<Action>Pacing</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/pacing
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?php
$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><PacingRequest></PacingRequest>");
$data->addChild("Sender","application@domain.com"); // required
$data->addChild("APIKey","ta8wr7ymd"); // required
$data->addChild("MessageID","ID123456"); // required
$data->addChild("NumberOfOperators","1"); // required
$headers = array(
"Content-Type: text/xml",
"Accept: text/xml",
"encoding='utf-8'",
"Content-length: ".strlen($data->asXML()),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/set/pacing");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "400": // error
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "500": // critical error
echo $response."\n";
echo $err;
break;
default:
echo $response."\n";
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Pending</Status>
<JobNum>ABCD1234</JobNum>
<Action>Pacing</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/pacing
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?php
$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><PacingRequest></PacingRequest>");
$data->addChild("Sender","application@domain.com"); // required
$data->addChild("APIKey","ta8wr7ymd"); // required
$data->addChild("MessageID","ID123456"); // required
$data->addChild("NumberOfOperators","1"); // required
$headers = array(
"Content-Type: text/xml",
"Accept: text/xml",
"encoding='utf-8'",
"Content-length: ".strlen($data->asXML()),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/set/pacing");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "400": // error
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "500": // critical error
echo $response."\n";
echo $err;
break;
default:
echo $response."\n";
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Pending</Status>
<JobNum>ABCD1234</JobNum>
<Action>Pacing</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/pacing
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
namespace SetPacingXml
{
class Program
{
private static XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerText = val;
return workingNode;
}
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/set/pacing";
XmlDocument xmlDoc = new XmlDocument();
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null); // <?xml version="1.0" encoding="UTF-8"?>
xmlDoc.AppendChild(docNode);
XmlNode rootNode = xmlDoc.CreateElement("PacingRequest");
xmlDoc.AppendChild(rootNode);
rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com")); // required
rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd")); // required
rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", "ID123456")); // required
rootNode.AppendChild(addChildNode(xmlDoc, "NumberOfOperators", "1")); // required
//
// Send Raw XML Request
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "text/xml; encoding='utf-8'";
request.Accept = "text/xml; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
request.ContentLength = byteArray.Length;
Stream newStream = request.GetRequestStream(); //open connection
newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
newStream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Pending</Status>
<JobNum>ABCD1234</JobNum>
<Action>Pacing</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/pacing
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
namespace SetPacingXml
{
class Program
{
private static XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerText = val;
return workingNode;
}
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/set/pacing";
XmlDocument xmlDoc = new XmlDocument();
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null); // <?xml version="1.0" encoding="UTF-8"?>
xmlDoc.AppendChild(docNode);
XmlNode rootNode = xmlDoc.CreateElement("PacingRequest");
xmlDoc.AppendChild(rootNode);
rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com")); // required
rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd")); // required
rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", "ID123456")); // required
rootNode.AppendChild(addChildNode(xmlDoc, "NumberOfOperators", "1")); // required
//
// Send Raw XML Request
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "text/xml; encoding='utf-8'";
request.Accept = "text/xml; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
request.ContentLength = byteArray.Length;
Stream newStream = request.GetRequestStream(); //open connection
newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
newStream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Pending</Status>
<JobNum>ABCD1234</JobNum>
<Action>Pacing</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/pacing
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
import requests
import xml.etree.ElementTree as ET
url = "https://api.tnz.co.nz/api/v2.01/set/pacing"
headers = {
"Content-Type": "text/xml",
"Accept": "text/xml",
"encoding": "utf-8"
}
root = ET.Element('PacingRequest')
ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "MessageID").text = "ID123456"
ET.SubElement(root, "NumberOfOperators").text = "1"
r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)
print(r)
print(r.text)
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Pending</Status>
<JobNum>ABCD1234</JobNum>
<Action>Pacing</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/set/pacing
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
import requests
import xml.etree.ElementTree as ET
url = "https://api.tnz.co.nz/api/v2.01/set/pacing"
headers = {
"Content-Type": "text/xml",
"Accept": "text/xml",
"encoding": "utf-8"
}
root = ET.Element('PacingRequest')
ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "MessageID").text = "ID123456"
ET.SubElement(root, "NumberOfOperators").text = "1"
r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)
print(r)
print(r.text)
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<Status>Pending</Status>
<JobNum>ABCD1234</JobNum>
<Action>Pacing</Action>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Message not found</Message>
</root>
| Parameter | Example Value | Description | |
|---|---|---|---|
| Sender | application@domain.com | Sender value set up in Create a new API user token | |
| APIKey | ta8wr7ymd | APIKey value set up in Create a new API user token | |
| MessageID | ID123456 | MessageID the Action should apply to | |
| NumberOfOperators | 4 | NumberOfOperators value to apply | |
| Parameter | Example Value | Description | |
|---|---|---|---|
| Result | Success | Result of your API call (not the result of the message) | |
| MessageID | ID123456 | MessageID the Action was applied to | |
| Status | Pending | State of the message prior to performing the Action ('Transmit', 'Pending', 'Delayed', 'CreditHold', 'Deleted') | |
| JobNum | ABCD1234 | Eight digit alphanumeric tracking number (our internal Job Number) | |
| Action | NumberOfOperators | The Action performed | |
| Parameter | Example Value | Description | |
|---|---|---|---|
| Result | Failed | Result of your API call (not the result of the message) | |
| MessageID | ID123456 | MessageID provided in your request | |
| Message | Message not found | Reason for the API call failure (see a list of possible values: TNZ API Errors) | |
Delivery Reports advise whether delivery was successful. If not, it will describe why.
Each delivery report type is optional and multiple delivery report types can be used.
You will be supplied with a Web Dashboard login at registration. The Dashboard can be used to set up new sender/token pairs, as well as track sent and replied messages. You can drill into specific messages to view individual events, such as delivery attempts, retries, replies, results, clicks, etc.
Delivery reports are emailed as an HTML email for viewing by an end-user. Your sales representative can enable this for you.
Whitelabelling of SMTP Email reports is available.
To receive Delivery Reports via Webhook, please advise the URL to submit to.
Webhooks are delivered as an HTTP POST in either XML or JSON format (your preference).
Webhook failures are retried every five minutes for a maximum of 24 hours.
Supplied parameters are:
| Parameter | Example Value | Description |
|---|---|---|
| Sender | application@domain.com | Webhook sender authentication (can configure a unique Sender if required) |
| APIKey | ta8wr7ymd | Webhook token authentication (can configure a unique APIKey if required) |
| Type | SMS | Type of Message ('Email', 'SMS', 'Fax', 'Voice' or 'TextToSpeech') |
| Destination | +6421000001 | Destination that the webhook is for (alphanumeric field, where telephone/mobile numbers are supplied in E.164 internationalised format) |
| MessageID | js82hn8n | MessageID parameter supplied when sending your original API call |
| SubAccount | SubAccount01 | Used for reporting, billing and Web Dashboard segmentation |
| Department | Department01 | Used for reporting, billing and Web Dashboard segmentation |
| JobNumber | 10C7B9A0 | Eight digit alphanumeric tracking number (our internal Job Number) |
| SentTime | 16/10/2019 13:43 p.m. | Time message was completed (Sender's local time time in 'dd/MM/yyyy HH:mm tt' format) |
| Status | SUCCESS | For submission results, values are SUCCESS, FAILED, PENDING For reply reports, this will be RECEIVED For additional analytics, this will be UPDATED |
| Result | Sent OK | Final delivery result and/or the cause for a message delivery failure For a list of possible values, see SMS, Fax, Voice, TextToSpeech Email result codes are defined by the receiving email server For reply reports, this will be RECEIVED For additional analytics, this will be the event description |
| Message | Field will be blank; it is used by the Receive Messages webhook only | |
| Price | 0.20 | Your cost for this transaction, charged by us to you |
| Detail | SMSParts:2 | Additional billing detail: "SMSParts", "FaxPages", "VoiceMinutes", "Size", "Prompts" |
| URL | https://www.example.com/webhook | The URL this webhook is sent to |
| RESPONSEMODE | JSON | This webhook's format |
API users are able to poll for the status of a message via the GET Status API.
The GET Poll should be configured to timeout after 48 hours with no result.
API URL: https://api.tnz.co.nz/api/v2.01/get/status
HTTP Header: Content-Type="application/json; encoding='utf-8'"
{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageID": "ID123456"
}
{
"Result": "Success",
"Data": {
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"Status": "Completed",
"JobNum": "10AB20CD",
"Account": "Account#",
"SubAccount": "",
"Department": "",
"Count": "1",
"Complete": "1",
"Success": "1",
"Failed": "0"
}
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/status
HTTP Header: Content-Type="application/json; encoding='utf-8'"
{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageID": "ID123456"
}
{
"Result": "Success",
"Data": {
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"Status": "Completed",
"JobNum": "10AB20CD",
"Account": "Account#",
"SubAccount": "",
"Department": "",
"Count": "1",
"Complete": "1",
"Success": "1",
"Failed": "0"
}
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/status
HTTP Header: Content-Type="application/json; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/get/status \
--header "Content-Type: application/json; encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageID": "ID123456"
}'
{
"Result": "Success",
"Data": {
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"Status": "Completed",
"JobNum": "10AB20CD",
"Account": "Account#",
"SubAccount": "",
"Department": "",
"Count": "1",
"Complete": "1",
"Success": "1",
"Failed": "0"
}
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/status
HTTP Header: Content-Type="application/json; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/get/status \
--header "Content-Type: application/json; encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageID": "ID123456"
}'
{
"Result": "Success",
"Data": {
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"Status": "Completed",
"JobNum": "10AB20CD",
"Account": "Account#",
"SubAccount": "",
"Department": "",
"Count": "1",
"Complete": "1",
"Success": "1",
"Failed": "0"
}
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/status
HTTP Header: Content-Type="application/json; encoding='utf-8'"
<?php
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$message_id = "ID123456"; // required
$data = array(
"Sender" => $sender,
"APIKey" => $apikey,
"MessageID" => $message_id
);
$headers = array(
"Content-Type: application/json",
"encoding='utf-8'",
"Content-length: ".strlen(json_encode($data)),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/get/status");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header('Content-Type: application/json');
echo $response;
break;
case "400": // error
header('Content-Type: application/json');
echo $response;
break;
case "500": // critical error
echo $response;
echo $err;
break;
default:
echo $response;
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
{
"Result": "Success",
"Data": {
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"Status": "Completed",
"JobNum": "10AB20CD",
"Account": "Account#",
"SubAccount": "",
"Department": "",
"Count": "1",
"Complete": "1",
"Success": "1",
"Failed": "0"
}
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/status
HTTP Header: Content-Type="application/json; encoding='utf-8'"
<?php
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$message_id = "ID123456"; // required
$data = array(
"Sender" => $sender,
"APIKey" => $apikey,
"MessageID" => $message_id
);
$headers = array(
"Content-Type: application/json",
"encoding='utf-8'",
"Content-length: ".strlen(json_encode($data)),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/get/status");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header('Content-Type: application/json');
echo $response;
break;
case "400": // error
header('Content-Type: application/json');
echo $response;
break;
case "500": // critical error
echo $response;
echo $err;
break;
default:
echo $response;
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
{
"Result": "Success",
"Data": {
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"Status": "Completed",
"JobNum": "10AB20CD",
"Account": "Account#",
"SubAccount": "",
"Department": "",
"Count": "1",
"Complete": "1",
"Success": "1",
"Failed": "0"
}
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/status
HTTP Header: Content-Type="application/json; encoding='utf-8'"
using System;
using System.Text;
using System.IO;
using System.Net;
namespace TNZ
{
class Program
{
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/get/status";
//
// Send TTS by REST API Interface
//
string strJSONData = $@"{{
""Sender"": ""application@domain.com"",
""APIKey"": ""ta8wr7ymd"",
""MessageID"": ""ID123456"",
}}";
//
// Send API Request to REST API
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/json; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
request.ContentLength = byteArray.Length;
Stream stream = request.GetRequestStream(); //open connection
stream.Write(byteArray, 0, byteArray.Length); // Send the data.
stream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
{
"Result": "Success",
"Data": {
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"Status": "Completed",
"JobNum": "10AB20CD",
"Account": "Account#",
"SubAccount": "",
"Department": "",
"Count": "1",
"Complete": "1",
"Success": "1",
"Failed": "0"
}
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/status
HTTP Header: Content-Type="application/json; encoding='utf-8'"
using System;
using System.Text;
using System.IO;
using System.Net;
namespace TNZ
{
class Program
{
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/get/status";
//
// Send TTS by REST API Interface
//
string strJSONData = $@"{{
""Sender"": ""application@domain.com"",
""APIKey"": ""ta8wr7ymd"",
""MessageID"": ""ID123456"",
}}";
//
// Send API Request to REST API
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/json; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
request.ContentLength = byteArray.Length;
Stream stream = request.GetRequestStream(); //open connection
stream.Write(byteArray, 0, byteArray.Length); // Send the data.
stream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
{
"Result": "Success",
"Data": {
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"Status": "Completed",
"JobNum": "10AB20CD",
"Account": "Account#",
"SubAccount": "",
"Department": "",
"Count": "1",
"Complete": "1",
"Success": "1",
"Failed": "0"
}
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/status
HTTP Header: Content-Type="application/json; encoding='utf-8'"
import requests
import json
url = "https://api.tnz.co.nz/api/v2.01/get/status"
headers = {
"Content-Type": "application/json",
"encoding": "utf-8"
}
data = {
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageID" : "ID123456"
}
r = requests.post(url, data=json.dumps(data), headers=headers)
print(r)
print(r.text)
{
"Result": "Success",
"Data": {
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"Status": "Completed",
"JobNum": "10AB20CD",
"Account": "Account#",
"SubAccount": "",
"Department": "",
"Count": "1",
"Complete": "1",
"Success": "1",
"Failed": "0"
}
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/status
HTTP Header: Content-Type="application/json; encoding='utf-8'"
import requests
import json
url = "https://api.tnz.co.nz/api/v2.01/get/status"
headers = {
"Content-Type": "application/json",
"encoding": "utf-8"
}
data = {
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageID" : "ID123456"
}
r = requests.post(url, data=json.dumps(data), headers=headers)
print(r)
print(r.text)
{
"Result": "Success",
"Data": {
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"Status": "Completed",
"JobNum": "10AB20CD",
"Account": "Account#",
"SubAccount": "",
"Department": "",
"Count": "1",
"Complete": "1",
"Success": "1",
"Failed": "0"
}
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/status
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?xml version="1.0" encoding="UTF-8"?>
<StatusRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageID>ID123456</MessageID>
</StatusRequest>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<Status>Completed</Status>
<JobNum>10AB20CD</JobNum>
<Account>Account#</Account>
<SubAccount></SubAccount>
<Department></Department>
<Count>1</Count>
<Complete>1</Complete>
<Success>1</Success>
<Failed>0</Failed>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/get/status
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?xml version="1.0" encoding="UTF-8"?>
<StatusRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageID>ID123456</MessageID>
</StatusRequest>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<Status>Completed</Status>
<JobNum>10AB20CD</JobNum>
<Account>Account#</Account>
<SubAccount></SubAccount>
<Department></Department>
<Count>1</Count>
<Complete>1</Complete>
<Success>1</Success>
<Failed>0</Failed>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/get/status
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/get/status \
--header "Content-Type: text/xml; encoding='utf-8'" \
--data '
<?xml version="1.0" encoding="UTF-8"?>
<StatusRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageID>ID123456</MessageID>
</StatusRequest>
'
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<Status>Completed</Status>
<JobNum>10AB20CD</JobNum>
<Account>Account#</Account>
<SubAccount></SubAccount>
<Department></Department>
<Count>1</Count>
<Complete>1</Complete>
<Success>1</Success>
<Failed>0</Failed>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/get/status
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/get/status \
--header "Content-Type: text/xml; encoding='utf-8'" \
--data '
<?xml version="1.0" encoding="UTF-8"?>
<StatusRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageID>ID123456</MessageID>
</StatusRequest>
'
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<Status>Completed</Status>
<JobNum>10AB20CD</JobNum>
<Account>Account#</Account>
<SubAccount></SubAccount>
<Department></Department>
<Count>1</Count>
<Complete>1</Complete>
<Success>1</Success>
<Failed>0</Failed>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/get/status
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?php
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$message_id = "ID123456"; // required
$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><StatusRequest></StatusRequest>");
$data->addChild("Sender",$sender);
$data->addChild("APIKey",$apikey);
$data->addChild("MessageID",$message_id);
$options = array(
'http' => array(
'method' => 'POST',
'content' => $data->asXML(),
'header' => "Content-Type: text/xml; encoding='utf-8'\n"
)
);
$headers = array(
"Content-Type: text/xml",
"Accept: text/xml",
"encoding='utf-8'",
"Content-length: ".strlen($data->asXML()),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/get/status");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "400": // error
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "500": // critical error
echo $response."\n";
echo $err;
break;
default:
echo $response."\n";
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<Status>Completed</Status>
<JobNum>10AB20CD</JobNum>
<Account>Account#</Account>
<SubAccount></SubAccount>
<Department></Department>
<Count>1</Count>
<Complete>1</Complete>
<Success>1</Success>
<Failed>0</Failed>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/get/status
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?php
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$message_id = "ID123456"; // required
$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><StatusRequest></StatusRequest>");
$data->addChild("Sender",$sender);
$data->addChild("APIKey",$apikey);
$data->addChild("MessageID",$message_id);
$options = array(
'http' => array(
'method' => 'POST',
'content' => $data->asXML(),
'header' => "Content-Type: text/xml; encoding='utf-8'\n"
)
);
$headers = array(
"Content-Type: text/xml",
"Accept: text/xml",
"encoding='utf-8'",
"Content-length: ".strlen($data->asXML()),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/get/status");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "400": // error
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "500": // critical error
echo $response."\n";
echo $err;
break;
default:
echo $response."\n";
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<Status>Completed</Status>
<JobNum>10AB20CD</JobNum>
<Account>Account#</Account>
<SubAccount></SubAccount>
<Department></Department>
<Count>1</Count>
<Complete>1</Complete>
<Success>1</Success>
<Failed>0</Failed>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/get/status
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
namespace GetStatusXml
{
class Program
{
private static XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerText = val;
return workingNode;
}
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/get/status";
string strSender = "application@domain.com";
string strAPIKey = "ta8wr7ymd";
string strMessageID = "ID123456"; // required
XmlDocument xmlDoc = new XmlDocument();
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null); // <?xml version="1.0" encoding="UTF-8"?>
xmlDoc.AppendChild(docNode);
XmlNode rootNode = xmlDoc.CreateElement("StatusRequest");
xmlDoc.AppendChild(rootNode);
rootNode.AppendChild(addChildNode(xmlDoc, "Sender", strSender));
rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", strAPIKey));
rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", strMessageID));
XmlNode workingNode = xmlDoc.CreateElement("Sender");
//
// Send Raw XML Request
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "text/xml; encoding='utf-8'";
request.Accept = "text/xml; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
request.ContentLength = byteArray.Length;
Stream newStream = request.GetRequestStream(); //open connection
newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
newStream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<Status>Completed</Status>
<JobNum>10AB20CD</JobNum>
<Account>Account#</Account>
<SubAccount></SubAccount>
<Department></Department>
<Count>1</Count>
<Complete>1</Complete>
<Success>1</Success>
<Failed>0</Failed>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/get/status
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
namespace GetStatusXml
{
class Program
{
private static XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerText = val;
return workingNode;
}
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/get/status";
string strSender = "application@domain.com";
string strAPIKey = "ta8wr7ymd";
string strMessageID = "ID123456"; // required
XmlDocument xmlDoc = new XmlDocument();
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null); // <?xml version="1.0" encoding="UTF-8"?>
xmlDoc.AppendChild(docNode);
XmlNode rootNode = xmlDoc.CreateElement("StatusRequest");
xmlDoc.AppendChild(rootNode);
rootNode.AppendChild(addChildNode(xmlDoc, "Sender", strSender));
rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", strAPIKey));
rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", strMessageID));
XmlNode workingNode = xmlDoc.CreateElement("Sender");
//
// Send Raw XML Request
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "text/xml; encoding='utf-8'";
request.Accept = "text/xml; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
request.ContentLength = byteArray.Length;
Stream newStream = request.GetRequestStream(); //open connection
newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
newStream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<Status>Completed</Status>
<JobNum>10AB20CD</JobNum>
<Account>Account#</Account>
<SubAccount></SubAccount>
<Department></Department>
<Count>1</Count>
<Complete>1</Complete>
<Success>1</Success>
<Failed>0</Failed>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/get/status
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
import requests
import xml.etree.ElementTree as ET
url = "https://api.tnz.co.nz/api/v2.01/get/status"
headers = {
"Content-Type": "text/xml",
"Accept": "text/xml",
"encoding": "utf-8"
}
root = ET.Element('StatusRequest')
ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "MessageID").text = "ID123456"
r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)
print(r)
print(r.text)
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<Status>Completed</Status>
<JobNum>10AB20CD</JobNum>
<Account>Account#</Account>
<SubAccount></SubAccount>
<Department></Department>
<Count>1</Count>
<Complete>1</Complete>
<Success>1</Success>
<Failed>0</Failed>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/get/status
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
import requests
import xml.etree.ElementTree as ET
url = "https://api.tnz.co.nz/api/v2.01/get/status"
headers = {
"Content-Type": "text/xml",
"Accept": "text/xml",
"encoding": "utf-8"
}
root = ET.Element('StatusRequest')
ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "MessageID").text = "ID123456"
r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)
print(r)
print(r.text)
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<Status>Completed</Status>
<JobNum>10AB20CD</JobNum>
<Account>Account#</Account>
<SubAccount></SubAccount>
<Department></Department>
<Count>1</Count>
<Complete>1</Complete>
<Success>1</Success>
<Failed>0</Failed>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
<ErrorMessage>Missing or empty sender</Message>
</root>
| Parameter | Example Value | Description | |
|---|---|---|---|
| Sender | application@domain.com | Sender value set up in Create a new API user token | |
| APIKey | ta8wr7ymd | APIKey value set up in Create a new API user token | |
| MessageID | ID123456 | Your provided Message ID or TNZ Group generated Message ID | |
| Parameter | Example Value | Description | |
|---|---|---|---|
| Result | Success | Result of your API call (not the result of the message) | |
| MessageID | AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD | Your provided Message ID or TNZ Group generated Message ID | |
| Status | Completed | Current state of the message ('Unknown', 'Pending', 'Delayed', 'Completed', 'CreditHold') | |
| JobNum | 10AB20CE | Eight digit alphanumeric tracking number (our internal Job Number) | |
| Account | 102030 | Your TNZ Account | |
| SubAccount | Your supplied TNZ SubAccount | ||
| Department | Your supplied TNZ Department | ||
| Count | 5 | Total Destinations specified in the message | |
| Complete | 5 | Total Destinations where message transmission has completed | |
| Success | 4 | Total Destinations where message result is Success | |
| Failed | 1 | Total Destinations where message result is Failed | |
| Parameter | Example Value | Description | |
|---|---|---|---|
| Result | Failed | Result of your API call (not the result of the message) | |
| MessageID | AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD | Your provided Message ID or TNZ Group generated Message ID | |
| Message | Missing Sender | Reason for the API call failure (see a list of possible values: TNZ API Errors) | |
Currently, tracking SMS Received is supported.
Tracking of faxes and voicemail received is scheduled for a future release. Let your account manager know if this interests you.
You will be supplied with a Web Dashboard login at registration. The Dashboard can be used to set up new sender/token pairs, as well as track sent and replied messages. You can drill into specific messages to view individual events, such as delivery attempts, retries, replies, results, clicks, etc.
Reply message reports are emailed as an HTML email for viewing by an end-user.
Whitelabelling of SMTP Email reports is available.
When submitting SMS messages, specify the SMSEmailReply parameter.
If you are set up to receive Status webhooks, you will also be receiving SMS Received webhooks.
To receive SMS replies via Webhook, please advise the URL to submit to.
Webhooks are delivered as an HTTP POST in either XML or JSON format (your preference).
Webhook failures are retried every five minutes for a maximum of 24 hours.
The mobile has 7 days to reply to a message. Any replies received after the 7 day window will be treated as a new message.
Supplied parameters are:
| Parameter | Example Value | Description |
|---|---|---|
| Sender | application@domain.com | Webhook sender authentication (can configure a unique Sender if required) |
| APIKey | ta8wr7ymd | Webhook token authentication (can configure a unique APIKey if required) |
| Type | SMSReply | Type of Message ('Email', 'SMS', 'Fax', 'Voice', 'TextToSpeech', 'SMSInbound' or 'SMSReply') |
| Destination | +6421000001 | Mobile number that sent the SMS (alphanumeric field, where telephone/mobile numbers are supplied in E.164 internationalised format) |
| MessageID | js82hn8n | MessageID parameter supplied when sending your original API call |
| SubAccount | SubAccount01 | Used for reporting, billing and Web Dashboard segmentation |
| Department | Department01 | Used for reporting, billing and Web Dashboard segmentation |
| JobNumber | 10C7B9A0 | Eight digit alphanumeric tracking number (our internal Job Number) |
| SentTime | 16/10/2019 13:43 p.m. | Time reply message was received |
| Status | RECEIVED | For submission results, values are SUCCESS, FAILED, PENDING For reply reports, this will be RECEIVED For additional analytics, this will be UPDATED |
| Result | RECEIVED | Final delivery result and/or the cause for a message delivery failure For reply reports, this will be RECEIVED For additional analytics, this will be the event description |
| Message | This is a reply. | The received SMS message (if 'Type=SMSInbound' or 'Type=SMSReply') |
| Price | 0.20 | Your cost for the outbound message sent, charged by us to you (no cost for the reply received) |
| Detail | SMSParts:2 | Additional billing detail: "SMSParts", "FaxPages", "VoiceMinutes", "Size", "Prompts" on the outbound message sent (not the SMS Received) |
| URL | https://www.example.com/webhook | The URL this webhook is sent to |
| RESPONSEMODE | JSON | This webhook's format |
API users are able to poll for all received SMS messages in a given time-frame.
The GET Poll should be configured to timeout after 48 hours with no result.
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/received
HTTP Header: Content-Type="application/json; encoding='utf-8'"
{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"TimePeriod": "1440"
}
{
"Result": "Success",
"Data": {
"SMSReceived": [
{
"Date": "2019-12-01 14:02:03",
"From": "+6421000001",
"MessageText": "This is a reply back from the mobile phone."
},
{
"Date": "2019-12-01 14:04:14",
"From": "+6421000001",
"MessageText": "This is a second reply."
}
]
}
}
{
"Result": "Failed",
"ErrorMessage": "Message(s) NOT Found"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/received
HTTP Header: Content-Type="application/json; encoding='utf-8'"
{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"TimePeriod": "1440"
}
{
"Result": "Success",
"Data": {
"SMSReceived": [
{
"Date": "2019-12-01 14:02:03",
"From": "+6421000001",
"MessageText": "This is a reply back from the mobile phone."
},
{
"Date": "2019-12-01 14:04:14",
"From": "+6421000001",
"MessageText": "This is a second reply."
}
]
}
}
{
"Result": "Failed",
"ErrorMessage": "Message(s) NOT Found"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/received
HTTP Header: Content-Type="application/json; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/get/sms/received \
--header "Content-Type: application/json; encoding='utf-8'" "Accept: application/json; encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"TimePeriod": "1440"
}'
{
"Result": "Success",
"Data": {
"SMSReceived": [
{
"Date": "2019-12-01 14:02:03",
"From": "+6421000001",
"MessageText": "This is a reply back from the mobile phone."
},
{
"Date": "2019-12-01 14:04:14",
"From": "+6421000001",
"MessageText": "This is a second reply."
}
]
}
}
{
"Result": "Failed",
"ErrorMessage": "Message(s) NOT Found"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/received
HTTP Header: Content-Type="application/json; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/get/sms/received \
--header "Content-Type: application/json; encoding='utf-8'" "Accept: application/json; encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"TimePeriod": "1440"
}'
{
"Result": "Success",
"Data": {
"SMSReceived": [
{
"Date": "2019-12-01 14:02:03",
"From": "+6421000001",
"MessageText": "This is a reply back from the mobile phone."
},
{
"Date": "2019-12-01 14:04:14",
"From": "+6421000001",
"MessageText": "This is a second reply."
}
]
}
}
{
"Result": "Failed",
"ErrorMessage": "Message(s) NOT Found"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/received
HTTP Header: Content-Type="application/json; encoding='utf-8'"
<?php
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$timeperiod = "1440"; // required
$data = array(
"Sender" => $sender,
"APIKey" => $apikey,
"TimePeriod" => $timeperiod
);
$headers = array(
"Content-Type: application/json",
"Accept: application/json",
"encoding='utf-8'",
"Content-length: ".strlen(json_encode($data)),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/get/sms/received");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header('Content-Type: application/json');
echo $response;
break;
case "400": // error
header('Content-Type: application/json');
echo $response;
break;
case "500": // critical error
echo $response;
echo $err;
break;
default:
echo $response;
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
{
"Result": "Success",
"Data": {
"SMSReceived": [
{
"Date": "2019-12-01 14:02:03",
"From": "+6421000001",
"MessageText": "This is a reply back from the mobile phone."
},
{
"Date": "2019-12-01 14:04:14",
"From": "+6421000001",
"MessageText": "This is a second reply."
}
]
}
}
{
"Result": "Failed",
"ErrorMessage": "Message(s) NOT Found"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/received
HTTP Header: Content-Type="application/json; encoding='utf-8'"
<?php
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$timeperiod = "1440"; // required
$data = array(
"Sender" => $sender,
"APIKey" => $apikey,
"TimePeriod" => $timeperiod
);
$headers = array(
"Content-Type: application/json",
"Accept: application/json",
"encoding='utf-8'",
"Content-length: ".strlen(json_encode($data)),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/get/sms/received");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header('Content-Type: application/json');
echo $response;
break;
case "400": // error
header('Content-Type: application/json');
echo $response;
break;
case "500": // critical error
echo $response;
echo $err;
break;
default:
echo $response;
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
{
"Result": "Success",
"Data": {
"SMSReceived": [
{
"Date": "2019-12-01 14:02:03",
"From": "+6421000001",
"MessageText": "This is a reply back from the mobile phone."
},
{
"Date": "2019-12-01 14:04:14",
"From": "+6421000001",
"MessageText": "This is a second reply."
}
]
}
}
{
"Result": "Failed",
"ErrorMessage": "Message(s) NOT Found"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/received
HTTP Header: Content-Type="application/json; encoding='utf-8'"
using System;
using System.Text;
using System.IO;
using System.Net;
namespace TNZ
{
class Program
{
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/get/sms/received";
//
// Send TTS by REST API Interface
//
string strJSONData = $@"{{
""Sender"": ""application@domain.com"",
""APIKey"": ""ta8wr7ymd"",
""TimePeriod"": 1440,
}}";
//
// Send API Request to REST API
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/json; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
request.ContentLength = byteArray.Length;
Stream stream = request.GetRequestStream(); //open connection
stream.Write(byteArray, 0, byteArray.Length); // Send the data.
stream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
{
"Result": "Success",
"Data": {
"SMSReceived": [
{
"Date": "2019-12-01 14:02:03",
"From": "+6421000001",
"MessageText": "This is a reply back from the mobile phone."
},
{
"Date": "2019-12-01 14:04:14",
"From": "+6421000001",
"MessageText": "This is a second reply."
}
]
}
}
{
"Result": "Failed",
"ErrorMessage": "Message(s) NOT Found"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/received
HTTP Header: Content-Type="application/json; encoding='utf-8'"
using System;
using System.Text;
using System.IO;
using System.Net;
namespace TNZ
{
class Program
{
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/get/sms/received";
//
// Send TTS by REST API Interface
//
string strJSONData = $@"{{
""Sender"": ""application@domain.com"",
""APIKey"": ""ta8wr7ymd"",
""TimePeriod"": 1440,
}}";
//
// Send API Request to REST API
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/json; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
request.ContentLength = byteArray.Length;
Stream stream = request.GetRequestStream(); //open connection
stream.Write(byteArray, 0, byteArray.Length); // Send the data.
stream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
{
"Result": "Success",
"Data": {
"SMSReceived": [
{
"Date": "2019-12-01 14:02:03",
"From": "+6421000001",
"MessageText": "This is a reply back from the mobile phone."
},
{
"Date": "2019-12-01 14:04:14",
"From": "+6421000001",
"MessageText": "This is a second reply."
}
]
}
}
{
"Result": "Failed",
"ErrorMessage": "Message(s) NOT Found"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/received
HTTP Header: Content-Type="application/json; encoding='utf-8'"
import requests
import json
url = "https://api.tnz.co.nz/api/v2.01/get/sms/received"
headers = {
"Content-Type": "application/json",
"encoding": "utf-8"
}
data = {
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"TimePeriod": "1440"
}
r = requests.post(url, data=json.dumps(data), headers=headers)
print(r)
print(r.text)
{
"Result": "Success",
"Data": {
"SMSReceived": [
{
"Date": "2019-12-01 14:02:03",
"From": "+6421000001",
"MessageText": "This is a reply back from the mobile phone."
},
{
"Date": "2019-12-01 14:04:14",
"From": "+6421000001",
"MessageText": "This is a second reply."
}
]
}
}
{
"Result": "Failed",
"ErrorMessage": "Message(s) NOT Found"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/received
HTTP Header: Content-Type="application/json; encoding='utf-8'"
import requests
import json
url = "https://api.tnz.co.nz/api/v2.01/get/sms/received"
headers = {
"Content-Type": "application/json",
"encoding": "utf-8"
}
data = {
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"TimePeriod": "1440"
}
r = requests.post(url, data=json.dumps(data), headers=headers)
print(r)
print(r.text)
{
"Result": "Success",
"Data": {
"SMSReceived": [
{
"Date": "2019-12-01 14:02:03",
"From": "+6421000001",
"MessageText": "This is a reply back from the mobile phone."
},
{
"Date": "2019-12-01 14:04:14",
"From": "+6421000001",
"MessageText": "This is a second reply."
}
]
}
}
{
"Result": "Failed",
"ErrorMessage": "Message(s) NOT Found"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/received
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?xml version="1.0" encoding="UTF-8"?>
<SMSReceivedRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<TimePeriod>1440</TimePeriod>
</SMSReceivedRequest>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<Data>
<SMSReceived>
<SMSMessage>
<Date>2021-07-26 10:41:05</Date>
<From>+6421000001</From>
<MessageText>This is a reply back from the mobile phone.</MessageText>
</SMSMessage>
<SMSMessage>
<Date>2021-07-26 10:42:29</Date>
<From>+6421000001</From>
<MessageText>This is a second reply.</MessageText>
</SMSMessage>
</SMSReceived>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<ErrorMessage>Message(s) NOT Found</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/received
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?xml version="1.0" encoding="UTF-8"?>
<SMSReceivedRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<TimePeriod>1440</TimePeriod>
</SMSReceivedRequest>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<Data>
<SMSReceived>
<SMSMessage>
<Date>2021-07-26 10:41:05</Date>
<From>+6421000001</From>
<MessageText>This is a reply back from the mobile phone.</MessageText>
</SMSMessage>
<SMSMessage>
<Date>2021-07-26 10:42:29</Date>
<From>+6421000001</From>
<MessageText>This is a second reply.</MessageText>
</SMSMessage>
</SMSReceived>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<ErrorMessage>Message(s) NOT Found</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/received
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/get/sms/received \
--header "Content-Type: text/xml; encoding='utf-8'" "Accept: text/xml; encoding='utf-8'" \
--data '
<?xml version="1.0" encoding="UTF-8"?>
<SMSReceivedRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<TimePeriod>1440</TimePeriod>
</SMSReceivedRequest>
'
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<Data>
<SMSReceived>
<SMSMessage>
<Date>2021-07-26 10:41:05</Date>
<From>+6421000001</From>
<MessageText>This is a reply back from the mobile phone.</MessageText>
</SMSMessage>
<SMSMessage>
<Date>2021-07-26 10:42:29</Date>
<From>+6421000001</From>
<MessageText>This is a second reply.</MessageText>
</SMSMessage>
</SMSReceived>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<ErrorMessage>Message(s) NOT Found</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/received
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/get/sms/received \
--header "Content-Type: text/xml; encoding='utf-8'" "Accept: text/xml; encoding='utf-8'" \
--data '
<?xml version="1.0" encoding="UTF-8"?>
<SMSReceivedRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<TimePeriod>1440</TimePeriod>
</SMSReceivedRequest>
'
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<Data>
<SMSReceived>
<SMSMessage>
<Date>2021-07-26 10:41:05</Date>
<From>+6421000001</From>
<MessageText>This is a reply back from the mobile phone.</MessageText>
</SMSMessage>
<SMSMessage>
<Date>2021-07-26 10:42:29</Date>
<From>+6421000001</From>
<MessageText>This is a second reply.</MessageText>
</SMSMessage>
</SMSReceived>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<ErrorMessage>Message(s) NOT Found</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/received
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?php
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$timeperiod = "1440"; // required
$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><SMSReceivedRequest></SMSReceivedRequest>");
$data->addChild("Sender",$sender);
$data->addChild("APIKey",$apikey);
$data->addChild("TimePeriod",$timeperiod);
$headers = array(
"Content-Type: text/xml",
"Accept: text/xml",
"encoding='utf-8'",
"Content-length: ".strlen($data->asXML()),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/get/sms/received");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "400": // error
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "500": // critical error
echo $response."\n";
echo $err;
break;
default:
echo $response."\n";
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<Data>
<SMSReceived>
<SMSMessage>
<Date>2021-07-26 10:41:05</Date>
<From>+6421000001</From>
<MessageText>This is a reply back from the mobile phone.</MessageText>
</SMSMessage>
<SMSMessage>
<Date>2021-07-26 10:42:29</Date>
<From>+6421000001</From>
<MessageText>This is a second reply.</MessageText>
</SMSMessage>
</SMSReceived>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<ErrorMessage>Message(s) NOT Found</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/received
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?php
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$timeperiod = "1440"; // required
$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><SMSReceivedRequest></SMSReceivedRequest>");
$data->addChild("Sender",$sender);
$data->addChild("APIKey",$apikey);
$data->addChild("TimePeriod",$timeperiod);
$headers = array(
"Content-Type: text/xml",
"Accept: text/xml",
"encoding='utf-8'",
"Content-length: ".strlen($data->asXML()),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/get/sms/received");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "400": // error
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "500": // critical error
echo $response."\n";
echo $err;
break;
default:
echo $response."\n";
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<Data>
<SMSReceived>
<SMSMessage>
<Date>2021-07-26 10:41:05</Date>
<From>+6421000001</From>
<MessageText>This is a reply back from the mobile phone.</MessageText>
</SMSMessage>
<SMSMessage>
<Date>2021-07-26 10:42:29</Date>
<From>+6421000001</From>
<MessageText>This is a second reply.</MessageText>
</SMSMessage>
</SMSReceived>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<ErrorMessage>Message(s) NOT Found</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/received
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
namespace GetSMSReceivedXml
{
class Program
{
private static XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerText = val;
return workingNode;
}
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/get/sms/received";
string strSender = "application@domain.com";
string strAPIKey = "ta8wr7ymd";
string strTimePeriod = "1440"; // required
XmlDocument xmlDoc = new XmlDocument();
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null); // <?xml version="1.0" encoding="UTF-8"?>
xmlDoc.AppendChild(docNode);
XmlNode rootNode = xmlDoc.CreateElement("SMSReceivedRequest");
xmlDoc.AppendChild(rootNode);
rootNode.AppendChild(addChildNode(xmlDoc, "Sender", strSender));
rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", strAPIKey));
rootNode.AppendChild(addChildNode(xmlDoc, "TimePeriod", strTimePeriod));
XmlNode workingNode = xmlDoc.CreateElement("Sender");
//
// Send Raw XML Request
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "text/xml; encoding='utf-8'";
request.Accept = "text/xml; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
request.ContentLength = byteArray.Length;
Stream newStream = request.GetRequestStream(); //open connection
newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
newStream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<Data>
<SMSReceived>
<SMSMessage>
<Date>2021-07-26 10:41:05</Date>
<From>+6421000001</From>
<MessageText>This is a reply back from the mobile phone.</MessageText>
</SMSMessage>
<SMSMessage>
<Date>2021-07-26 10:42:29</Date>
<From>+6421000001</From>
<MessageText>This is a second reply.</MessageText>
</SMSMessage>
</SMSReceived>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<ErrorMessage>Message(s) NOT Found</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/received
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
namespace GetSMSReceivedXml
{
class Program
{
private static XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerText = val;
return workingNode;
}
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/get/sms/received";
string strSender = "application@domain.com";
string strAPIKey = "ta8wr7ymd";
string strTimePeriod = "1440"; // required
XmlDocument xmlDoc = new XmlDocument();
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null); // <?xml version="1.0" encoding="UTF-8"?>
xmlDoc.AppendChild(docNode);
XmlNode rootNode = xmlDoc.CreateElement("SMSReceivedRequest");
xmlDoc.AppendChild(rootNode);
rootNode.AppendChild(addChildNode(xmlDoc, "Sender", strSender));
rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", strAPIKey));
rootNode.AppendChild(addChildNode(xmlDoc, "TimePeriod", strTimePeriod));
XmlNode workingNode = xmlDoc.CreateElement("Sender");
//
// Send Raw XML Request
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "text/xml; encoding='utf-8'";
request.Accept = "text/xml; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
request.ContentLength = byteArray.Length;
Stream newStream = request.GetRequestStream(); //open connection
newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
newStream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<Data>
<SMSReceived>
<SMSMessage>
<Date>2021-07-26 10:41:05</Date>
<From>+6421000001</From>
<MessageText>This is a reply back from the mobile phone.</MessageText>
</SMSMessage>
<SMSMessage>
<Date>2021-07-26 10:42:29</Date>
<From>+6421000001</From>
<MessageText>This is a second reply.</MessageText>
</SMSMessage>
</SMSReceived>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<ErrorMessage>Message(s) NOT Found</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/received
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
import requests
import xml.etree.ElementTree as ET
url = "https://api.tnz.co.nz/api/v2.01/get/sms/received"
headers = {
"Content-Type": "text/xml",
"Accept": "text/xml",
"encoding": "utf-8"
}
root = ET.Element('SMSReceivedRequest')
ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "TimePeriod").text = "1440"
r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)
print(r)
print(r.text)
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<Data>
<SMSReceived>
<SMSMessage>
<Date>2021-07-26 10:41:05</Date>
<From>+6421000001</From>
<MessageText>This is a reply back from the mobile phone.</MessageText>
</SMSMessage>
<SMSMessage>
<Date>2021-07-26 10:42:29</Date>
<From>+6421000001</From>
<MessageText>This is a second reply.</MessageText>
</SMSMessage>
</SMSReceived>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<ErrorMessage>Message(s) NOT Found</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/received
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
import requests
import xml.etree.ElementTree as ET
url = "https://api.tnz.co.nz/api/v2.01/get/sms/received"
headers = {
"Content-Type": "text/xml",
"Accept": "text/xml",
"encoding": "utf-8"
}
root = ET.Element('SMSReceivedRequest')
ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "TimePeriod").text = "1440"
r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)
print(r)
print(r.text)
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<Data>
<SMSReceived>
<SMSMessage>
<Date>2021-07-26 10:41:05</Date>
<From>+6421000001</From>
<MessageText>This is a reply back from the mobile phone.</MessageText>
</SMSMessage>
<SMSMessage>
<Date>2021-07-26 10:42:29</Date>
<From>+6421000001</From>
<MessageText>This is a second reply.</MessageText>
</SMSMessage>
</SMSReceived>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<ErrorMessage>Message(s) NOT Found</ErrorMessage>
</root>
| Parameter | Example Value | Description | |
|---|---|---|---|
| Sender | application@domain.com | Sender value set up in Create a new API user token | |
| APIKey | ta8wr7ymd | APIKey value set up in Create a new API user token | |
| TimePeriod | 1440 | Return results from the last x minutes | |
| Parameter | Example Value | Description | |
|---|---|---|---|
| Result | Success | Result of your API call (not the result of the message) | |
| Date | 2019-12-01 14:02:03 | Date/Time SMS was received (yyyy-mm-dd HH:mm:ss) | |
| From | +6421000001 | Sender of the SMS in E.164 internationalised format | |
| MessageText | This is a reply back from the mobile phone. | The SMS message received | |
| Parameter | Example Value | Description | |
|---|---|---|---|
| Result | Failed | Result of your API call (not the result of the message) | |
| Message | Missing Sender | Reason for the API call failure (see a list of possible values: TNZ API Errors) | |
API users are able to poll for replies to a specific SMS message, tracked using the MessageID on the outbound message.
The GET Poll should be configured to timeout after 48 hours with no result.
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/reply
HTTP Header: Content-Type="application/json; encoding='utf-8'"
{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageID": "ID123456"
}
{
"Result": "Success",
"Data": {
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"Status": "Received",
"JobNum": "10AB20CD",
"Account": "Account#",
"SubAccount": "",
"Department": "",
"MessageSent": {
"Date": "2019-12-01 13:45:54",
"Destination": 6421000001,
"MessageText": "This is an outbound message sent via API."
},
"MessageReceived": [
{
"Date": "2019-12-01 14:02:03",
"From": "+6421000001",
"MessageText": "This is a reply back from the mobile phone."
},
{
"Date": "2019-12-01 14:04:14",
"From": "+6421000001",
"MessageText": "This is a second reply."
}
]
}
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/reply
HTTP Header: Content-Type="application/json; encoding='utf-8'"
{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageID": "ID123456"
}
{
"Result": "Success",
"Data": {
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"Status": "Received",
"JobNum": "10AB20CD",
"Account": "Account#",
"SubAccount": "",
"Department": "",
"MessageSent": {
"Date": "2019-12-01 13:45:54",
"Destination": 6421000001,
"MessageText": "This is an outbound message sent via API."
},
"MessageReceived": [
{
"Date": "2019-12-01 14:02:03",
"From": "+6421000001",
"MessageText": "This is a reply back from the mobile phone."
},
{
"Date": "2019-12-01 14:04:14",
"From": "+6421000001",
"MessageText": "This is a second reply."
}
]
}
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/reply
HTTP Header: Content-Type="application/json; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/get/sms/reply \
--header "Content-Type: application/json; encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageID": "ID123456"
}'
{
"Result": "Success",
"Data": {
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"Status": "Received",
"JobNum": "10AB20CD",
"Account": "Account#",
"SubAccount": "",
"Department": "",
"MessageSent": {
"Date": "2019-12-01 13:45:54",
"Destination": 6421000001,
"MessageText": "This is an outbound message sent via API."
},
"MessageReceived": [
{
"Date": "2019-12-01 14:02:03",
"From": "+6421000001",
"MessageText": "This is a reply back from the mobile phone."
},
{
"Date": "2019-12-01 14:04:14",
"From": "+6421000001",
"MessageText": "This is a second reply."
}
]
}
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/reply
HTTP Header: Content-Type="application/json; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/get/sms/reply \
--header "Content-Type: application/json; encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageID": "ID123456"
}'
{
"Result": "Success",
"Data": {
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"Status": "Received",
"JobNum": "10AB20CD",
"Account": "Account#",
"SubAccount": "",
"Department": "",
"MessageSent": {
"Date": "2019-12-01 13:45:54",
"Destination": 6421000001,
"MessageText": "This is an outbound message sent via API."
},
"MessageReceived": [
{
"Date": "2019-12-01 14:02:03",
"From": "+6421000001",
"MessageText": "This is a reply back from the mobile phone."
},
{
"Date": "2019-12-01 14:04:14",
"From": "+6421000001",
"MessageText": "This is a second reply."
}
]
}
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/reply
HTTP Header: Content-Type="application/json; encoding='utf-8'"
<?php
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$message_id = "ID123456"; // required
$data = array(
"Sender" => $sender,
"APIKey" => $apikey,
"MessageID" => $message_id
);
$headers = array(
"Content-Type: application/json",
"encoding='utf-8'",
"Content-length: ".strlen(json_encode($data)),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/get/sms/reply");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header('Content-Type: application/json');
echo $response;
break;
case "400": // error
header('Content-Type: application/json');
echo $response;
break;
case "500": // critical error
echo $response;
echo $err;
break;
default:
echo $response;
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
{
"Result": "Success",
"Data": {
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"Status": "Received",
"JobNum": "10AB20CD",
"Account": "Account#",
"SubAccount": "",
"Department": "",
"MessageSent": {
"Date": "2019-12-01 13:45:54",
"Destination": 6421000001,
"MessageText": "This is an outbound message sent via API."
},
"MessageReceived": [
{
"Date": "2019-12-01 14:02:03",
"From": "+6421000001",
"MessageText": "This is a reply back from the mobile phone."
},
{
"Date": "2019-12-01 14:04:14",
"From": "+6421000001",
"MessageText": "This is a second reply."
}
]
}
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/reply
HTTP Header: Content-Type="application/json; encoding='utf-8'"
<?php
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$message_id = "ID123456"; // required
$data = array(
"Sender" => $sender,
"APIKey" => $apikey,
"MessageID" => $message_id
);
$headers = array(
"Content-Type: application/json",
"encoding='utf-8'",
"Content-length: ".strlen(json_encode($data)),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/get/sms/reply");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header('Content-Type: application/json');
echo $response;
break;
case "400": // error
header('Content-Type: application/json');
echo $response;
break;
case "500": // critical error
echo $response;
echo $err;
break;
default:
echo $response;
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
{
"Result": "Success",
"Data": {
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"Status": "Received",
"JobNum": "10AB20CD",
"Account": "Account#",
"SubAccount": "",
"Department": "",
"MessageSent": {
"Date": "2019-12-01 13:45:54",
"Destination": 6421000001,
"MessageText": "This is an outbound message sent via API."
},
"MessageReceived": [
{
"Date": "2019-12-01 14:02:03",
"From": "+6421000001",
"MessageText": "This is a reply back from the mobile phone."
},
{
"Date": "2019-12-01 14:04:14",
"From": "+6421000001",
"MessageText": "This is a second reply."
}
]
}
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/reply
HTTP Header: Content-Type="application/json; encoding='utf-8'"
using System;
using System.Text;
using System.IO;
using System.Net;
namespace TNZ
{
class Program
{
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/get/sms/reply";
//
// Send TTS by REST API Interface
//
string strJSONData = $@"{{
""Sender"": ""application@domain.com"",
""APIKey"": ""ta8wr7ymd"",
""MessageID"": ""ID123456"",
}}";
//
// Send API Request to REST API
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/json; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
request.ContentLength = byteArray.Length;
Stream stream = request.GetRequestStream(); //open connection
stream.Write(byteArray, 0, byteArray.Length); // Send the data.
stream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
{
"Result": "Success",
"Data": {
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"Status": "Received",
"JobNum": "10AB20CD",
"Account": "Account#",
"SubAccount": "",
"Department": "",
"MessageSent": {
"Date": "2019-12-01 13:45:54",
"Destination": 6421000001,
"MessageText": "This is an outbound message sent via API."
},
"MessageReceived": [
{
"Date": "2019-12-01 14:02:03",
"From": "+6421000001",
"MessageText": "This is a reply back from the mobile phone."
},
{
"Date": "2019-12-01 14:04:14",
"From": "+6421000001",
"MessageText": "This is a second reply."
}
]
}
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/reply
HTTP Header: Content-Type="application/json; encoding='utf-8'"
using System;
using System.Text;
using System.IO;
using System.Net;
namespace TNZ
{
class Program
{
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/get/sms/reply";
//
// Send TTS by REST API Interface
//
string strJSONData = $@"{{
""Sender"": ""application@domain.com"",
""APIKey"": ""ta8wr7ymd"",
""MessageID"": ""ID123456"",
}}";
//
// Send API Request to REST API
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/json; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
request.ContentLength = byteArray.Length;
Stream stream = request.GetRequestStream(); //open connection
stream.Write(byteArray, 0, byteArray.Length); // Send the data.
stream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
{
"Result": "Success",
"Data": {
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"Status": "Received",
"JobNum": "10AB20CD",
"Account": "Account#",
"SubAccount": "",
"Department": "",
"MessageSent": {
"Date": "2019-12-01 13:45:54",
"Destination": 6421000001,
"MessageText": "This is an outbound message sent via API."
},
"MessageReceived": [
{
"Date": "2019-12-01 14:02:03",
"From": "+6421000001",
"MessageText": "This is a reply back from the mobile phone."
},
{
"Date": "2019-12-01 14:04:14",
"From": "+6421000001",
"MessageText": "This is a second reply."
}
]
}
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/reply
HTTP Header: Content-Type="application/json; encoding='utf-8'"
import requests
import json
url = "https://api.tnz.co.nz/api/v2.01/get/sms/reply"
headers = {
"Content-Type": "application/json",
"encoding": "utf-8"
}
data = {
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageID" : "ID123456"
}
r = requests.post(url, data=json.dumps(data), headers=headers)
print(r)
print(r.text)
{
"Result": "Success",
"Data": {
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"Status": "Received",
"JobNum": "10AB20CD",
"Account": "Account#",
"SubAccount": "",
"Department": "",
"MessageSent": {
"Date": "2019-12-01 13:45:54",
"Destination": 6421000001,
"MessageText": "This is an outbound message sent via API."
},
"MessageReceived": [
{
"Date": "2019-12-01 14:02:03",
"From": "+6421000001",
"MessageText": "This is a reply back from the mobile phone."
},
{
"Date": "2019-12-01 14:04:14",
"From": "+6421000001",
"MessageText": "This is a second reply."
}
]
}
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/reply
HTTP Header: Content-Type="application/json; encoding='utf-8'"
import requests
import json
url = "https://api.tnz.co.nz/api/v2.01/get/sms/reply"
headers = {
"Content-Type": "application/json",
"encoding": "utf-8"
}
data = {
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageID" : "ID123456"
}
r = requests.post(url, data=json.dumps(data), headers=headers)
print(r)
print(r.text)
{
"Result": "Success",
"Data": {
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"Status": "Received",
"JobNum": "10AB20CD",
"Account": "Account#",
"SubAccount": "",
"Department": "",
"MessageSent": {
"Date": "2019-12-01 13:45:54",
"Destination": 6421000001,
"MessageText": "This is an outbound message sent via API."
},
"MessageReceived": [
{
"Date": "2019-12-01 14:02:03",
"From": "+6421000001",
"MessageText": "This is a reply back from the mobile phone."
},
{
"Date": "2019-12-01 14:04:14",
"From": "+6421000001",
"MessageText": "This is a second reply."
}
]
}
}
{
"Result": "Failed",
"MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
"ErrorMessage": "Missing Sender"
}
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/reply
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?xml version="1.0" encoding="UTF-8"?>
<SMSReplyRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageID>ID123456</MessageID>
</SMSReplyRequest>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<JobNum>10AB20CD</JobNum>
<Account>Account</Account>
<SubAccount></SubAccount>
<Department></Department>
<SMSSent>
<Date>2021-07-25 11:02:05</Date>
<Destination>+6421000001</Destination>
<MessageText>This is an outbound message sent via API.</MessageText>
</SMSSent>
<SMSReceived>
<SMSMessage>
<Date>2021-07-26 10:41:05</Date>
<From>+6421000001</From>
<MessageText>This is a reply back from the mobile phone.</MessageText>
</SMSMessage>
<SMSMessage>
<Date>2021-07-26 10:42:29</Date>
<From>+6421000001</From>
<MessageText>This is a second reply.</MessageText>
</SMSMessage>
</SMSReceived>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Unable to find message sent.</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/reply
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?xml version="1.0" encoding="UTF-8"?>
<SMSReplyRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageID>ID123456</MessageID>
</SMSReplyRequest>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<JobNum>10AB20CD</JobNum>
<Account>Account</Account>
<SubAccount></SubAccount>
<Department></Department>
<SMSSent>
<Date>2021-07-25 11:02:05</Date>
<Destination>+6421000001</Destination>
<MessageText>This is an outbound message sent via API.</MessageText>
</SMSSent>
<SMSReceived>
<SMSMessage>
<Date>2021-07-26 10:41:05</Date>
<From>+6421000001</From>
<MessageText>This is a reply back from the mobile phone.</MessageText>
</SMSMessage>
<SMSMessage>
<Date>2021-07-26 10:42:29</Date>
<From>+6421000001</From>
<MessageText>This is a second reply.</MessageText>
</SMSMessage>
</SMSReceived>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Unable to find message sent.</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/reply
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/get/sms/reply \
--header "Content-Type: text/xml; encoding='utf-8'" "Accept: text/xml; encoding='utf-8'" \
--data '
<?xml version="1.0" encoding="UTF-8"?>
<SMSReplyRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageID>ID123456</MessageID>
</SMSReplyRequest>
'
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<JobNum>10AB20CD</JobNum>
<Account>Account</Account>
<SubAccount></SubAccount>
<Department></Department>
<SMSSent>
<Date>2021-07-25 11:02:05</Date>
<Destination>+6421000001</Destination>
<MessageText>This is an outbound message sent via API.</MessageText>
</SMSSent>
<SMSReceived>
<SMSMessage>
<Date>2021-07-26 10:41:05</Date>
<From>+6421000001</From>
<MessageText>This is a reply back from the mobile phone.</MessageText>
</SMSMessage>
<SMSMessage>
<Date>2021-07-26 10:42:29</Date>
<From>+6421000001</From>
<MessageText>This is a second reply.</MessageText>
</SMSMessage>
</SMSReceived>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Unable to find message sent.</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/reply
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
curl --request POST \
--url https://api.tnz.co.nz/api/v2.01/get/sms/reply \
--header "Content-Type: text/xml; encoding='utf-8'" "Accept: text/xml; encoding='utf-8'" \
--data '
<?xml version="1.0" encoding="UTF-8"?>
<SMSReplyRequest>
<Sender>application@domain.com</Sender>
<APIKey>ta8wr7ymd</APIKey>
<MessageID>ID123456</MessageID>
</SMSReplyRequest>
'
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<JobNum>10AB20CD</JobNum>
<Account>Account</Account>
<SubAccount></SubAccount>
<Department></Department>
<SMSSent>
<Date>2021-07-25 11:02:05</Date>
<Destination>+6421000001</Destination>
<MessageText>This is an outbound message sent via API.</MessageText>
</SMSSent>
<SMSReceived>
<SMSMessage>
<Date>2021-07-26 10:41:05</Date>
<From>+6421000001</From>
<MessageText>This is a reply back from the mobile phone.</MessageText>
</SMSMessage>
<SMSMessage>
<Date>2021-07-26 10:42:29</Date>
<From>+6421000001</From>
<MessageText>This is a second reply.</MessageText>
</SMSMessage>
</SMSReceived>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Unable to find message sent.</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/reply
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?php
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$message_id = "ID123456"; // required
$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><SMSReplyRequest></SMSReplyRequest>");
$data->addChild("Sender",$sender);
$data->addChild("APIKey",$apikey);
$data->addChild("MessageID",$message_id);
$headers = array(
"Content-Type: text/xml",
"Accept: text/xml",
"encoding='utf-8'",
"Content-length: ".strlen($data->asXML()),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/get/sms/reply");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "400": // error
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "500": // critical error
echo $response."\n";
echo $err;
break;
default:
echo $response."\n";
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<JobNum>10AB20CD</JobNum>
<Account>Account</Account>
<SubAccount></SubAccount>
<Department></Department>
<SMSSent>
<Date>2021-07-25 11:02:05</Date>
<Destination>+6421000001</Destination>
<MessageText>This is an outbound message sent via API.</MessageText>
</SMSSent>
<SMSReceived>
<SMSMessage>
<Date>2021-07-26 10:41:05</Date>
<From>+6421000001</From>
<MessageText>This is a reply back from the mobile phone.</MessageText>
</SMSMessage>
<SMSMessage>
<Date>2021-07-26 10:42:29</Date>
<From>+6421000001</From>
<MessageText>This is a second reply.</MessageText>
</SMSMessage>
</SMSReceived>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Unable to find message sent.</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/reply
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
<?php
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$message_id = "ID123456"; // required
$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><SMSReplyRequest></SMSReplyRequest>");
$data->addChild("Sender",$sender);
$data->addChild("APIKey",$apikey);
$data->addChild("MessageID",$message_id);
$headers = array(
"Content-Type: text/xml",
"Accept: text/xml",
"encoding='utf-8'",
"Content-length: ".strlen($data->asXML()),
"Connection: close"
);
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.tnz.co.nz/api/v2.01/get/sms/reply");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$err = "";
if(curl_errno($ch))
{
$err = curl_error($ch);
}
else
{
curl_close($ch);
}
switch( $info['http_code'] )
{
case "200": // success;
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "400": // error
header("Content-Type: text/xml; encoding='utf-8'");
echo $response;
break;
case "500": // critical error
echo $response."\n";
echo $err;
break;
default:
echo $response."\n";
echo $err;
break;
}
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage();
}
?>
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<JobNum>10AB20CD</JobNum>
<Account>Account</Account>
<SubAccount></SubAccount>
<Department></Department>
<SMSSent>
<Date>2021-07-25 11:02:05</Date>
<Destination>+6421000001</Destination>
<MessageText>This is an outbound message sent via API.</MessageText>
</SMSSent>
<SMSReceived>
<SMSMessage>
<Date>2021-07-26 10:41:05</Date>
<From>+6421000001</From>
<MessageText>This is a reply back from the mobile phone.</MessageText>
</SMSMessage>
<SMSMessage>
<Date>2021-07-26 10:42:29</Date>
<From>+6421000001</From>
<MessageText>This is a second reply.</MessageText>
</SMSMessage>
</SMSReceived>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Unable to find message sent.</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/reply
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
namespace GetSMSReplyXml
{
class Program
{
private static XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerText = val;
return workingNode;
}
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/get/sms/reply";
string strSender = "application@domain.com";
string strAPIKey = "ta8wr7ymd";
string strMessageID = "ID123456"; // required
XmlDocument xmlDoc = new XmlDocument();
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null); // <?xml version="1.0" encoding="UTF-8"?>
xmlDoc.AppendChild(docNode);
XmlNode rootNode = xmlDoc.CreateElement("SMSReplyRequest");
xmlDoc.AppendChild(rootNode);
rootNode.AppendChild(addChildNode(xmlDoc, "Sender", strSender));
rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", strAPIKey));
rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", strMessageID));
XmlNode workingNode = xmlDoc.CreateElement("Sender");
//
// Send Raw XML Request
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "text/xml; encoding='utf-8'";
request.Accept = "text/xml; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
request.ContentLength = byteArray.Length;
Stream newStream = request.GetRequestStream(); //open connection
newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
newStream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<JobNum>10AB20CD</JobNum>
<Account>Account</Account>
<SubAccount></SubAccount>
<Department></Department>
<SMSSent>
<Date>2021-07-25 11:02:05</Date>
<Destination>+6421000001</Destination>
<MessageText>This is an outbound message sent via API.</MessageText>
</SMSSent>
<SMSReceived>
<SMSMessage>
<Date>2021-07-26 10:41:05</Date>
<From>+6421000001</From>
<MessageText>This is a reply back from the mobile phone.</MessageText>
</SMSMessage>
<SMSMessage>
<Date>2021-07-26 10:42:29</Date>
<From>+6421000001</From>
<MessageText>This is a second reply.</MessageText>
</SMSMessage>
</SMSReceived>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Unable to find message sent.</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/reply
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
namespace GetSMSReplyXml
{
class Program
{
private static XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerText = val;
return workingNode;
}
static void Main(string[] args)
{
string apiURL = "https://api.tnz.co.nz/api/v2.01/get/sms/reply";
string strSender = "application@domain.com";
string strAPIKey = "ta8wr7ymd";
string strMessageID = "ID123456"; // required
XmlDocument xmlDoc = new XmlDocument();
XmlNode docNode = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null); // <?xml version="1.0" encoding="UTF-8"?>
xmlDoc.AppendChild(docNode);
XmlNode rootNode = xmlDoc.CreateElement("SMSReplyRequest");
xmlDoc.AppendChild(rootNode);
rootNode.AppendChild(addChildNode(xmlDoc, "Sender", strSender));
rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", strAPIKey));
rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", strMessageID));
XmlNode workingNode = xmlDoc.CreateElement("Sender");
//
// Send Raw XML Request
//
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(apiURL);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "text/xml; encoding='utf-8'";
request.Accept = "text/xml; encoding='utf-8'";
byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
request.ContentLength = byteArray.Length;
Stream newStream = request.GetRequestStream(); //open connection
newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
newStream.Close();
string strResponse = "";
//
// More code to handle 400 Bad Request errors
//
try
{
using (var response = request.GetResponse() as HttpWebResponse)
{
if (request.HaveResponse && response != null)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (WebException wex)
{
if (wex.Response != null)
{
using (var errorResponse = (HttpWebResponse)wex.Response)
{
using (var reader = new StreamReader(errorResponse.GetResponseStream()))
{
strResponse = reader.ReadToEnd();
}
}
}
}
Console.WriteLine(strResponse);
Console.ReadLine();
}
}
}
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<JobNum>10AB20CD</JobNum>
<Account>Account</Account>
<SubAccount></SubAccount>
<Department></Department>
<SMSSent>
<Date>2021-07-25 11:02:05</Date>
<Destination>+6421000001</Destination>
<MessageText>This is an outbound message sent via API.</MessageText>
</SMSSent>
<SMSReceived>
<SMSMessage>
<Date>2021-07-26 10:41:05</Date>
<From>+6421000001</From>
<MessageText>This is a reply back from the mobile phone.</MessageText>
</SMSMessage>
<SMSMessage>
<Date>2021-07-26 10:42:29</Date>
<From>+6421000001</From>
<MessageText>This is a second reply.</MessageText>
</SMSMessage>
</SMSReceived>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Unable to find message sent.</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/reply
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
import requests
import xml.etree.ElementTree as ET
url = "https://api.tnz.co.nz/api/v2.01/get/sms/reply"
headers = {
"Content-Type": "text/xml",
"Accept": "text/xml",
"encoding": "utf-8"
}
root = ET.Element('SMSReplyRequest')
ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "MessageID").text = "ID123456"
r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)
print(r)
print(r.text)
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<JobNum>10AB20CD</JobNum>
<Account>Account</Account>
<SubAccount></SubAccount>
<Department></Department>
<SMSSent>
<Date>2021-07-25 11:02:05</Date>
<Destination>+6421000001</Destination>
<MessageText>This is an outbound message sent via API.</MessageText>
</SMSSent>
<SMSReceived>
<SMSMessage>
<Date>2021-07-26 10:41:05</Date>
<From>+6421000001</From>
<MessageText>This is a reply back from the mobile phone.</MessageText>
</SMSMessage>
<SMSMessage>
<Date>2021-07-26 10:42:29</Date>
<From>+6421000001</From>
<MessageText>This is a second reply.</MessageText>
</SMSMessage>
</SMSReceived>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Unable to find message sent.</ErrorMessage>
</root>
API URL: https://api.tnz.co.nz/api/v2.01/get/sms/reply
HTTP Header: Content-Type="text/xml; encoding='utf-8'"
Accept="text/xml; encoding='utf-8'"
import requests
import xml.etree.ElementTree as ET
url = "https://api.tnz.co.nz/api/v2.01/get/sms/reply"
headers = {
"Content-Type": "text/xml",
"Accept": "text/xml",
"encoding": "utf-8"
}
root = ET.Element('SMSReplyRequest')
ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "MessageID").text = "ID123456"
r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)
print(r)
print(r.text)
<?xml version="1.0"?>
<root>
<Result>Success</Result>
<MessageID>ID123456</MessageID>
<Data>
<JobNum>10AB20CD</JobNum>
<Account>Account</Account>
<SubAccount></SubAccount>
<Department></Department>
<SMSSent>
<Date>2021-07-25 11:02:05</Date>
<Destination>+6421000001</Destination>
<MessageText>This is an outbound message sent via API.</MessageText>
</SMSSent>
<SMSReceived>
<SMSMessage>
<Date>2021-07-26 10:41:05</Date>
<From>+6421000001</From>
<MessageText>This is a reply back from the mobile phone.</MessageText>
</SMSMessage>
<SMSMessage>
<Date>2021-07-26 10:42:29</Date>
<From>+6421000001</From>
<MessageText>This is a second reply.</MessageText>
</SMSMessage>
</SMSReceived>
</Data>
</root>
<?xml version="1.0"?>
<root>
<Result>Failed</Result>
<MessageID>ID123456</MessageID>
<ErrorMessage>Unable to find message sent.</ErrorMessage>
</root>
| Parameter | Example Value | Description | |
|---|---|---|---|
| Sender | application@domain.com | Sender value set up in Create a new API user token | |
| APIKey | ta8wr7ymd | APIKey value set up in Create a new API user token | |
| MessageID | ID123456 | Your provided Message ID or TNZ Group generated Message ID | |
| Parameter | Example Value | Description | |
|---|---|---|---|
| Result | Success | Result of your API call (not the result of the message) | |
| Status | Received | Static value | |
| JobNum | 10AB20CE | Eight digit alphanumeric tracking number (our internal Job Number) | |
| Account | 102030 | Your TNZ Account | |
| SubAccount | Your supplied TNZ SubAccount | ||
| Department | Your supplied TNZ Department | ||
| MessageSent | Date | 2019-12-01 13:45:54 | Time SMS was sent (yyyy-mm-dd HH:mm:ss) |
| Destination | 6421000001 | Recipient of the SMS in E.164 internationalised format | |
| MessageText | This is an outbound message sent via API. | Plain or UTF-8 formatted SMS message sent | |
| MessageReceived | Date | 2019-12-01 14:02:03 | Time SMS was received (yyyy-mm-dd HH:mm:ss) |
| From | +6421000001 | Sender of the SMS in E.164 internationalised format | |
| MessageText | This is a reply back from the mobile phone. | Plain or UTF-8 formatted SMS message received | |
| Parameter | Example Value | Description | |
|---|---|---|---|
| Result | Failed | Result of your API call (not the result of the message) | |
| MessageID | AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD | Your provided Message ID or TNZ Group generated Message ID | |
| Message | Missing Sender | Reason for the API call failure (see a list of possible values: TNZ API Errors) | |
When a new version of the API is released, the APIVersion url parameter is incremented.
This allows you to use a different API version based on the API URL, limiting the testing you require should you wish to update one API URL to a later version of the API.
Want to upgrade to a new version for SMS but don't want to break and retest Email? Use the newer APIVersion for SMS while using the older APIVersion for Email.
https://api.tnz.co.nz/api/v2.01/send/email
https://api.tnz.co.nz/api/v2.00/send/email
As new versions of the API are released, this API reference guide will be updated to reflect the latest version and features supported:
API Version ChangeLog