Last updated: May 14th 2020

API Introduction

This API is designed to be as flexible as possible.
Using just one API, your software will be configured for sending various types of messages. The MessageType parameter specifies which type of message is sent (eg Email).

If you don't have an account, you'll need to register one.

Learn more...

You'll need a new Sender/APIKey combo for your application.

Learn more...

The API is REST based. Requests can be submitted in JSON or XML.

Learn more...

The API URL is: https://www.tnz.co.nz/api
The base parameters are simply: Sender, APIKey, APIVersion, MessageType, MessageData. Depending on the 'MessageType', additional parameters are specified inside 'MessageData'.

Learn more...

There are specific variables dedicated to each 'MessageType'. These are specified on a message-by-message basis.

Learn more...

Delivery Reports can be provided via a Webhook to your URL, Email, or viewed with the Web Dashboard.

Learn more...

Submitted messages can be retried using the Web Dashboard, or by submitting a new API request.

Learn more...

Specify the SendMode parameter in your message object to skip message delivery. The message will be accepted and processed with a simulated delivery result displayed.

Learn more...

Register your account

Head to https://www.tnz.co.nz/Customer/SignUp to create a new account.

A test account is possible, however creating a commerical account and using the Mode=Test function of the API is simpler to use when you’re ready to push your application live.

After completing the sign up form, a sales consultant will manually activate your account. This may take one business day. Once the account has been activated, you will be able to Create a new API user token.


Create a new API user token

Using the API will require a Sender and APIKey pair to authenticate with the API.

You can generate this using the Web Dashboard under: Users | Outbound Users | Create
User Email Address = Sender
User Token = APIKey


Understanding the API basics

The API is designed to be as flexible as possible. This means you can use the same API URL to send a variety of message types.

Base REST URL:
https://www.tnz.co.nz/api/

Request Formatting Type:
The formatting of the request is specified in the URL.

Send outbound message using raw JSON: https://www.tnz.co.nz/api/json/send/
Send outbound message using raw XML: https://www.tnz.co.nz/api/xml/send/

MessageType:
The type of message being sent is specified in the MessageType parameter.

Send email using raw JSON:
https://www.tnz.co.nz/api/json/send/

"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageType": "Email",
"APIVersion": "1.04",
"MessageID": "ID123456",
"MessageData" : %%


Send SMS using raw JSON:
https://www.tnz.co.nz/api/json/send/

"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageType": "SMS",
"APIVersion": "1.04",
"MessageID": "ID123456",
"MessageData" : %%


API - Send Messages - the base API URL

The base parameters are: Sender, APIKey, APIVersion, MessageType, MessageData


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
APIVersion 1.04 Version of the API used; can differ based on MessageType
MessageID
(Optional)
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)
MessageType Email Available message types referenced in Adding variables based on the MessageType, eg Email, Fax, SMS, Voice, TextToSpeech
MessageData %Variable% String of values based on the MessageType referenced in Adding variables to MessageData based on MessageType

The possible POST response values are:
  200 OK, Job %JOBNUMBER%
  400 BAD REQUEST, %ERROR REASON%
  500 Internal Server Error


MessageType=Email - Send Email via REST API

 
 
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "MessageType": "Email",
    "APIVersion": "1.04",
    "MessageData" :
    {
        "EmailSubject": "Test Email Subject",
        "MessagePlain": "Hello, This is a test message. Thank you.",
        "Destinations" : 
        [
            "recipient.four@example.com"
        ]
    }
}                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "MessageType": "Email",
    "APIVersion": "1.04",
    "MessageID": "ID123456",
    "MessageData" :
    {
        "Reference": "Test1",
        "SendTime": "",
        "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": "recipient.one@example.com",
                "Attention": "Recipient One",
                "Company": "Example Corp",
                "Custom1": "",
                "Custom2": ""
            },
            "recipient.two@example.com",
            "recipient.three@example.com",
            "recipient.four@example.com"
        ],
        "Files":
        [
            {
                "Name": "Sample.pdf",
                "Data": "%%BASE-64 CONTENT%%"
            },
            {
                "Name": "Sample2.pdf",
                "Data": "%%BASE-64 CONTENT%%"
            }
        ]
    }
}                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "ID123456"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/json/send \
  --header "Content-Type: application/json; encoding='utf-8'" \
  --data '{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "MessageType": "Email",
    "APIVersion": "1.04",
    "MessageData" :
    {
        "EmailSubject": "Test Email Subject",
        "MessagePlain": "Hello, This is a test message. Thank you.",
        "Destinations" : 
        [
            "recipient.four@example.com"
        ]
    }
  }'                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/json/send \
  --header "Content-Type: application/json; encoding='utf-8'" \
  --data '{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "MessageType": "Email",
    "APIVersion": "1.04",
    "MessageID": "ID123456",
    "MessageData" :
    {
        "Reference": "Test1",
        "SendTime": "",
        "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": "recipient.one@example.com",
                "Attention": "Recipient One",
                "Company": "Example Corp",
                "Custom1": "",
                "Custom2": ""
            },
            "recipient.two@example.com",
            "recipient.three@example.com",
            "recipient.four@example.com"
        ],
        "Files":
        [
            {
                "Name": "Sample.pdf",
                "Data": "%%BASE-64 CONTENT%%"
            },
            {
                "Name": "Sample2.pdf",
                "Data": "%%BASE-64 CONTENT%%"
            }
        ]       
    }
  }'                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "ID123456"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

<?php

$data = array(
    "Sender" => "application@domain.com", // your user id
    "APIKey" => "ta8wr7ymd",              // your api key
    "MessageType" => "Email",
    "APIVersion" => "1.04",
    "MessageData" => array(
        "EmailSubject" => "Test Email Subject",
        "MessagePlain" => "Hello, This is a test message. Thank you.",
        "Destinations" => array(
            "recipient.four@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://www.tnz.co.nz/api/json/send");
    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();
}

?>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

<?php

$sender = "application@domain.com"; // your user id
$apikey = "ta8wr7ymd";              // your api key
$type = "Email";
$version = "1.04";
$message_id = "ID123456";           //optional

$file1 = "Sample.pdf";
$file2 = "Sample2.pdf";

if( file_exsits($file1) )
{
    $fp = fopen($file1,"r");
    $file_content1 = fread($fp,filesize($file1));
    fclose($fp);
}

if( file_exists($file2) )
{
    $fp = fopen($file2,"r");
    $file_content2 = fread($fp,filesize($file2));
    fclose($fp);
}

$data = array(
    "Sender" => $sender,
    "APIKey" => $apikey,
    "MessageType" => $type,
    "APIVersion" => $version,
    "MessageID" => $message_id,
    "MessageData" => array(
        "Reference" => "Test1",
        "SendTime" => "",
        "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" => "recipient.one@example.com", "Attention" => "Recipient One", "Company" => "Example Corp", "Custom1" => "", "Custom2" => "" ), "recipient.two@example.com", "recipient.three@example.com", "recipient.four@example.com" ), "Files" => array( array( "Name" => $file1, "Data" => base64_encode($file_content1) ), array( "Name" => $file2, "Data" => base64_encode($file_content2) ) ), ) ); $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://www.tnz.co.nz/api/json/send"); 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(); } ?>

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "ID123456"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

using System;
using System.Text;

using System.IO;
using System.Net;

namespace EmailSimple
{
    class Program
    {
        static void Main(string[] args)
        {
            string apiURL = "https://www.tnz.co.nz/api/json/send";

            //
            // Build JSON Data
            //

            string strJSONData = @"{
                ""Sender"": ""application@domain.com"",
                ""APIKey"": ""ta8wr7ymd"",
                ""MessageType"": ""Email"",
                ""APIVersion"": ""1.04"",
                ""MessageData"": {
                    ""EmailSubject"": ""Test Email Subject"",
                    ""MessagePlain"": ""Hello, This is a test message. Thank you."",
                    ""Destinations"":
                    [
                        ""recipient@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 = "";

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            using (StreamReader sr = new StreamReader(response.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }

            Console.WriteLine(strResponse);
        }
    }
}
                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

using System;
using System.Text;

using System.IO;
using System.Net;

namespace EmailAdvanced
{
    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://www.tnz.co.nz/api/json/send";

            string file1 = "C:\\File1.pdf";
            string file2 = "C:\\File2.pdf";

            string file1_data = GetFileContents(file1);
            string file2_data = GetFileContents(file2);

            //
            // Build JSON Data
            //

            string strJSONData = $@"{{
                ""Sender"": ""application@domain.com"",
                ""APIKey"": ""ta8wr7ymd"",
                ""MessageType"": ""Email"",
                ""APIVersion"": ""1.04"",
                ""MessageID"": ""ID123456"",
                ""MessageData"": {{
                    ""Reference"": ""Test1"",
                    ""SendTime"": """",
                    ""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"": ""recipient.one @example.com"",
                            ""Attention"": ""Recipient One"",
                            ""Company"": ""Example Corp""
                        }},
                        ""recipient.two@example.com"",
                        ""recipient.three@example.com"",
                        ""recipient.four@example.com""
                    ],
                    ""Files"":
                    [
                        {{
                            ""Name"": ""File1.pdf"",
                            ""Data"": ""{file1_data}""
                        }},
                        {{
                            ""Name"": ""File2.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);
        }
    }
}
                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "ID123456"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

import requests
import json

url = "https://www.tnz.co.nz/api/json/send/"

headers = {
    "Content-Type": "application/json",
    "encoding": "utf-8"
}

data = {
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "MessageType": "Email",
    "APIVersion": "1.04",
    "MessageData" :
    {
        "EmailSubject" : "Test Email Subject",
        "MessagePlain" : "Hello, This is a test message. Thank you.",
        "Destinations" : 
        [
            "recipient.four@example.com"
        ]
    }
}

r = requests.post(url, data=json.dumps(data), headers=headers)

print(r)
print(r.text)                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

import requests
import base64
import json

url = "https://www.tnz.co.nz/api/json/send/"

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",
    "MessageType": "Email",
    "APIVersion": "1.04",
    "MessageID": "ID123456",
    "MessageData" :
    {
        "Reference": "Test1",
        "SendTime": "",
        "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" : [ { "Recipient": "recipient.one@example.com", "Attention": "Recipient One", "Company": "Example Corp", "Custom1": "", "Custom2": "" }, "recipient.two@example.com", "recipient.three@example.com", "recipient.four@example.com" ], "Files" : [ { "Name": "File1.pdf", "Data": file_data } ] } } r = requests.post(url, data=json.dumps(data), headers=headers) print(r) print(r.text)

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "ID123456"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <Sender>application@domain.com</Sender>
  <APIKey>ta8wr7ymd</APIKey>
  <MessageType>Email</MessageType>
  <APIVersion>1.04</APIVersion>
  <MessageData>
    <EmailSubject>Test Email Subject</EmailSubject>
    <MessagePlain>Hello, This is a test message. Thank you.</MessagePlain>
    <Destinations>recipient.one@example.com</Destinations>
  </MessageData>
</root>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <Sender>application@domain.com</Sender>
  <APIKey>ta8wr7ymd</APIKey>
  <MessageType>Email</MessageType>
  <APIVersion>1.04</APIVersion>
  <MessageID>ID123456</MessageID>
  <MessageData>
    <Reference>Test1</Reference>
    <SendTime></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>
        <Recipient>recipient.one@example.com</Recipient>
        <Attention>Recipient One</Attention>
        <Company>Example Corp</Company>
        <Custom1></Custom1>
        <Custom2></Custom2>
    </Destinations>
    <Destinations>recipient.two@example.com</Destinations>
    <Destinations>recipient.three@example.com</Destinations>
    <Destinations>recipient.four@example.com</Destinations>
    <Files>
        <Name>Sample.pdf</Name>
        <Data>%%BASE-64 CONTENT%%</Data>
    </Files>
    <Files>
        <Name>Sample2.pdf</Name>
        <Data>%%BASE-64 CONTENT%%</Data>
    </Files>    
  </MessageData>
</root>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>ID123456</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/xml/send \
  --header "Content-Type: text/xml; encoding='utf-8'" \
  --data '
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
      <Sender>application@domain.com</Sender>
      <APIKey>ta8wr7ymd</APIKey>
      <MessageType>Email</MessageType>
      <APIVersion>1.04</APIVersion>
      <MessageData>
        <EmailSubject>Test Email Subject</EmailSubject>
        <MessagePlain>Hello, This is a test message. Thank you.</MessagePlain>
        <Destinations>recipient@example.com</Destinations>
      </MessageData>
    </root>
  '                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/xml/send \
  --header "Content-Type: text/xml; encoding='utf-8'" \
  --data '
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
      <Sender>application@domain.com</Sender>
      <APIKey>ta8wr7ymd</APIKey>
      <MessageType>Email</MessageType>
      <APIVersion>1.04</APIVersion>
      <MessageID>ID123456</MessageID>
      <MessageData>
        <Reference>Test1</Reference>
        <SendTime></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>
            <Recipient>recipient.one@example.com</Recipient>
            <Attention>Recipient One</Attention>
            <Company>Example Corp</Company>
            <Custom1></Custom1>
            <Custom2></Custom2>
        </Destinations>
        <Destinations>recipient.two@example.com</Destinations>
        <Destinations>recipient.three@example.com</Destinations>
        <Destinations>recipient.four@example.com</Destinations>
        <Files>
            <Name>Sample.pdf</Name>
            <Data>%%BASE-64 CONTENT%%</Data>
        </Files>
        <Files>
            <Name>Sample2.pdf</Name>
            <Data>%%BASE-64 CONTENT%%</Data>
        </Files>    
      </MessageData>
    </root>
  '                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>ID123456</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?php

$data = new SimpleXMLExtended("<?xml version=\"1.0\" encoding=\"utf-8\"?><root></root>");

$data->addChild("Sender","application@domain.com");
$data->addChild("APIKey","ta8wr7ymd");
$data->addChild("MessageType","1.04");
$data->addChild("APIVersion","Email");

$data->addChild("MessageData");
$data->MessageData->addChild("EmailSubject","Test Email Subject");
$data->MessageData->addChild("MessaePlain","Hello, This is a test message. Thank you.");
$data->MessageData->addChild("Destinations","recipient@example.com");

$headers = array(
  "Content-Type: text/xml",
  "encoding='utf-8'",
  "Content-length: ".strlen($data->asXML()),
  "Connection: close"
);  

try
{
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://www.tnz.co.nz/api/xml/send");
    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();
}

?>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="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)); 
  } 
}

$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "Email";
$version = "1.04";
$message_id = "ID123456"; //optional

$file_name1 = "Sample.pdf";
$file_name2 = "Sample2.pdf";

if( file_exists($file_name1) )
{
    $fp = fopen($file_name1,"r");
    $file_content1 = fread($fp,filesize($file_name1));
    fclose($fp);
}

if( file_exists($file_name2) )
{
    $fp = fopen($file_name2,"r");
    $file_content2 = fread($fp,filesize($file_name2));
    fclose($fp);  
}

$data = new SimpleXMLExtended("<?xml version=\"1.0\" encoding=\"utf-8\"?><root></root>");

$data->addChild("Sender",$sender);
$data->addChild("APIKey",$apikey);
$data->addChild("MessageType",$type);
$data->addChild("APIVersion",$version);
$data->addChild("MessageID",$message_id);

$data->addChild("MessageData");
$data->MessageData->addChild("Reference","Test1");
$data->MessageData->addChild("SendTime");
$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("MessaePlain","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

$destination1 = $data->MessageData->addChild("Destinations");
$destination1->addChild("Recipient","recipient.one@example.com");
$destination1->addChild("Attention","Recipient One");
$destination1->addChild("Company","Example Corp");
$destination1->addChild("Custom1","");
$destination1->addChild("Custom2","");

$destination2 = $data->MessageData->addChild("Destinations","recipient.two@example.com");
$destination3 = $data->MessageData->addChild("Destinations","recipient.three@example.com");
$destination4 = $data->MessageData->addChild("Destinations","recipient.four@example.com");

if( file_exists($file_name1) )
{
    $fileElement1 = $data->MessageData->addChild("Files");
    $fileElement1->addChild("Name",basename($file_name1));
    $fileElement1->addChild("Data",base64_encode($file_content1));
}

if( file_exists($file_name2) )
{
    $fileElement2 = $data->MessageData->addChild("Files");
    $fileElement2->addChild("Name",basename($file_name2));
    $fileElement2->addChild("Data",base64_encode($file_content2));
}

$headers = array(
  "Content-Type: text/xml",
  "encoding='utf-8'",
  "Content-length: ".strlen($data->asXML()),
  "Connection: close"
);  

try
{
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://www.tnz.co.nz/api/xml/send");
    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();
}

?>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>ID123456</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

using System;
using System.IO;
using System.Text;
using System.Net;
using System.Xml;

namespace EmailSimple
{
    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://www.tnz.co.nz/api/xml/send";

            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("root");
            xmlDoc.AppendChild(rootNode);

            rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com"));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd"));
            rootNode.AppendChild(addChildNode(xmlDoc, "MessageType", "Email"));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIVersion", "1.04"));

            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 Destination
            //
            messageDataNode.AppendChild(addChildNode(xmlDoc, "Destinations", "recipient@example.com"));

            //
            // 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'";

            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);
        }
    }
}
                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

using System;
using System.IO;
using System.Text;
using System.Net;
using System.Xml;

namespace EmailAdvanced
{
    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 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://www.tnz.co.nz/api/xml/send";

            string file1 = "C:\\File1.pdf";
            string file2 = "C:\\File2.pdf";

            string file1_data = GetFileContents(file1);
            string file2_data = GetFileContents(file2);

            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("root");
            xmlDoc.AppendChild(rootNode);

            rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com"));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd"));
            rootNode.AppendChild(addChildNode(xmlDoc, "MessageType", "Email"));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIVersion", "1.04"));
            rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", "ID123456"));

            XmlNode workingNode = xmlDoc.CreateElement("Sender");

            //
            // MessageData
            //
            XmlNode messageDataNode = xmlDoc.CreateElement("MessageData");

            messageDataNode.AppendChild(addChildNode(xmlDoc, "Reference", "Test1"));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "SendTime", ""));
            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");
            workingNode.AppendChild(addChildNode(xmlDoc, "Recipient", "recipient.one@example.com"));
            workingNode.AppendChild(addChildNode(xmlDoc, "Attention", "Recipient One"));
            workingNode.AppendChild(addChildNode(xmlDoc, "Company", "Example Corp"));
            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", "recipient.two@example.com"));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "Destinations", "recipient.three@example.com"));

            //
            // Attach File 1
            //
            workingNode = xmlDoc.CreateElement("Files");
            workingNode.AppendChild(addChildNode(xmlDoc, "Name", "File1.pdf"));
            workingNode.AppendChild(addChildNode(xmlDoc, "Data", file1_data));

            messageDataNode.AppendChild(workingNode);

            //
            // Attach File 2
            //
            workingNode = xmlDoc.CreateElement("Files");
            workingNode.AppendChild(addChildNode(xmlDoc, "Name", "File2.pdf"));
            workingNode.AppendChild(addChildNode(xmlDoc, "Data", file2_data));

            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'";

            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);
        }
    }
}
                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>ID123456</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

import requests
import xml.etree.ElementTree as ET

url = "https://www.tnz.co.nz/api/xml/send/"

headers = {
    "Content-Type": "text/xml",
    "encoding": "utf-8"
}

root = ET.Element('root')

ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "MessageType").text = "Email"
ET.SubElement(root, "APIVersion").text = "1.04"

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."
ET.SubElement(message_data, "Destinations").text = "recipient.four@example.com"

r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)

print(r)
print(r.text)                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

import requests
import base64
import xml.etree.ElementTree as ET

url = "https://www.tnz.co.nz/api/xml/send/"

headers = {
    "Content-Type": "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('root')

ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "MessageType").text = "Email"
ET.SubElement(root, "APIVersion").text = "1.04"
ET.SubElement(root, "MessageID").text = "ID123456"

message_data = ET.SubElement(root,"MessageData")
ET.SubElement(message_data, "Reference").text = "Test1"
ET.SubElement(message_data, "SendTime").text = ""
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 = "Hello,

This is a test message.

Thank you.]]>" destinations = ET.SubElement(message_data,"Destinations") ET.SubElement(destinations,"Recipient").text = "recipient.one@example.com" ET.SubElement(destinations,"Attention").text = "Recipient One" ET.SubElement(destinations,"Company").text = "Example Corp" ET.SubElement(destinations,"Custom1").text = "" ET.SubElement(destinations,"Custom2").text = "" ET.SubElement(message_data, "Destinations").text = "recipient.two@example.com" ET.SubElement(message_data, "Destinations").text = "recipient.three@example.com" ET.SubElement(message_data, "Destinations").text = "recipient.four@example.com" message_data_files = ET.SubElement(message_data,"Files") ET.SubElement(message_data_files,"Name").text = "File1.pdf" ET.SubElement(message_data_files,"Data").text = file_data_1 message_data_files = ET.SubElement(message_data,"Files") ET.SubElement(message_data_files,"Name").text = "File2.pdf" ET.SubElement(message_data_files,"Data").text = file_data_2 r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers) print(r) print(r.text)

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>ID123456</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                

Required MessageData parameters

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.two@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)

Optional MessageData parameters

Parameter Example Value Description
Reference Test1 Tracking ID or message description
SendTime 08/12/2019 13:04 Delay sending until the specified date/time (dd/mm/yyyy HH:mm in your local timezone, specified by your Sender setting or overridden using the TimeZone command)
TimeZone New Zealand Timezone specified using Windows timezone value (default set using Web Dashboard can be overridden here)
See Microsoft Timezones (use the Country value)
SubAccount SubAccount01 Used for reporting, billing and Web Dashboard segmentation
Department Department01 Used for reporting, billing and Web Dashboard segmentation
ChargeCode BillingGroup01 Cost allocation for billing
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 recipient.one@example.com Recipient of the email
> Attention Recipient One Recipient's friendly name
> Company Example Corp Recipient's company
> Custom1 Recipient One Customisable field
> Custom2 Recipient One Customisable field
Files > Name Sample.pdf Attachment's filename
> Data %%Base-64%% Base-64 encoded value of the attached file

MessageType=SMS - Send SMS/TXT via REST API

 
 
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "MessageType": "sms",
    "APIVersion": "1.04",
    "MessageData" :
    {
        "Message": "Hello, this is a test message from Department01. Thank you.",
        "Destinations" : 
        [
            "6421000002"
        ]
    }
}                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "MessageType": "sms",
    "APIVersion": "1.04",
    "MessageID": "ID123456",
    "MessageData" :
    {
        "Reference": "Test1",
        "SendTime": "",
        "TimeZone": "New Zealand",
        "SubAccount": "SubAccount01",
        "Department": "Department01",
        "ChargeCode": "BillingGroup01",
        "FromNumber": "6422000001",
        "SMSEmailReply": "person.one@domain.com",
        "ForceGSMChars": true,
        "Message": "Hello, this is a test message. Click the link to download file1 [[File1]], and file2 [[File2]]",
        "Destinations" : 
        [
            {
                "Recipient": "6421000001",
                "Attention": "Recipient One",
                "Company": "Example Corp",
                "Custom1": "",
                "Custom2": ""
            },
            "6421000002",
            "6421000003",
            "6421000004"
        ], 
        "Files":
        [
            {
                "Name": "Sample.pdf",
                "Data": "%%BASE-64 CONTENT%%"
            },
            {
                "Name": "Sample2.pdf",
                "Data": "%%BASE-64 CONTENT%%"
            }
        ]
    }
}                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "ID123456"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/json/send \
  --header "Content-Type: application/json; encoding='utf-8'" \
  --data '{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "MessageType": "sms",
    "APIVersion": "1.04",
    "MessageData" :
    {
        "Message": "Hello, this is a test message from Department01. Thank you.",
        "Destinations" : 
        [
            "6421000001"
        ]
    }
  }'                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/json/send \
  --header "Content-Type: application/json; encoding='utf-8'" \
  --data '{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "MessageType": "sms",
    "APIVersion": "1.04",
    "MessageID": "ID123456",
    "MessageData" :
    {
        "Reference": "Test1",
        "SendTime": "",
        "TimeZone": "New Zealand",
        "SubAccount": "SubAccount01",
        "Department": "Department01",
        "ChargeCode": "BillingGroup01",
        "FromNumber": "6422000001",
        "SMSEmailReply": "person.one@domain.com",
        "ForceGSMChars": true,
        "Message": "Hello, this is a test message. Click the link to download file1 [[File1]], and file2 [[File2]]",
        "Destinations" : 
        [
            {
                "Recipient": "6421000001",
                "Attention": "Recipient One",
                "Company": "Example Corp",
                "Custom1": "",
                "Custom2": ""
            },
            "6421000002",
            "6421000003",
            "6421000004"
        ],
        "Files":
        [
            {
                "Name": "Sample.pdf",
                "Data": "%%BASE-64 CONTENT%%"
            },
            {
                "Name": "Sample2.pdf",
                "Data": "%%BASE-64 CONTENT%%"
            }
        ]   
    }
  }'                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "ID123456"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

<?php

$data = array(
    "Sender" => "application@domain.com",
    "APIKey" => "ta8wr7ymd",
    "MessageType" => "sms",
    "APIVersion" => "1.04",
    "MessageData" => array(
        "Message" => "Hello, this is a test message from Department01. Thank you.",
        "Destinations" => array(
            "6421000001",
        ),
    )
);

$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://www.tnz.co.nz/api/json/send");
    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();
}

?>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

<?php

$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "sms";
$version = "1.04";
$message_id = "ID123456";           // optional

$file1 = "Sample.pdf";
$file2 = "Sample2.pdf";

if( file_exsits($file1) )
{
    $fp = fopen($file1,"r");
    $file_content1 = fread($fp,filesize($file1));
    fclose($fp);
}

if( file_exists($file2) )
{
    $fp = fopen($file2,"r");
    $file_content2 = fread($fp,filesize($file2));
    fclose($fp);
}

$data = array(
    "Sender" => $sender,
    "APIKey" => $apikey,
    "MessageType" => $type,
    "APIVersion" => $version,
    "MessageID" => $message_id,
    "MessageData" => array(
        "Reference" => "Test1",
        "SendTime" => "",
        "TimeZone" => "New Zealand",
        "SubAccount" => "SubAccount01",
        "Department" => "Department01",
        "ChargeCode" => "BillingGroup01",
        "FromNumber" => "6422000001",
        "SMSEmailReply" => "person.one@domain.com",
        "ForceGSMChars" => true,
        "Message" => "Hello, this is a test message. Click the link to download file1 [[File1]], and file2 [[File2]]",
        "Destinations" => array(
            array(
                "Recipient" => "6421000001",
                "Attention" => "Recipient One",
                "Company" => "Example Corp",
                "Custom1" => "",
                "Custom2" => ""
            ),
            "6421000002",
            "6421000003",
            "6421000004"
        ),
        "Files" => array(
            array(
                "Name" => $file1,
                "Data" => base64_encode($file_content1)
            ),
            array(
                "Name" => $file2,
                "Data" => base64_encode($file_content2)
            )
        ),
    )
);

$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://www.tnz.co.nz/api/json/send");
    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();
}

?>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "ID123456"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Net;
using System.IO;

namespace SMSJSON
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }
        
        private void SendSMSByJSONAPI()
        {
            string apiURL = "https://www.tnz.co.nz/api/json/send";
            
            string strJSONData = "{" +
                "\"Sender\": \"application@domain.com\"," +
                "\"APIKey\": \"ta8wr7ymd\"," +
                "\"MessageType\":\"SMS\"," +
                "\"APIVersion\":\"1.04\"," +
                "\"MessageData\": {" +
                    "\"Message\": \"Hello, this is a test message from Department01. Thank you.\"," + 
                    "\"Destinations\" : [" +
                        "\"6421000001\"" +
                    "]" + 
                "}" +
            "}";
                        
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "application/json; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }
            
            MessageBox.Show(strResponse);
        }
    }
}                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Net;
using System.IO;

namespace SMSJSON
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }

        private 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 void SendSMSByJSONAPI()
        {
            string apiURL = "https://www.tnz.co.nz/api/json/send";

            string strSender = "application@domain.com";
            string strAPIKey = "ta8wr7ymd";
            string strMessageType = "SMS";
            string strAPIVersion = "1.04";
            string strMessageID = "ID123456";             // optional

            string strReference = "Test1";
            string strSendTime = "";
            string strTimeZone = "New Zealand";
            string strSubAccount = "SubAccount01";
            string strDepartment = "Department01";
            string strChargeCode = "BillingGroup01";
            string strFromNumber = "6422000001";
            string strSMSEmailReply = "person.one@domain.com";
            string strMessage = addslashes("Hello, this is a test message. Click the link to download file1 [[File1]], and file2 [[File2]]");
            string strRecipient = "6421000001";
            string strForceGSMChars = "true";
            
            string strFileName1 = "Sample.PDF";
            string strFileName2 = "Sample2.PDF";

            Dictionary<int, String> FileNames = new Dictionary<int, String>();
            Dictionary<int, String> FileContents = new Dictionary<int, String>();

            //
            // Retrieve file(s) to sms - MessageLink
            //
            if ( File.Exists(strFileName1))
            {
                FileNames.Add(1,GetFileName(strFileName1));
                FileContents.Add(1,System.Text.Encoding.ASCII.GetString(GetFileContents(strFileName1)));
            }

            if ( File.Exists(strFileName2) )
            {
                FileNames.Add(2, GetFileName(strFileName2));
                FileContents.Add(2, System.Text.Encoding.ASCII.GetString(GetFileContents(strFileName2)));
            }
            
            StringBuilder sb = new StringBuilder();

            string strFiles = "";

            if (FileNames.Count > 0)
            {
                for (int i = 1; i < 10; i++)
                {
                    if (FileNames.ContainsKey(i))
                    {
                        sb.Append("{").AppendFormat("\"Name\":\"{0}\", \"Data\": \"{1}\"", FileNames[i], FileContents[i]).Append("}");

                        if (FileNames.ContainsKey(i + 1))
                        {
                            sb.Append(",");
                        }
                    }
                }

                strFiles = "\"Files\": [" + sb.ToString() + "]," + EOL;
            }

            string strJSONData = "{" +
                "\"Sender\": \"" + strSender + "\"," +
                "\"APIKey\": \"" + strAPIKey + "\"," +
                "\"MessageType\":\"" + strMessageType + "\"," +
                "\"APIVersion\":\"" + strAPIVersion + "\"," +
                "\"MessageID\":\"" + strMessageID + "\"," +
                "\"MessageData\": {" +
                    "\"Reference\": \"" + strReference + "\"," +
                    "\"SendTime\": \"" + strSendTime + "\"," +
                    "\"TimeZone\": \"" + strTimeZone + "\"," +
                    "\"SubAccount\": \"" + strSubAccount + "\"," +
                    "\"Department\": \"" + strDepartment + "\"," +
                    "\"ChargeCode\": \"" + strChargeCode + "\"," +
                    "\"FromNumber\":\"" + strFromNumber + "\","+
                    "\"SMSEmailReply\":\"" + strSMSEmailReply + "\","+
                    "\"strForceGSMChars\":" + strForceGSMChars + ","+
                    "\"Message\": \"" + strMessage + "\"," + // escape special characters (ie. \r\n to \\r\\n)
                    strFiles +
                    "\"Destinations\" : [" +
                        "\"" + strRecipient + "\"" +
                    "]" + 
                "}" +
            "}";
                        
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "application/json; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }
            
            MessageBox.Show(strResponse);
        }
    }
}                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "ID123456"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

import requests
import json

url = "https://www.tnz.co.nz/api/json/send/"

headers = {
    "Content-Type": "application/json",
    "encoding": "utf-8"
}

data = {
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "MessageType": "SMS",
    "APIVersion": "1.04",
    "MessageData" :
    {
        "Message": "Hello, this is a test message from Department01. Thank you.",
        "Destinations" : 
        [
            "6421000002"
        ]
    }
}

r = requests.post(url, data=json.dumps(data), headers=headers)

print(r)
print(r.text)                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

import requests
import json
import base64

url = "https://www.tnz.co.nz/api/json/send/"

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",
    "MessageType": "SMS",
    "APIVersion": "1.04",
    "MessageID": "ID123456",
    "MessageData" :
    {
        "Reference": "Test1",
        "SendTime": "",
        "TimeZone": "New Zealand",
        "SubAccount": "SubAccount01",
        "Department": "Department01",
        "ChargeCode": "BillingGroup01",
        "FromNumber": "6422000001",
        "SMSEmailReply": "person.one@domain.com",
        "ForceGSMChars": True,
        "Message": "Hello, this is a test message. Click the link to download file1 [[File1]], and file2 [[File2]]",
        "Destinations" : 
        [
            {
                "Recipient": "6421000001",
                "Attention": "Recipient One",
                "Company": "Example Corp",
                "Custom1": "",
                "Custom2": ""
            },
            "6421000002",
            "6421000003",
            "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)                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "ID123456"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <Sender>application@domain.com</Sender>
  <APIKey>ta8wr7ymd</APIKey>
  <MessageType>SMS</MessageType>
  <APIVersion>1.04</APIVersion>
  <MessageData>
    <Message>Hello, this is a test message from Department01. Thank you.</Message>
    <Destinations>6421000001</Destinations>
  </MessageData>
</root>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <Sender>application@domain.com</Sender>
  <APIKey>ta8wr7ymd</APIKey>
  <MessageType>SMS</MessageType>
  <APIVersion>1.04</APIVersion>
  <MessageID>ID123456</MessageID>
  <MessageData>
    <Reference>Test1</Reference>
    <SendTime></SendTime>
    <TimeZone>New Zealand</TimeZone>
    <SubAccount>SubAccount01</SubAccount>
    <Department>Department01</Department>
    <ChargeCode>BillingGroup01</ChargeCode>
    <FromNumber>6422000001</FromNumber>
    <SMSEmailReply>person.one@domain.com</SMSEmailReply>
    <ForceGSMChars>true</ForceGSMChars>
    <Message>Hello, this is a test message. Click the link to download file1 [[File1]], and file2 [[File2]]</Message>
    <Destinations>
        <Recipient>6421000001</Recipient>
        <Attention>Recipient One</Attention>
        <Company>Example Corp</Company>
        <Custom1></Custom1>
        <Custom2></Custom2>
    </Destinations>
    <Destinations>6421000002</Destinations>
    <Destinations>6421000003</Destinations>
    <Destinations>6421000004</Destinations>
    <Files>
        <Name>Sample.pdf</Name>
        <Data>%%BASE-64 CONTENT%%</Data>
    </Files>
    <Files>
        <Name>Sample2.pdf</Name>
        <Data>%%BASE-64 CONTENT%%</Data>
    </Files>  
  </MessageData>
</root>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>ID123456</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/xml/send \
  --header "Content-Type: text/xml; encoding='utf-8'" \
  --data '
  <?xml version="1.0" encoding="UTF-8"?>
  <root>
    <Sender>application@domain.com</Sender>
    <APIKey>ta8wr7ymd</APIKey>
    <MessageType>SMS</MessageType>
    <APIVersion>1.04</APIVersion>
    <MessageData>
      <Message>Hello, this is a test message from Department01. Thank you.</Message>
      <Destinations>6421000001</Destinations>
    </MessageData>
  </root>
  '                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/xml/send \
  --header "Content-Type: text/xml; encoding='utf-8'" \
  --data '
  <?xml version="1.0" encoding="UTF-8"?>
  <root>
    <Sender>application@domain.com</Sender>
    <APIKey>ta8wr7ymd</APIKey>
    <MessageType>SMS</MessageType>
    <APIVersion>1.04</APIVersion>
    <MessageID>ID123456</MessageID>
    <MessageData>
      <Reference>Test1</Reference>
      <SendTime></SendTime>
      <TimeZone>New Zealand</TimeZone>
      <SubAccount>SubAccount01</SubAccount>
      <Department>Department01</Department>
      <ChargeCode>BillingGroup01</ChargeCode>
      <FromNumber>6422000001</FromNumber>
      <SMSEmailReply>person.one@domain.com</SMSEmailReply>
      <ForceGSMChars>true</ForceGSMChars>
      <Message>Hello, this is a test message. Click the link to download file1 [[File1]], and file2 [[File2]]</Message>
      <Destinations>
          <Recipient>6421000001</Recipient>
          <Attention>Recipient One</Attention>
          <Company>Example Corp</Company>
          <Custom1></Custom1>
          <Custom2></Custom2>
      </Destinations>
      <Destinations>6421000002</Destinations>
      <Destinations>6421000003</Destinations>
      <Destinations>6421000004</Destinations>
      <Files>
          <Name>Sample.pdf</Name>
          <Data>%%BASE-64 CONTENT%%</Data>
      </Files>
      <Files>
          <Name>Sample2.pdf</Name>
          <Data>%%BASE-64 CONTENT%%</Data>
      </Files>  
    </MessageData>
  </root>
  '                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>ID123456</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?php

$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "SMS";
$version = "1.04";

$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><root></root>");

$data->addChild("Sender",$sender);
$data->addChild("APIKey",$apikey);
$data->addChild("MessageType",$type);
$data->addChild("APIVersion",$version);

$data->addChild("MessageData");
$data->MessageData->addChild("Message","Hello, this is a test message from Department01. Thank you.");
$data->MessageData->addChild("Destinations","6421000001");

$headers = array(
  "Content-Type: text/xml",
  "encoding='utf-8'",
  "Content-length: ".strlen($data->asXML()),
  "Connection: close"
);  

try
{
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://www.tnz.co.nz/api/xml/send");
    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();
}

?>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?php

$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "SMS";
$version = "1.04";
$message_id = "ID123456";           // optional

$file_name1 = "Sample.pdf";
$file_name2 = "Sample2.pdf";

if( file_exists($file_name1) )
{
    $fp = fopen($file_name1,"r");
    $file_content1 = fread($fp,filesize($file_name1));
    fclose($fp);
}

if( file_exists($file_name2) )
{
    $fp = fopen($file_name2,"r");
    $file_content2 = fread($fp,filesize($file_name2));
    fclose($fp);  
}

$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><root></root>");

$data->addChild("Sender",$sender);
$data->addChild("APIKey",$apikey);
$data->addChild("MessageType",$type);
$data->addChild("APIVersion",$version);
$data->addChild("MessageID",$message_id);

$data->addChild("MessageData");
$data->MessageData->addChild("Reference","Test1");
$data->MessageData->addChild("SendTime");
$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("ForceGSMChars",true);
$data->MessageData->addChild("Message","Hello, this is a test message. Click the link to download file1 [[File1]], and file2 [[File2]]");

$destination1 = $data->MessageData->addChild("Destinations");
$destination1->addChild("Recipient","6421000001");
$destination1->addChild("Attention","Recipient One");
$destination1->addChild("Company","Example Corp");
$destination1->addChild("Custom1","");
$destination1->addChild("Custom2","");

$destination2 = $data->MessageData->addChild("Destinations","6421000002");
$destination3 = $data->MessageData->addChild("Destinations","6421000003");
$destination4 = $data->MessageData->addChild("Destinations","6421000004");

if( file_exists($file_name1) )
{
    $fileElement1 = $data->MessageData->addChild("Files");
    $fileElement1->addChild("Name",basename($file_name1));
    $fileElement1->addChild("Data",base64_encode($file_content1));
}

if( file_exists($file_name2) )
{
    $fileElement2 = $data->MessageData->addChild("Files");
    $fileElement2->addChild("Name",basename($file_name2));
    $fileElement2->addChild("Data",base64_encode($file_content2));
}

$headers = array(
  "Content-Type: text/xml",
  "encoding='utf-8'",
  "Content-length: ".strlen($data->asXML()),
  "Connection: close"
);  

try
{
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://www.tnz.co.nz/api/xml/send");
    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();
}

?>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>ID123456</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Xml;
using System.Windows.Forms;

using System.IO;
using System.Net;

namespace TestXML
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
        {
            XmlNode workingNode = xmlDoc.CreateElement(name);
            workingNode.InnerText = val;

            return workingNode;
        }
        
        private void btnSendSMS_Click(object sender, EventArgs e)
        {
            string apiURL = "https://www.tnz.co.nz/api/xml/send";
            
            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("root");
            xmlDoc.AppendChild(rootNode);

            rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com"));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd"));
            rootNode.AppendChild(addChildNode(xmlDoc, "MessageType", "SMS"));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIVersion", "1.04"));

            XmlNode workingNode = xmlDoc.CreateElement("Sender");

            //
            // MessageData
            //
            XmlNode messageDataNode = xmlDoc.CreateElement("MessageData");
            
            messageDataNode.AppendChild(addChildNode(xmlDoc, "Message", "Hello, this is a test message from Department01. Thank you."));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "Destinations", "6421000001"));

            //
            // Set MessageData into root node
            //
            rootNode.AppendChild(messageDataNode);

            //
            // Send Raw XML Request
            //
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "text/xml; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }

            MessageBox.Show(strResponse);
        }
    }
}                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Xml;
using System.Windows.Forms;

using System.IO;
using System.Net;

namespace TestXML
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        
        private string GetFileName(string strFileLocation)
        {
            return System.IO.Path.GetFileName(strFileLocation);
        }

        private byte[] GetFileContents(string strFileLocation)
        {
            //
            // Read files in bytes, convert to Base64String and return in byte[]
            //
            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);

                System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                return encoding.GetBytes(strContent);
            }
        }

        private XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
        {
            XmlNode workingNode = xmlDoc.CreateElement(name);
            workingNode.InnerText = val;

            return workingNode;
        }
        
        private void btnSendSMS_Click(object sender, EventArgs e)
        {
            string apiURL = "https://www.tnz.co.nz/api/xml/send";

            string strSender = "application@domain.com";
            string strAPIKey = "ta8wr7ymd";
            string strMessageType = "SMS";
            string strAPIVersion = "1.04";
            string strMessageID = "ID123456";           // optional

            string strReference = "Test1";
            string strSendTime = "";
            string strTimeZone = "New Zealand";
            string strSubAccount = "SubAccount01";
            string strDepartment = "Department01";
            string strChargeCode = "BillingGroup01";
            string strFromNumber = "6422000001";
            string strSMSEmailReply = "person.one@domain.com";
            string strMessage = "Hello, this is a test message. Click the link to download file1 [[File1]], and file2 [[File2]]";
            string strRecipient = "6421000001";
            string strForceGSMChars = "true";
            
            string strFileName1 = "Sample.PDF";
            string strFileName2 = "Sample2.PDF";

            Dictionary<int, String> FileNames = new Dictionary<int, String>();
            Dictionary<int, String> FileContents = new Dictionary<int, String>();

            //
            // Retrieve file(s) to email
            //
            if ( File.Exists(strFileName1) )
            {
                FileNames.Add(1, GetFileName(strFileName1));
                FileContents.Add(1, System.Text.Encoding.ASCII.GetString(GetFileContents(strFileName1)));
            }

            if ( File.Exists(strFileName2) )
            {
                FileNames.Add(2, GetFileName(strFileName2));
                FileContents.Add(2, System.Text.Encoding.ASCII.GetString(GetFileContents(strFileName2)));
            }

            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("root");
            xmlDoc.AppendChild(rootNode);

            rootNode.AppendChild(addChildNode(xmlDoc, "Sender", strSender));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", strAPIKey));
            rootNode.AppendChild(addChildNode(xmlDoc, "MessageType", strMessageType));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIVersion", strAPIVersion));
            rootNode.AppendChild(addChildNode(xmlDoc, "FromNumber", strFromNumber));
            rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", strMessageID));

            XmlNode workingNode = xmlDoc.CreateElement("Sender");

            //
            // MessageData
            //
            XmlNode messageDataNode = xmlDoc.CreateElement("MessageData");

            messageDataNode.AppendChild(addChildNode(xmlDoc, "Reference", strReference));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "SendTime", strSendTime));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "TimeZone", strTimeZone));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "SubAccount", strSubAccount));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "Department", strDepartment));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "ChargeCode", strChargeCode));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "SMSEmailReply", strSMSEmailReply));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "ForceGSMChars", strForceGSMChars));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "Message", strMessage));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "Destinations", strRecipient));
            
            //
            // MessageData -> Files
            //
            if (FileNames.Count > 0)
            {
                for (int i = 1; i < 10; i++)
                {
                    if (FileNames.ContainsKey(i))
                    {
                        workingNode = xmlDoc.CreateElement("Files");
                        workingNode.AppendChild(addChildNode(xmlDoc, "Name", FileNames[i]));
                        workingNode.AppendChild(addChildNode(xmlDoc, "Data", FileContents[i]));

                        messageDataNode.AppendChild(workingNode);
                    }
                }
            }

            //
            // Set MessageData into root node
            //
            rootNode.AppendChild(messageDataNode);

            //
            // Send Raw XML Request
            //
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "text/xml; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }

            MessageBox.Show(strResponse);
        }
    }
}                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>ID123456</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

import requests
import xml.etree.ElementTree as ET

url = "https://www.tnz.co.nz/api/xml/send/"

headers = {
    "Content-Type": "text/xml",
    "encoding": "utf-8"
}

root = ET.Element('root')

ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "MessageType").text = "SMS"
ET.SubElement(root, "APIVersion").text = "1.04"

message_data = ET.SubElement(root,"MessageData")
ET.SubElement(message_data, "Message").text = "Hello, this is a call from test. This is relevant information."
ET.SubElement(message_data, "Destinations").text = "6421000002"

r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)

print(r)
print(r.text)                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

import requests
import base64
import xml.etree.ElementTree as ET

url = "https://www.tnz.co.nz/api/xml/send/"

headers = {
    "Content-Type": "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('root')

ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "MessageType").text = "SMS"
ET.SubElement(root, "APIVersion").text = "1.04"
ET.SubElement(root, "MessageID").text = "ID123456"

message_data = ET.SubElement(root,"MessageData")
ET.SubElement(message_data, "Reference").text = "Test1"
ET.SubElement(message_data, "SendTime").text = ""
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, "ForceGSMChars").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")
ET.SubElement(destinations,"Recipient").text = "6421000001"
ET.SubElement(destinations,"Attention").text = "Recipient One"
ET.SubElement(destinations,"Company").text = "Example Corp"
ET.SubElement(destinations,"Custom1").text = ""
ET.SubElement(destinations,"Custom2").text = ""

ET.SubElement(message_data, "Destinations").text = "6421000002"
ET.SubElement(message_data, "Destinations").text = "6421000003"
ET.SubElement(message_data, "Destinations").text = "6421000004"

message_data_files = ET.SubElement(message_data,"Files")
ET.SubElement(message_data_files,"Name").text = "File1.pdf"
ET.SubElement(message_data_files,"Data").text = file_data_1

message_data_files = ET.SubElement(message_data,"Files")
ET.SubElement(message_data_files,"Name").text = "File2.pdf"
ET.SubElement(message_data_files,"Data").text = file_data_2

r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)

print(r)
print(r.text)                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>ID123456</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                

Required MessageData parameters

Parameter Example Value Description
Message Hello, this is a test message from Department01. Thank you. Plain or UTF-8 formatted SMS message
Destinations 6421000002
6421000003
6421000004
Mobile number(s) to receive the message (for detailed formatting, see the Destinations parameter below)

Optional MessageData parameters

Parameter Example Value Description
Reference Test1 Tracking ID or message description
SendTime 08/12/2019 13:04 Delay sending until the specified date/time (dd/mm/yyyy HH:mm in your local timezone, specified by your Sender setting or overridden using the TimeZone command)
TimeZone New Zealand Timezone specified using Windows timezone value (default set using Web Dashboard can be overridden here)
See Microsoft Timezones (use the Country value)
SubAccount SubAccount01 Used for reporting, billing and Web Dashboard segmentation
Department Department01 Used for reporting, billing and Web Dashboard segmentation
ChargeCode BillingGroup01 Cost allocation for billing
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
ForceGSMChars true Convert multi-byte characters into normalised GSM character format. ie. © to (C)
Destinations > Recipient 6421000001 Recipient of the SMS in E.164 internationalised format (for localized or friendly formatting, contact your account manager)
> Attention Recipient One Recipient's friendly name
> Company Example Corp Recipient's company
> Custom1 Recipient One Customisable field
> Custom2 Recipient One Customisable field
Files > Name File Name.pdf Files referenced in [[File1]] commands (for MessageLink)
> Data %%Base-64%% Base-64 encoded value of the attached file

MessageType=Fax - Send Fax via REST API

 
 
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "MessageType": "Fax",
    "APIVersion": "1.04",
    "MessageData" :
    {
        "Destinations" : 
        [
            "6495005001",
        ],
        "Files":
        [
            {
                "Name": "Sample.pdf",
                "Data": "%%BASE-64 CONTENT%%"
            }
        ]       
    }
}                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "MessageType": "Fax",
    "APIVersion": "1.04",
    "MessageID": "ID123456",
    "MessageData" :
    {
        "Reference": "Test1",
        "SendTime": "",
        "TimeZone": "New Zealand",
        "SubAccount": "SubAccount01",
        "Department": "Department01",
        "ChargeCode": "BillingGroup01",
        "Resolution": "high",
        "CSID": "Station ID",
        "Destinations" : 
        [
            {
                "Recipient": "6495005000",
                "Attention": "Recipient One",
                "Company": "Example Corp",
                "Custom1": "",
                "Custom2": ""
            },
            "6495005001",
            "6495005002",
            "6495005003"
        ],
        "Files":
        [
            {
                "Name": "Sample.pdf",
                "Data": "%%BASE-64 CONTENT%%"
            },
            {
                "Name": "Sample2.pdf",
                "Data": "%%BASE-64 CONTENT%%"
            }
        ]       
    }
}                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "ID123456"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/json/send \
  --header "Content-Type: application/json; encoding='utf-8'" \
  --data '{
        "Sender": "application@domain.com",
        "APIKey": "ta8wr7ymd",
        "MessageType": "Fax",
        "APIVersion": "1.04",
        "MessageData" :
        {
            "Destinations" : 
            [
                "6495005001"
            ],
            "Files":
            [
                {
                    "Name": "Sample.pdf",
                    "Data": "%%BASE-64 CONTENT%%"
                }
            ]       
        }
    }'                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/json/send \
  --header "Content-Type: application/json; encoding='utf-8'" \
  --data '{
        "Sender": "application@domain.com",
        "APIKey": "ta8wr7ymd",
        "MessageType": "Fax",
        "APIVersion": "1.04",
        "MessageID" : "ID123456",
        "MessageData" :
        {
            "Reference": "Test1",
            "SendTime": "",
            "TimeZone": "New Zealand",
            "SubAccount": "SubAccount01",
            "Department": "Department01",
            "ChargeCode": "BillingGroup01",
            "Resolution": "high",
            "CSID": "Station ID",
            "Destinations" : 
            [
                {
                    "Recipient": "6495005000",
                    "Attention": "Recipient One",
                    "Company": "Example Corp",
                    "Custom1": "",
                    "Custom2": ""
                },
                "6495005001",
                "6495005002",
                "6495005003"
            ],
            "Files":
            [
                {
                    "Name": "Sample.pdf",
                    "Data": "%%BASE-64 CONTENT%%"
                },
                {
                    "Name": "Sample2.pdf",
                    "Data": "%%BASE-64 CONTENT%%"
                }
            ]       
        }
    }'                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "ID123456"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

<?php

$file1 = "Sample.pdf";

$fp = fopen($file1,"r");
$file_content1 = fread($fp,filesize($file1));
fclose($fp);

$data = array(
    "Sender" => "application@domain.com",
    "APIKey" => "ta8wr7ymd",
    "MessageType" => "Fax",
    "APIVersion" => "1.04",
    "MessageData" => array(
        "Destinations" => array(
            "6495005001"
        ),
        "Files" => array(
            array(
                "Name" => $file1,
                "Data" => base64_encode($file_content1)
            )
        ),
    )
);


$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://www.tnz.co.nz/api/json/send");
    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();
}

?>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

<?php

$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "Fax";
$version = "1.04";
$message_id = "ID123456";           //optional

$file1 = "Sample.pdf";

$fp = fopen($file1,"r");
$file_content1 = fread($fp,filesize($file1));
fclose($fp);

$file2 = "Sample2.pdf";

$fp = fopen($file2,"r");
$file_content2 = fread($fp,filesize($file2));
fclose($fp);

$data = array(
    "Sender" => $sender,
    "APIKey" => $apikey,
    "MessageType" => $type,
    "APIVersion" => $version,
    "MessageID" => $message_id,
    "MessageData" => array(
        "Reference" => "Test1",
        "SendTime" => "",
        "TimeZone" => "New Zealand",
        "SubAccount" => "SubAccount01",
        "Department" => "Department01",
        "ChargeCode" => "BillingGroup01",
        "Resolution" => "high",
        "CSID"       => "Station ID",
        "Destinations" => array(
            array(
                "Recipient" => "6495005000",
                "Attention" => "Recipient One",
                "Company" => "Example Corp",
                "Custom1" => "",
                "Custom2" => ""
            ),
            "6495005001",
            "6495005002",
            "6495005003"
        ),
        "Files" => array(
            array(
                "Name" => $file1,
                "Data" => base64_encode($file_content1)
            ),
            array(
                "Name" => $file2,
                "Data" => base64_encode($file_content2)
            )
        ),
    )
);


$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://www.tnz.co.nz/api/json/send");
    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();
}

?>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "ID123456"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.IO;
using System.Net;

namespace FaxJSON
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        private string GetFileName(string strFileLocation)
        {
            return System.IO.Path.GetFileName(strFileLocation);
        }
        
        private byte[] GetFileContents(string strFileLocation)
        {
            //
            // Read files in bytes, convert to Base64String and return in byte[]
            //
            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);

                System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                return encoding.GetBytes(strContent);
            }
        }

        private void SendFax()
        {
            string apiURL = "https://www.tnz.co.nz/api/json/send";
            
            string strFile1 = "Sample.PDF";

            Dictionary FileNames = new Dictionary();
            Dictionary FileContents = new Dictionary();

            //
            // Retrieve file(s) to fax
            //
            if ( File.Exists(strFile1))
            {
                FileNames.Add(1,GetFileName(strFile1));
                FileContents.Add(1,System.Text.Encoding.ASCII.GetString(GetFileContents(strFile1)));
            }

            //
            // Send Fax by JSON API interface
            //

            string EOL = "\r\n";

            StringBuilder sb = new StringBuilder();

            string strFiles = "";

            if (FileNames.Count > 0)
            {
                for (int i = 1; i < 10; i++)
                {
                    if (FileNames.ContainsKey(i))
                    {
                        sb.Append("{").AppendFormat("\"Name\":\"{0}\", \"Data\": \"{1}\"", FileNames[i], FileContents[i]).Append("}");

                        if (FileNames.ContainsKey(i + 1))
                        {
                            sb.Append(",");
                        }
                    }
                }

                strFiles = "\"Files\": [" + sb.ToString() + "]," + EOL;
            }

            string strJSONData = "{" + EOL +
                    "\"Sender\": \"application@domain.com\"," + EOL +
                    "\"APIKey\": \"ta8wr7ymd\"," + EOL +
                    "\"APIVersion\": \"1.04\"," + EOL +
                    "\"MessageType\": \"Fax\"," + EOL +
                    "\"MessageData\": {" + EOL +
                        strFiles +
                        "\"Destinations\" : [\"6495005000\"]" + EOL +
                    "}" + EOL +
                "}";

            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "application/json; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }

            MessageBox.Show(strResponse);    
        }
    }
}                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.IO;
using System.Net;

namespace FaxJSON
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        private string GetFileName(string strFileLocation)
        {
            return System.IO.Path.GetFileName(strFileLocation);
        }
        
        private byte[] GetFileContents(string strFileLocation)
        {
            //
            // Read files in bytes, convert to Base64String and return in byte[]
            //
            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);

                System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                return encoding.GetBytes(strContent);
            }
        }

        private 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 void SendFax()
        {
            string apiURL = "https://www.tnz.co.nz/api/json/send";

            string strSender = "application@domain.com";
            string strToken = "ta8wr7ymd";
            string strMessageType = "Fax";
            string strAPIVersion = "1.04";
            string strMessageID = "ID123456";             //optional

            string strReference = "Test1";
            string strSendTime = "";
            string strTimeZone = "New Zealand";
            string strSubAccount = "SubAccount01";
            string strDepartment = "Department01";
            string strChargeCode = "BillingGroup01";
            string strResolution = "high";
            string strCSID = "Station ID";
            
            string strRecipient = "6495005000";
            
            string strFile1 = "Sample.PDF";
            string strFile2 = "Sample2.PDF";

            Dictionary FileNames = new Dictionary();
            Dictionary FileContents = new Dictionary();

            //
            // Retrieve file(s) to fax
            //
            if ( File.Exists(strFile1))
            {
                FileNames.Add(1,GetFileName(strFile1));
                FileContents.Add(1,System.Text.Encoding.ASCII.GetString(GetFileContents(strFile1)));
            }

            if ( File.Exists(strFile2))
            {
                FileNames.Add(2, GetFileName(strFile2));
                FileContents.Add(2, System.Text.Encoding.ASCII.GetString(GetFileContents(strFile2)));
            }

            //
            // Send Fax by JSON API interface
            //

            string EOL = "\r\n";

            StringBuilder sb = new StringBuilder();

            string strFiles = "";

            if (FileNames.Count > 0)
            {
                for (int i = 1; i < 10; i++)
                {
                    if (FileNames.ContainsKey(i))
                    {
                        sb.Append("{").AppendFormat("\"Name\":\"{0}\", \"Data\": \"{1}\"", FileNames[i], FileContents[i]).Append("}");

                        if (FileNames.ContainsKey(i + 1))
                        {
                            sb.Append(",");
                        }
                    }
                }

                strFiles = "\"Files\": [" + sb.ToString() + "]," + EOL;
            }

            string strJSONData = "{" + EOL +
                    "\"Sender\": \"" + strSender + "\"," + EOL +
                    "\"APIKey\": \"" + strToken + "\"," + EOL +
                    "\"MessageType\": \"" + strMessageType + "\"," + EOL +
                    "\"APIVersion\": \"" + strAPIVersion + "\"," + EOL +
                    "\"MessageID\": \"" + strMessageID + "\"," + EOL +
                    "\"MessageData\": {" + EOL +
                        "\"Reference\": \"" + strReference + "\"," + EOL +                        
                        "\"SendTime\": \"" + strSendTime + "\"," + EOL +
                        "\"TimeZone\": \"" + strTimeZone + "\"," + EOL +
                        "\"SubAccount\": \"" + strSubAccount + "\"," + EOL +
                        "\"Department\": \"" + strDepartment + "\"," + EOL +
                        "\"ChargeCode\": \"" + strChargeCode + "\"," + EOL +
                        "\"Resolution\": \"" + strResolution + "\"," + EOL +
                        "\"CSID\": \"" + strCSID + "\"," + EOL +
                        strFiles +
                        "\"Destinations\" :" + EOL +
                        "[" + EOL +
                            "\"" + strRecipient + "\"" + EOL +
                        "]" + EOL +
                    "}" + EOL +
                "}";

            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "application/json; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }

            MessageBox.Show(strResponse);    
        }
    }
}                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "ID123456"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

import requests
import base64
import json

url = "https://www.tnz.co.nz/api/json/send/"

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",
    "MessageType": "Fax",
    "APIVersion": "1.04",
    "MessageData" :
    {
        "Destinations" : 
        [
            "6495005001"
        ],
        "Files" :
        [
            {
                "Name": "File1.pdf",
                "Data": file_data
            }
        ]
    }
}

r = requests.post(url, data=json.dumps(data), headers=headers)

print(r)
print(r.text)                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

import requests
import base64
import json

url = "https://www.tnz.co.nz/api/json/send/"

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",
    "MessageType": "Fax",
    "APIVersion": "1.04",
    "MessageID": "ID123456",
    "MessageData" :
    {
        "Reference": "Test1",
        "SendTime": "",
        "TimeZone": "New Zealand",
        "SubAccount": "SubAccount01",
        "Department": "Department01",
        "ChargeCode": "BillingGroup01",
        "Resolution": "high",
        "CSID": "Station ID",
        "Destinations" : 
        [
            {
                "Recipient": "6495005000",
                "Attention": "Recipient One",
                "Company": "Example Corp",
                "Custom1": "",
                "Custom2": ""
            },
            "6495005001",
            "6495005002",
            "6495005003"
        ],
        "Files" :
        [
            {
                "Name": "File1.pdf",
                "Data": file_data
            }
        ]
    }
}

r = requests.post(url, data=json.dumps(data), headers=headers)

print(r)
print(r.text)                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "ID123456"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <Sender>application@domain.com</Sender>
  <APIKey>ta8wr7ymd</APIKey>
  <MessageType>Fax</MessageType>
  <APIVersion>1.04</APIVersion>
  <MessageData>
    <Destinations>6495005001</Destinations>
    <Files>
        <Name>Sample.pdf</Name>
        <Data>%%BASE-64 CONTENT%%</Data>
    </Files>
  </MessageData>
</root>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <Sender>application@domain.com</Sender>
  <APIKey>ta8wr7ymd</APIKey>
  <MessageType>Fax</MessageType>
  <APIVersion>1.04</APIVersion>
  <MessageID>ID123456</MessageID>
  <MessageData>
    <Reference>Test1</Reference>
    <SendTime></SendTime>
    <TimeZone>New Zealand</TimeZone>
    <SubAccount>SubAccount01</SubAccount>
    <Department>Department01</Department>
    <ChargeCode>BillingGroup01</ChargeCode>
    <Resolution>High</Resolution>
    <CSID>Station ID</CSID>
    <Destinations>
        <Recipient>6495005000</Recipient>
        <Attention>Recipient One</Attention>
        <Company>Example Corp</Company>
        <Custom1></Custom1>
        <Custom2></Custom2>
    </Destinations>
    <Destinations>6495005001</Destinations>
    <Destinations>6495005002</Destinations>
    <Destinations>6495005003</Destinations>
    <Files>
        <Name>Sample.pdf</Name>
        <Data>%%BASE-64 CONTENT%%</Data>
    </Files>
    <Files>
        <Name>Sample2.pdf</Name>
        <Data>%%BASE-64 CONTENT%%</Data>
    </Files>
  </MessageData>
</root>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>ID123456</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/xml/send \
  --header "Content-Type: text/xml; encoding='utf-8'" \
  --data '
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
      <Sender>application@domain.com</Sender>
      <APIKey>ta8wr7ymd</APIKey>
      <MessageType>Fax</MessageType>
      <APIVersion>1.04</APIVersion>
      <MessageData>
        <Destinations>6495005001</Destinations>
        <Files>
            <Name>Sample.pdf</Name>
            <Data>%%BASE-64 CONTENT%%</Data>
        </Files>
      </MessageData>
    </root>
  '                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/xml/send \
  --header "Content-Type: text/xml; encoding='utf-8'" \
  --data '
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
      <Sender>application@domain.com</Sender>
      <APIKey>ta8wr7ymd</APIKey>
      <MessageType>Fax</MessageType>
      <APIVersion>1.04</APIVersion>
      <MessageID>ID123456</MessageID>
      <MessageData>
        <Reference>Test1</Reference>
        <SendTime></SendTime>
        <TimeZone>New Zealand</TimeZone>
        <SubAccount>SubAccount01</SubAccount>
        <Department>Department01</Department>
        <ChargeCode>BillingGroup01</ChargeCode>
        <Resolution>High</Resolution>
        <CSID>Station ID</CSID>
        <Destinations>
            <Recipient>6495005000</Recipient>
            <Attention>Recipient One</Attention>
            <Company>Example Corp</Company>
            <Custom1></Custom1>
            <Custom2></Custom2>
        </Destinations>
        <Destinations>6495005001</Destinations>
        <Destinations>6495005002</Destinations>
        <Destinations>6495005003</Destinations>
        <Files>
            <Name>Sample.pdf</Name>
            <Data>%%BASE-64 CONTENT%%</Data>
        </Files>
        <Files>
            <Name>Sample2.pdf</Name>
            <Data>%%BASE-64 CONTENT%%</Data>
        </Files>
      </MessageData>
    </root>
  '                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>ID123456</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?php

$file_name1 = "Sample.pdf";

if( file_exists($file_name1) )
{
    $fp = fopen($file_name1,"r");
    $file_content1 = fread($fp,filesize($file_name1));
    fclose($fp);
}

$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><root></root>");

$data->addChild("Sender","application@domain.com");
$data->addChild("APIKey","ta8wr7ymd");
$data->addChild("APIVersion","1.04");
$data->addChild("MessageType","Fax");

$data->addChild("MessageData");
$data->MessageData->addChild("Destinations","6495005001");

if( file_exists($file_name1) )
{
    $fileElement1 = $data->MessageData->addChild("Files");
    $fileElement1->addChild("Name",basename($file_name1));
    $fileElement1->addChild("Data",base64_encode($file_content1));
}

$headers = array(
  "Content-Type: text/xml",
  "encoding='utf-8'",
  "Content-length: ".strlen($data->asXML()),
  "Connection: close"
);  

try
{
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://www.tnz.co.nz/api/xml/send");
    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();
}

?>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?php

$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "Fax";
$version = "1.04";
$message_id = "ID123456";           // optional

$file_name1 = "Sample.pdf";
$file_name2 = "Sample2.pdf";

if( file_exists($file_name1) )
{
    $fp = fopen($file_name1,"r");
    $file_content1 = fread($fp,filesize($file_name1));
    fclose($fp);
}

if( file_exists($file_name2) )
{
    $fp = fopen($file_name2,"r");
    $file_content2 = fread($fp,filesize($file_name2));
    fclose($fp);  
}

$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><root></root>");

$data->addChild("Sender",$sender);
$data->addChild("APIKey",$apikey);
$data->addChild("MessageType",$type);
$data->addChild("APIVersion",$version);
$data->addChild("MessageID",$message_id);

$data->addChild("MessageData");
$data->MessageData->addChild("Reference","Test1");
$data->MessageData->addChild("SendTime");
$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");

$destination1 = $data->MessageData->addChild("Destinations");
$destination1->addChild("Recipient","6495005000");
$destination1->addChild("Attention","Recipient One");
$destination1->addChild("Company","Example Corp");
$destination1->addChild("Custom1","");
$destination1->addChild("Custom2","");

$destination2 = $data->MessageData->addChild("Destinations","6495005001");
$destination3 = $data->MessageData->addChild("Destinations","6495005002");
$destination4 = $data->MessageData->addChild("Destinations","6495005003");

if( file_exists($file_name1) )
{
    $fileElement1 = $data->MessageData->addChild("Files");
    $fileElement1->addChild("Name",basename($file_name1));
    $fileElement1->addChild("Data",base64_encode($file_content1));
}

if( file_exists($file_name2) )
{
    $fileElement2 = $data->MessageData->addChild("Files");
    $fileElement2->addChild("Name",basename($file_name2));
    $fileElement2->addChild("Data",base64_encode($file_content2));
}

$headers = array(
  "Content-Type: text/xml",
  "encoding='utf-8'",
  "Content-length: ".strlen($data->asXML()),
  "Connection: close"
);  

try
{
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://www.tnz.co.nz/api/xml/send");
    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();
}
?>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>ID123456</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Xml;
using System.Windows.Forms;

using System.IO;
using System.Net;

namespace TestXML
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private string GetFileName(string strFileLocation)
        {
            return System.IO.Path.GetFileName(strFileLocation);
        }

        private byte[] GetFileContents(string strFileLocation)
        {
            //
            // Read files in bytes, convert to Base64String and return in byte[]
            //
            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);

                System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                return encoding.GetBytes(strContent);
            }
        }

        private XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
        {
            XmlNode workingNode = xmlDoc.CreateElement(name);
            workingNode.InnerText = val;

            return workingNode;
        }

        private void btnSendFax_Click(object sender, EventArgs e)
        {
            string apiURL = "https://www.tnz.co.nz/api/xml/send";

            //
            // Retrieve Fax Destination based on multi or single target
            //
            string strFileName1 = "Sample.PDF";

            Dictionary<int, String> FileNames = new Dictionary<int, String>();
            Dictionary<int, String> FileContents = new Dictionary<int, String>();

            //
            // Retrieve file(s) to fax
            //
            if (File.Exists(strFileName1))
            {
                FileNames.Add(1, GetFileName(strFileName1));
                FileContents.Add(1, System.Text.Encoding.ASCII.GetString(GetFileContents(strFileName1)));
            }

            //
            // Send Fax 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("root");
            xmlDoc.AppendChild(rootNode);

            rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com"));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd"));
            rootNode.AppendChild(addChildNode(xmlDoc, "MessageType", "Fax"));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIVersion", "1.04"));

            XmlNode workingNode = xmlDoc.CreateElement("Sender");

            //
            // MessageData
            //
            XmlNode messageDataNode = xmlDoc.CreateElement("MessageData");

            messageDataNode.AppendChild(addChildNode(xmlDoc, "Destinations", "6495005000"));

            //
            // MessageData -> Files
            //
            if (FileNames.Count > 0)
            {
                for (int i = 1; i < 10; i++)
                {
                    if (FileNames.ContainsKey(i))
                    {
                        workingNode = xmlDoc.CreateElement("Files");
                        workingNode.AppendChild(addChildNode(xmlDoc, "Name", FileNames[i]));
                        workingNode.AppendChild(addChildNode(xmlDoc, "Data", FileContents[i]));

                        messageDataNode.AppendChild(workingNode);
                    }
                }
            }

            //
            // Set MessageData into root node
            //

            rootNode.AppendChild(messageDataNode);

            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "text/xml; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }

            MessageBox.Show(strResponse); 
        }
    }
}                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Xml;
using System.Windows.Forms;

using System.IO;
using System.Net;

namespace TestXML
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private string GetFileName(string strFileLocation)
        {
            return System.IO.Path.GetFileName(strFileLocation);
        }

        private byte[] GetFileContents(string strFileLocation)
        {
            //
            // Read files in bytes, convert to Base64String and return in byte[]
            //
            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);

                System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                return encoding.GetBytes(strContent);
            }
        }

        private XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
        {
            XmlNode workingNode = xmlDoc.CreateElement(name);
            workingNode.InnerText = val;

            return workingNode;
        }

        private void btnSendFax_Click(object sender, EventArgs e)
        {
            string apiURL = "https://www.tnz.co.nz/api/xml/send";

            string strMessageType = "Fax";
            string strAPIVersion = "1.04";
            string strSender = "application@domain.com";
            string strAPIKey = "ta8wr7ymd";
            string strMessageID = "ID123456";            // optional

            string strReference = "Test1";
            string strSendTime = "";
            string strTimeZone = "New Zealand";
            string strSubAccount = "SubAccount01";
            string strDepartment = "Department01";
            string strChargeCode = "BillingGroup01";
            string strResolution = "High";
            string strCSID       = "Station ID";

            //
            // Retrieve Fax Destination based on multi or single target
            //
            string strRecipient = "6495005000";

            string strFileName1 = "Sample.PDF";
            string strFileName2 = "Sample2.PDF";

            Dictionary<int, String> FileNames = new Dictionary<int, String>();
            Dictionary<int, String> FileContents = new Dictionary<int, String>();

            //
            // Retrieve file(s) to fax
            //
            if (File.Exists(strFileName1))
            {
                FileNames.Add(1, GetFileName(strFileName1));
                FileContents.Add(1, System.Text.Encoding.ASCII.GetString(GetFileContents(strFileName1)));
            }

            if (File.Exists(strFileName2))
            {
                FileNames.Add(2, GetFileName(strFileName2));
                FileContents.Add(2, System.Text.Encoding.ASCII.GetString(GetFileContents(strFileName2)));
            }

            //
            // Send Fax 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("root");
            xmlDoc.AppendChild(rootNode);

            rootNode.AppendChild(addChildNode(xmlDoc, "Sender", strSender));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", strAPIKey));
            rootNode.AppendChild(addChildNode(xmlDoc, "MessageType", strMessageType));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIVersion", strAPIVersion));
            rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", strMessageID));

            XmlNode workingNode = xmlDoc.CreateElement("Sender");

            //
            // MessageData
            //
            XmlNode messageDataNode = xmlDoc.CreateElement("MessageData");

            messageDataNode.AppendChild(addChildNode(xmlDoc, "Reference", strReference));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "SendTime", strSendTime));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "TimeZone", strTimeZone));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "SubAccount", strSubAccount));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "Department", strDepartment));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "ChargeCode", strChargeCode));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "Resolution", strResolution));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "CSID", strCSID));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "Destinations", strRecipient));

            //
            // MessageData -> Files
            //
            if (FileNames.Count > 0)
            {
                for (int i = 1; i < 10; i++)
                {
                    if (FileNames.ContainsKey(i))
                    {
                        workingNode = xmlDoc.CreateElement("Files");
                        workingNode.AppendChild(addChildNode(xmlDoc, "Name", FileNames[i]));
                        workingNode.AppendChild(addChildNode(xmlDoc, "Data", FileContents[i]));

                        messageDataNode.AppendChild(workingNode);
                    }
                }
            }

            //
            // Set MessageData into root node
            //

            rootNode.AppendChild(messageDataNode);

            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "text/xml; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }

            MessageBox.Show(strResponse); 
        }
    }
}                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>ID123456</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

import requests
import base64
import xml.etree.ElementTree as ET

url = "https://www.tnz.co.nz/api/xml/send/"

headers = {
    "Content-Type": "text/xml",
    "encoding": "utf-8"
}

file_data = base64.b64encode(open("d:/File1.pdf","rb").read()).decode("utf-8")

root = ET.Element('root')

ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "MessageType").text = "Fax"
ET.SubElement(root, "APIVersion").text = "1.04"

message_data = ET.SubElement(root,"MessageData")
ET.SubElement(message_data, "Destinations").text = "6495005001"

message_data_files = ET.SubElement(message_data,"Files")
ET.SubElement(message_data_files,"Name").text = "File1.pdf"
ET.SubElement(message_data_files,"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))                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

import requests
import base64
import xml.etree.ElementTree as ET

url = "https://www.tnz.co.nz/api/xml/send/"

headers = {
    "Content-Type": "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('root')

ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "MessageType").text = "Fax"
ET.SubElement(root, "APIVersion").text = "1.04"
ET.SubElement(root, "MessageID").text = "ID123456"

message_data = ET.SubElement(root,"MessageData")
ET.SubElement(message_data, "Reference").text = "Test1"
ET.SubElement(message_data, "SendTime").text = ""
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")
ET.SubElement(destinations,"Recipient").text = "6495005000"
ET.SubElement(destinations,"Attention").text = "Recipient One"
ET.SubElement(destinations,"Company").text = "Example Corp"
ET.SubElement(destinations,"Custom1").text = ""
ET.SubElement(destinations,"Custom2").text = ""

ET.SubElement(message_data, "Destinations").text = "6495005001"
ET.SubElement(message_data, "Destinations").text = "6495005002"
ET.SubElement(message_data, "Destinations").text = "6495005003"

message_data_files = ET.SubElement(message_data,"Files")
ET.SubElement(message_data_files,"Name").text = "File1.pdf"
ET.SubElement(message_data_files,"Data").text = file_data_1

message_data_files = ET.SubElement(message_data,"Files")
ET.SubElement(message_data_files,"Name").text = "File2.pdf"
ET.SubElement(message_data_files,"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))                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>ID123456</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                

Required MessageData parameters

Parameter Example Value Description
Destinations 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

Optional MessageData parameters

Parameter Example Value Description
Reference Test1 Tracking ID or message description
SendTime 08/12/2019 13:04 Delay sending until the specified date/time (dd/mm/yyyy HH:mm in your local timezone, specified by your Sender setting or overridden using the TimeZone command)
TimeZone New Zealand Timezone specified using Windows timezone value (default set using Web Dashboard can be overridden here)
See Microsoft Timezones (use the Country value)
SubAccount SubAccount01 Used for reporting, billing and Web Dashboard segmentation
Department Department01 Used for reporting, billing and Web Dashboard segmentation
ChargeCode BillingGroup01 Cost allocation for billing
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 Recipient One Recipient's friendly name
> Company Example Corp Recipient's company
> Custom1 Recipient One Customisable field
> Custom2 Recipient One Customisable field

MessageType=Voice - Send VoiceCast via REST API

 
 
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "MessageType": "Voice",
    "APIVersion": "1.04",
    "MessageData" :
    {
        "MessageToPeople": "[base64 encoded WAV audio data, 16-bit, 8000hz]",
        "Destinations" : 
        [
            "6495005001"
        ]
    }
}                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "MessageType": "Voice",
    "APIVersion": "1.04",
    "MessageID": "ID123456",
    "MessageData" :
    {
        "Reference": "Test1",
        "SendTime": "",
        "TimeZone": "New Zealand",
        "SubAccount": "SubAccount01",
        "Department": "Department01",
        "ChargeCode": "BillingGroup01",
        "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",
                "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",
        "RetryAttempts": "3",
        "RetryPeriod": "1",
        "Options": "",
        "Destinations" : 
        [
            {
                "Recipient": "6421000001",
                "Custom1": "",
                "Custom2": ""
            },
            "6495005002",
            "6421000003"
        ]
    }
}                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "ID123456"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/json/send \
  --header "Content-Type: application/json; encoding='utf-8'" \
  --data '{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "MessageType": "Voice",
    "APIVersion": "1.04",
    "MessageData" :
    {
        "MessageToPeople": "[base64 encoded WAV audio data, 16-bit, 8000hz]",
        "Destinations" : 
        [
            "6495005001"
        ]
    }
  }'                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/json/send \
  --header "Content-Type: application/json; encoding='utf-8'" \
  --data '{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "MessageType": "Voice",
    "APIVersion": "1.04",
    "MessageID": "ID123456",
    "MessageData" :
    {
        "Reference": "Test1",
        "SendTime": "",
        "TimeZone": "New Zealand",
        "SubAccount": "SubAccount01",
        "Department": "Department01",
        "ChargeCode": "BillingGroup01",
        "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",
                "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",
        "RetryAttempts": "3",
        "RetryPeriod": "1",
        "Options": "",
        "Destinations" : 
        [
            {
                "Recipient": "6421000001",
                "Custom1": "",
                "Custom2": ""
            },
            "6495005002",
            "6421000003"
        ]
    }
  }'                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "ID123456"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

<?php

$data = array(
    "Sender" => "application@domain.com",
    "APIKey" => "ta8wr7ymd",
    "MessageType" => "Voice",
    "APIVersion" => "1.04",
    "MessageData" => array(
        "MessageToPeople" => "[base64 encoded WAV audio data, 16-bit, 8000hz]",
        "Destinations" => array(
            "6495005001"
        ),
    )
);

$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://www.tnz.co.nz/api/json/send");
    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();
}

?>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

<?php

$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "Voice";
$version = "1.04";
$message_id = "ID123456";           // optional

$data = array(
    "Sender" => $sender,
    "APIKey" => $apikey,
    "MessageType" => $type,
    "APIVersion" => $version,
    "MessageID" => $message_id,
    "MessageData" => array(
        "Reference" => "Test1",
        "SendTime" => "",
        "TimeZone" => "New Zealand",
        "SubAccount" => "SubAccount01",
        "Department" => "Department01",
        "ChargeCode" => "BillingGroup01",
        "MessageToPeople" => "[base64 encoded WAV audio data, 16-bit, 8000hz]",
        "MessageToAnswerphones" => "[base64 encoded WAV audio data, 16-bit, 8000hz]",
        "Keypads" => array(
            array(
                "Tone" => 1,
                "RouteNumber" => "64800123123"
            ),
            array(
                "Tone" => 2,
                "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",
        "RetryAttempts" => "3",
        "RetryPeriod" => "1",
        "Options" => "",
        "Destinations" => array(
            array(
                "Recipient" => "6421000001",
                "Custom1" => "",
                "Custom2" => ""
            ),
            "6495005002",
            "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://www.tnz.co.nz/api/json/send");
    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();
}

?>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "ID123456"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.IO;
using System.Net;

namespace SendVoiceJSON
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        private void SendVoice()
        {
            string apiURL = "https://www.tnz.co.nz/api/json/send";
            
            string strSender = "application@domain.com";
            string strToken = "ta8wr7ymd";
            string strMessageType = "Voice";
            string strAPIVersion = "1.04";
            
            string strMsgToPeople = "[base64 encoded WAV audio data, 16-bit, 8000hz]";
            
            string strRecipient = "6421000001";
            
            //
            // Send Voice by REST API Interface
            //

            string EOL = "\r\n";

            string strJSONData = "{" + EOL +
                    "\"Sender\": \"" + strSender + "\"," + EOL +
                    "\"APIKey\": \"" + strToken + "\"," + EOL +
                    "\"MessageType\": \"" + strMessageType + "\"," + EOL +
                    "\"APIVersion\": \"" + strAPIVersion + "\"," + EOL +
                    "\"MessageData\": {" + EOL +
                        "\"MessageToPeople\": \"" + strMsgToPeople + "\"," + EOL +
                        "\"Destinations\" :" + EOL +
                        "[" + EOL +
                            "\"" + strRecipient + "\"" + EOL +
                        "]" + EOL +
                    "}" + EOL +
                "}";

            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "application/json; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }

            MessageBox.Show(strResponse);      
        }
    }
}                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.IO;
using System.Net;

namespace SendVoiceJSON
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        private void SendVoice()
        {
            string apiURL = "https://www.tnz.co.nz/api/json/send";
            
            string strSender = "application@domain.com";
            string strToken = "ta8wr7ymd";
            string strMessageType = "Voice";
            string strAPIVersion = "1.04";
            string strMessageID = "ID123456";           // optional
            
            string strReference = "Test1";
            string strSendTime = "";
            string strTimeZone = "New Zealand";
            string strSubAccount = "SubAccount01";
            string strDepartment = "Department01";
            string strChargeCode = "BillingGroup01";
            
            string strMsgToPeople = "[base64 encoded WAV audio data, 16-bit, 8000hz]";
            string strMsgToAnswerPhones = "[base64 encoded WAV audio data, 16-bit, 8000hz]";             
            string strKeypads = "";
            
            Dictionary<int,string> Keypads = new Dictionary<int,string>();
            
            Keypads.Add(1,"64800123123");
            Keypads.Add(2,"6498008000");
            
            if (Keypads.Count > 0)
            {
                for (int i = 1; i < 10; i++)
                {
                    if (Keypads.ContainsKey(i))
                    {
                        sb.Append("{").AppendFormat("\"Tone\":{0}, \"RouteNumber\": \"{1}\"", i.ToString(), Keypads[i]).Append("}");

                        if (Keypads.ContainsKey(i + 1))
                        {
                            sb.Append(",");
                        }
                    }
                }

                strKeypads = "\"Keypads\": [" + sb.ToString() + "]," + EOL;
            }
            
            string strCallRouteMsgToPeople = "[base64 encoded WAV audio data, 16-bit, 8000hz]";
            string strCallRouteMsgToOperators = "[base64 encoded WAV audio data, 16-bit, 8000hz]";
            string strCallRouteMsgOnWrongKey = "[base64 encoded WAV audio data, 16-bit, 8000hz]";
            string strNumberOfOperators = "5";
            string strRetryAttempts = "3";
            string strRetryPeriod = "1";
            string strOptions = "";

            string strRecipient = "6421000001";
            
            //
            // Send Voice by REST API Interface
            //

            string EOL = "\r\n";

            string strJSONData = "{" + EOL +
                    "\"Sender\": \"" + strSender + "\"," + EOL +
                    "\"APIKey\": \"" + strToken + "\"," + EOL +
                    "\"MessageType\": \"" + strMessageType + "\"," + EOL +
                    "\"APIVersion\": \"" + strAPIVersion + "\"," + EOL +
                    "\"MessageID\": \"" + strMessageID + "\"," + EOL +
                    "\"MessageData\": {" + EOL +
                        "\"Reference\": \"" + strReference + "\"," + EOL +
                        "\"SendTime\": \"" + strSendTime + "\"," + EOL +
                        "\"TimeZone\": \"" + strTimeZone + "\"," + EOL +
                        "\"SubAccount\": \"" + strSubAccount + "\"," + EOL +
                        "\"Department\": \"" + strDepartment + "\"," + EOL +
                        "\"ChargeCode\": \"" + strChargeCode + "\"," + EOL +
                        "\"MessageToPeople\": \"" + strMsgToPeople + "\"," + EOL +
                        "\"MessageToAnswerphones\": \"" + strMsgToAnswerPhones + "\"," + EOL +
                        strKeypads +
                        "\"CallRouteMessageToPeople\": \"" + strCallRouteMsgToPeople + "\"," + EOL +
                        "\"CallRouteMessageToOperators\": \"" + strCallRouteMsgToOperators + "\"," + EOL +
                        "\"CallRouteMessageOnWrongKey\": \"" + strCallRouteMsgOnWrongKey + "\"," + EOL +
                        "\"NumberOfOperators\": \"" + strNumberOfOperators + "\"," + EOL +
                        "\"RetryAttempts\": \"" + strRetryAttempts + "\"," + EOL +
                        "\"RetryPeriod\": \"" + strRetryPeriod + "\"," + EOL +
                        "\"Voice\": \"" + strVoice + "\"," + EOL +
                        "\"Options\":\"\"," + EOL +
                        "\"Destinations\" :" + EOL +
                        "[" + EOL +
                            "\"" + strRecipient + "\"" + EOL +
                        "]" + EOL +
                    "}" + EOL +
                "}";

            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "application/json; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }

            MessageBox.Show(strResponse);      
        }
    }
}                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "ID123456"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

import requests
import base64
import json

url = "https://www.tnz.co.nz/api/json/send/"

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",
    "MessageType": "Voice",
    "APIVersion": "1.04",
    "MessageData" :
    {
        "MessageToPeople": file_data,
        "Destinations" : 
        [
            "6495005001"
        ]
    }
}

r = requests.post(url, data=json.dumps(data), headers=headers)

print(r)
print(r.text)                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

import requests
import base64
import json

url = "https://www.tnz.co.nz/api/json/send/"

headers = {
    "Content-Type": "application/json",
    "encoding": "utf-8"
}

voice_files = {
    "MessageToPeople": "d:/1.Intro.wav",
    "MessageToAnswerphones": "d:/1.Intro.wav",
    "CallRouteMessageToPeople": "d:/1.Intro.wav",
    "CallRouteMessageToOperators": "d:/1.Intro.wav",
    "CallRouteMessageOnWrongKey": "d:/1.Intro.wav",
}

data = {
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "MessageType": "Voice",
    "APIVersion": "1.04",
    "MessageID": "ID123456",
    "MessageData" :
    {
         "Reference": "Test1",
        "SendTime": "",
        "TimeZone": "New Zealand",
        "SubAccount": "SubAccount01",
        "Department": "Department01",
        "ChargeCode": "BillingGroup01",
        "MessageToPeople": base64.b64encode(open(voice_files["MessageToPeople"],"rb").read()).decode("utf-8"),
        "MessageToAnswerphones": base64.b64encode(open(voice_files["MessageToAnswerphones"],"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",
                "Custom1": "",
                "Custom2": ""
            },
            "6495005002",
            "6421000003"
        ]
    }
}

r = requests.post(url, data=json.dumps(data), headers=headers)

print(r)
print(r.text)                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "ID123456"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <Sender>application@domain.com</Sender>
  <APIKey>ta8wr7ymd</APIKey>
  <MessageType>Voice</MessageType>
  <APIVersion>1.04</APIVersion>
  <MessageData>
    <MessageToPeople>[base64 encoded WAV audio data, 16-bit, 8000hz]</MessageToPeople>
    <Destinations>6495005001</Destinations>
  </MessageData>
</root>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <Sender>application@domain.com</Sender>
  <APIKey>ta8wr7ymd</APIKey>
  <MessageType>Voice</MessageType>
  <APIVersion>1.04</APIVersion>
  <MessageID>ID123456</MessageID>
  <MessageData>
    <Reference>Test1</Reference>
    <SendTime></SendTime>
    <TimeZone>New Zealand</TimeZone>
    <SubAccount>SubAccount01</SubAccount>
    <Department>Department01</Department>
    <ChargeCode>BillingGroup01</ChargeCode>
    <MessageToPeople>[base64 encoded WAV audio data, 16-bit, 8000hz]</MessageToPeople>
    <MessageToAnswerphones>[base64 encoded WAV audio data, 16-bit, 8000hz]</MessageToAnswerphones>
    <Keypads>
      <Tone>1</Tone>
      <RouteNumber>64800123123</RouteNumber>
    </Keypads>
    <Keypads>
      <Tone>2</Tone>
      <RouteNumber>6498008000</RouteNumber>
    </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>
        <Recipient>6421000001</Recipient>
        <Custom1></Custom1>
        <Custom2></Custom2>
    </Destinations>
    <Destinations>6495005002</Destinations>
    <Destinations>6421000003</Destinations>
  </MessageData>
</root>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>ID123456</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/xml/send \
  --header "Content-Type: text/xml; encoding='utf-8'" \
  --data '
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
      <Sender>application@domain.com</Sender>
      <APIKey>ta8wr7ymd</APIKey>
      <MessageType>Voice</MessageType>
      <APIVersion>1.04</APIVersion>
      <MessageData>
        <MessageToPeople>[base64 encoded WAV audio data, 16-bit, 8000hz]</MessageToPeople>
        <Destinations>6495005001</Destinations>
      </MessageData>
    </root>
  '                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/xml/send \
  --header "Content-Type: text/xml; encoding='utf-8'" \
  --data '
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
      <Sender>application@domain.com</Sender>
      <APIKey>ta8wr7ymd</APIKey>
      <MessageType>Voice</MessageType>
      <APIVersion>1.04</APIVersion>
      <MessageID>ID123456</MessageID>
      <MessageData>
        <Reference>Test1</Reference>
        <SendTime></SendTime>
        <TimeZone>New Zealand</TimeZone>
        <SubAccount>SubAccount01</SubAccount>
        <Department>Department01</Department>
        <ChargeCode>BillingGroup01</ChargeCode>
        <MessageToPeople>[base64 encoded WAV audio data, 16-bit, 8000hz]</MessageToPeople>
        <MessageToAnswerphones>[base64 encoded WAV audio data, 16-bit, 8000hz]</MessageToAnswerphones>
        <Keypads>
          <Tone>1</Tone>
          <RouteNumber>64800123123</RouteNumber>
        </Keypads>
        <Keypads>
          <Tone>2</Tone>
          <RouteNumber>6498008000</RouteNumber>
        </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>
            <Recipient>6421000001</Recipient>
            <Custom1></Custom1>
            <Custom2></Custom2>
        </Destinations>
        <Destinations>6495005002</Destinations>
        <Destinations>6421000003</Destinations>
      </MessageData>
    </root>
  '                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>ID123456</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?php

$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "Voice";
$version = "1.04";

$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><root></root>");

$data->addChild("Sender",$sender);
$data->addChild("APIKey",$apikey);
$data->addChild("MessageType",$type);
$data->addChild("APIVersion",$version);

$data->addChild("MessageData");
$data->MessageData->addChild("MessageToPeople","[base64 encoded WAV audio data, 16-bit, 8000hz]");
$data->MessageData->addChild("Destinations","6495005001");

$headers = array(
  "Content-Type: text/xml",
  "encoding='utf-8'",
  "Content-length: ".strlen($data->asXML()),
  "Connection: close"
);  

try
{
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://www.tnz.co.nz/api/xml/send");
    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();
}

?>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?php

$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "Voice";
$version = "1.04";
$message_id = "ID123456";

$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><root></root>");

$data->addChild("Sender",$sender);
$data->addChild("APIKey",$apikey);
$data->addChild("MessageType",$type);
$data->addChild("APIVersion",$version);
$data->addChild("MessageID",$message_id);

$data->addChild("MessageData");
$data->MessageData->addChild("Reference","Test1");
$data->MessageData->addChild("SendTime");
$data->MessageData->addChild("TimeZone","New Zealand");
$data->MessageData->addChild("SubAccount","SubAccount01");
$data->MessageData->addChild("Department","Department01");
$data->MessageData->addChild("ChargeCode","BillingGroup01");
$data->MessageData->addChild("MessageToPeople","[base64 encoded WAV audio data, 16-bit, 8000hz]");
$data->MessageData->addChild("MessageToAnswerphones","[base64 encoded WAV audio data, 16-bit, 8000hz]");

$keypad1 = $data->MessageData->addChild("Keypads");
$keypad1->addChild("Tone",1);
$keypad1->addChild("RouteNumber","64800123123");

$keypad2 = $data->MessageData->addChild("Keypads");
$keypad2->addChild("Tone",2);
$keypad2->addChild("RouteNumber","6498008000");

$data->MessageData->addChild("CallRouteMessageToPeople","[base64 encoded WAV audio data, 16-bit, 8000hz]");
$data->MessageData->addChild("CallRouteMessageToOperators","[base64 encoded WAV audio data, 16-bit, 8000hz]");
$data->MessageData->addChild("CallRouteMessageOnWrongKey","[base64 encoded WAV audio data, 16-bit, 8000hz]");
$data->MessageData->addChild("NumberOfOperators",5);
$data->MessageData->addChild("RetryAttempts",3);
$data->MessageData->addChild("RetryPeriod",5);
$data->MessageData->addChild("Options","");

$destination1 = $data->MessageData->addChild("Destinations");
$destination1->addChild("Recipient","6421000001");
$destination1->addChild("Custom1","");
$destination1->addChild("Custom2","");

$destination2 = $data->MessageData->addChild("Destinations","6495005002");
$destination3 = $data->MessageData->addChild("Destinations","6421000003");

$headers = array(
  "Content-Type: text/xml",
  "encoding='utf-8'",
  "Content-length: ".strlen($data->asXML()),
  "Connection: close"
);  

try
{
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://www.tnz.co.nz/api/xml/send");
    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();
}
?>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>ID123456</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Xml;
using System.Windows.Forms;

using System.IO;
using System.Net;

namespace TestXML
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
        {
            XmlNode workingNode = xmlDoc.CreateElement(name);
            workingNode.InnerText = val;

            return workingNode;
        }
        
        private void btnSendVoice_Click(object sender, EventArgs e)
        {
            //
            // Populating values from frmMain
            //
            string apiURL = "https://www.tnz.co.nz/api/xml/send";

            string strSender = "application@domain.com";
            string strAPIKey = "ta8wr7ymd";
            string strMessageType = "Voice";
            string strAPIVersion = "1.04";

            string strMsgToPeople = "[base64 encoded WAV audio data, 16-bit, 8000hz]";
            string strRecipient = "6421000001";

            //
            // 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("root");
            xmlDoc.AppendChild(rootNode);

            rootNode.AppendChild(addChildNode(xmlDoc, "Sender", strSender));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", strAPIKey));
            rootNode.AppendChild(addChildNode(xmlDoc, "MessageType", strMessageType));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIVersion", strAPIVersion));

            XmlNode workingNode = xmlDoc.CreateElement("Sender");

            //
            // MessageData
            //
            XmlNode messageDataNode = xmlDoc.CreateElement("MessageData");

            messageDataNode.AppendChild(addChildNode(xmlDoc, "MessageToPeople", strMsgToPeople));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "Destinations", strRecipient));

            //
            // Set MessageData into root node
            //

            rootNode.AppendChild(messageDataNode);

            //
            // Send Raw XML API Request to REST API
            //            

            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "text/xml; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }

            MessageBox.Show(strResponse); 
        }

    }
}                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Xml;
using System.Windows.Forms;

using System.IO;
using System.Net;

namespace TestXML
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
        {
            XmlNode workingNode = xmlDoc.CreateElement(name);
            workingNode.InnerText = val;

            return workingNode;
        }
        
        private void btnSendVoice_Click(object sender, EventArgs e)
        {
            //
            // Populating values from frmMain
            //
            string apiURL = "https://www.tnz.co.nz/api/xml/send";

            string strSender = "application@domain.com";
            string strAPIKey = "ta8wr7ymd";
            string strMessageType = "Voice";
            string strAPIVersion = "1.04";
            string strMessageID = "ID123456";           // optional

            string strReference = "Test1";
            string strSendTime = "";
            string strTimeZone = "New Zealand";
            string strSubAccount = "SubAccount01";
            string strDepartment = "Department01";
            string strChargeCode = "BillingGroup01";

            string strMsgToPeople = "[base64 encoded WAV audio data, 16-bit, 8000hz]";
            string strMsgToAnswerPhones = "[base64 encoded WAV audio data, 16-bit, 8000hz]";

            Dictionary<int, string> Keypads = new Dictionary<int, string>();

            Keypads.Add(1, "64800123123");
            Keypads.Add(2, "6498008000");

            string strCallRouteMsgToPeople = "[base64 encoded WAV audio data, 16-bit, 8000hz]";
            string strCallRouteMsgToOperators = "[base64 encoded WAV audio data, 16-bit, 8000hz]";
            string strCallRouteMsgOnWrongKey = "[base64 encoded WAV audio data, 16-bit, 8000hz]";

            string strNumberOfOperators = "5";
            string strRetryAttempts = "3";
            string strRetryPeriod = "1";

            string strOptions = "";

            string strRecipient = "6421000001";

            //
            // 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("root");
            xmlDoc.AppendChild(rootNode);

            rootNode.AppendChild(addChildNode(xmlDoc, "Sender", strSender));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", strAPIKey));
            rootNode.AppendChild(addChildNode(xmlDoc, "MessageType", strMessageType));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIVersion", strAPIVersion));
            rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", strMessageID));

            XmlNode workingNode = xmlDoc.CreateElement("Sender");

            //
            // MessageData
            //
            XmlNode messageDataNode = xmlDoc.CreateElement("MessageData");

            messageDataNode.AppendChild(addChildNode(xmlDoc, "Reference", strReference));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "SendTime", strSendTime));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "TimeZone", strTimeZone));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "SubAccount", strSubAccount));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "Department", strDepartment));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "ChargeCode", strChargeCode));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "MessageToPeople", strMsgToPeople));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "MessageToAnswerphones", strMsgToAnswerPhones));

            //
            // MessageData -> Keypads
            //
            if (Keypads.Count > 0)
            {
                for (int i = 1; i < 10; i++)
                {
                    if (Keypads.ContainsKey(i))
                    {
                        workingNode = xmlDoc.CreateElement("Keypads");
                        workingNode.AppendChild(addChildNode(xmlDoc, "Tone", i.ToString()));
                        workingNode.AppendChild(addChildNode(xmlDoc, "RouteNumber", Keypads[i]));

                        messageDataNode.AppendChild(workingNode);
                    }
                }
            }

            messageDataNode.AppendChild(addChildNode(xmlDoc, "CallRouteMessageToPeople", strCallRouteMsgToPeople));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "CallRouteMessageToOperators", strCallRouteMsgToOperators));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "CallRouteMessageOnWrongKey", strCallRouteMsgOnWrongKey));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "NumberOfOperators", strNumberOfOperators));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "RetryAttempts", strRetryAttempts));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "RetryPeriod", strRetryPeriod));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "Voice", strVoice));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "Options", strOptions));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "Destinations", strRecipient));

            //
            // Set MessageData into root node
            //

            rootNode.AppendChild(messageDataNode);

            //
            // Send Raw XML API Request to REST API
            //            

            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "text/xml; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }

            MessageBox.Show(strResponse); 
        }

    }
}                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>ID123456</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

import requests
import base64
import xml.etree.ElementTree as ET

url = "https://www.tnz.co.nz/api/xml/send/"

headers = {
    "Content-Type": "text/xml",
    "encoding": "utf-8"
}

file_data = base64.b64encode(open("d:/1.Intro.wav","rb").read()).decode("utf-8")

root = ET.Element('root')

ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "MessageType").text = "Voice"
ET.SubElement(root, "APIVersion").text = "1.04"

message_data = ET.SubElement(root,"MessageData")
ET.SubElement(message_data, "MessageToPeople").text = file_data
ET.SubElement(message_data, "Destinations").text = "6495005001"

r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)

print(r)
print(r.text)                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

import requests
import base64
import xml.etree.ElementTree as ET

url = "https://www.tnz.co.nz/api/xml/send/"

headers = {
    "Content-Type": "text/xml",
    "encoding": "utf-8"
}

voice_files = {
    "MessageToPeople": "d:/1.Intro.wav",
    "MessageToAnswerphones": "d:/1.Intro.wav",
    "CallRouteMessageToPeople": "d:/1.Intro.wav",
    "CallRouteMessageToOperators": "d:/1.Intro.wav",
    "CallRouteMessageOnWrongKey": "d:/1.Intro.wav",
}

root = ET.Element('root')

ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "MessageType").text = "Voice"
ET.SubElement(root, "APIVersion").text = "1.04"
ET.SubElement(root, "MessageID").text = "ID123456"

message_data = ET.SubElement(root,"MessageData")
ET.SubElement(message_data, "Reference").text = "Test1"
ET.SubElement(message_data, "SendTime").text = ""
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, "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")
ET.SubElement(keypads,"Tone").text = "1"
ET.SubElement(keypads,"RouteNumber").text = "64800123123"

keypads = ET.SubElement(message_data,"Keypads")
ET.SubElement(keypads,"Tone").text = "2"
ET.SubElement(keypads,"RouteNumber").text = "6498008000"

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 = "5"
ET.SubElement(message_data, "Options").text = "5"

destinations = ET.SubElement(message_data,"Destinations")
ET.SubElement(destinations,"Recipient").text = "6421000001"
ET.SubElement(destinations,"Custom1").text = ""
ET.SubElement(destinations,"Custom2").text = ""

ET.SubElement(message_data, "Destinations").text = "6495005002"
ET.SubElement(message_data, "Destinations").text = "6421000003"

r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)

print(r)
print(r.text)                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>ID123456</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                

Required MessageData parameters

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 6495005001
6495005002
6495005003
Telephone number(s) to receive the message (for detailed formatting, see the Destinations parameter below)

Optional MessageData parameters

Parameter Example Value Description
Reference Test1 Tracking ID or message description
SendTime 08/12/2019 13:04 Delay sending until the specified date/time (dd/mm/yyyy HH:mm in your local timezone, specified by your Sender setting or overridden using the TimeZone command)
TimeZone New Zealand Timezone specified using Windows timezone value (default set using Web Dashboard can be overridden here)
See Microsoft Timezones (use the Country value)
SubAccount SubAccount01 Used for reporting, billing and Web Dashboard segmentation
Department Department01 Used for reporting, billing and Web Dashboard segmentation
ChargeCode BillingGroup01 Cost allocation for billing
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
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
Destinations > Recipient 6495005000 Recipient of the call in E.164 internationalised format (for localized or friendly formatting, contact your account manager)
> Attention Recipient One Recipient's friendly name
> Company Example Corp Recipient's company
> Custom1 Recipient One Customisable field
> Custom2 Recipient One Customisable field

MessageType=TextToSpeech - Send TTS via REST API

 
 
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "MessageType": "TextToSpeech",
    "APIVersion": "1.04",
    "MessageData" :
    {
        "MessageToPeople": "Hello, this is a call from test. This is relevant information.",
        "Destinations" : 
        [
            "6495005001"
        ]
    }
}                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "MessageType": "TextToSpeech",
    "APIVersion": "1.04",
    "MessageID": "ID123456",
    "MessageData" :
    {
        "Reference": "Test1",
        "SendTime": "",
        "TimeZone": "New Zealand",
        "SubAccount": "SubAccount01",
        "Department": "Department01",
        "ChargeCode": "BillingGroup01",
        "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": "Female2",
        "Options": "",
        "Destinations" : 
        [
            {
                "Recipient": "6421000001",
                "Custom1": "",
                "Custom2": ""
            },
            "6495005002",
            "6421000003"
        ]
    }
}                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "ID123456"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/json/send \
  --header "Content-Type: application/json; encoding='utf-8'" \
  --data '{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "MessageType": "TextToSpeech",
    "APIVersion": "1.04",
    "MessageData" :
    {
        "MessageToPeople": "Hello, this is a call from test. This is relevant information.",
        "Destinations" : 
        [
            "6495005001"
        ]
    }
  }'                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/json/send \
  --header "Content-Type: application/json; encoding='utf-8'" \
  --data '{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "MessageType": "TextToSpeech",
    "APIVersion": "1.04",
    "MessageID": "ID123456",
    "MessageData" :
    {
        "Reference": "Test1",
        "SendTime": "",
        "TimeZone": "New Zealand",
        "SubAccount": "SubAccount01",
        "Department": "Department01",
        "ChargeCode": "BillingGroup01",
        "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": "Female2",
        "Options": "",
        "Destinations" : 
        [
            {
                "Recipient": "6421000001",
                "Custom1": "",
                "Custom2": ""
            },
            "6495005002",
            "6421000003"
        ]
    }
  }'                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "ID123456"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

<?php

$data = array(
    "Sender" => "application@domain.com",
    "APIKey" => "ta8wr7ymd",
    "MessageType" => "TextToSpeech",
    "APIVersion" => "1.04",
    "MessageData" => array(
        "MessageToPeople" => "Hello, this is a call from test. This is relevant information.",
        "Destinations" => array(
            "6495005001"
        ),
    )
);

$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://www.tnz.co.nz/api/json/send");
    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();
}

?>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

<?php

$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "TextToSpeech";
$version = "1.04";
$message_id = "ID123456";           // optional

$data = array(
    "Sender" => $sender,
    "APIKey" => $apikey,
    "MessageType" => $type,
    "APIVersion" => $version,
    "MessageID" => $message_id,
    "MessageData" => array(
        "Reference" => "Test1",
        "SendTime" => "",
        "TimeZone" => "New Zealand",
        "SubAccount" => "SubAccount01",
        "Department" => "Department01",
        "ChargeCode" => "BillingGroup01",
        "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" => "Female2",
        "Options" => "",
        "Destinations" => array(
            array(
                "Recipient" => "6421000001",
                "Custom1" => "",
                "Custom2" => ""
            ),
            "6495005002",
            "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://www.tnz.co.nz/api/json/send");
    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();
}

?>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "ID123456"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

using System;
using System.Text;

using System.IO;
using System.Net;

namespace TTSSimple
{
    class Program
    {
        static void Main(string[] args)
        {
            string apiURL = "https://www.tnz.co.nz/api/json/send";

            //
            // Send TTS by REST API Interface
            //
            
            string strJSONData = @"{
                ""Sender"": ""application@domain.com"",
                ""APIKey"": ""ta8wr7ymd"",
                ""MessageType"": ""TextToSpeech"",
                ""APIVersion"": ""1.04"",
                ""MessageData"": {
                    ""MessageToPeople"": ""Hello, this is a call from test. This is relevant information."",
                    ""Destinations"":
                    [
                        ""6495005001""
                    ]
                }
            }";

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

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            using (StreamReader sr = new StreamReader(response.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }

            Console.WriteLine(strResponse);
        }
    }
}
                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
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://www.tnz.co.nz/api/json/send";

            //
            // Send TTS by REST API Interface
            //

            string strJSONData = @"{
                ""Sender"": ""application@domain.com"",
                ""APIKey"": ""ta8wr7ymd"",
                ""MessageType"": ""TextToSpeech"",
                ""APIVersion"": ""1.04"",
                ""MessageID"": ""ID123456"",
                ""MessageData"": {
                    ""Reference"": ""Test1"",
                    ""SendTime"": """",
                    ""TimeZone"": ""New Zealand"",
                    ""SubAccount"": ""SubAccount01"",
                    ""Department"": ""Department01"",
                    ""ChargeCode"": ""BillingGroup01"",
                    ""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"": ""Female2"",
                    ""Options"": """",
                    ""Destinations"":
                    [
                        {
                            ""Recipient"": ""6421000001"",
                            ""Custom1"": """",
                            ""Custom2"": """"
                        },
                        ""6495005002"",
                        ""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);
        }
    }
}
                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "ID123456"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

import requests
import json

url = "https://www.tnz.co.nz/api/json/send/"

headers = {
    "Content-Type": "application/json",
    "encoding": "utf-8"
}

data = {
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "MessageType": "TextToSpeech",
    "APIVersion": "1.04",
    "MessageData" :
    {
        "MessageToPeople": "Hello, this is a call from test. This is relevant information.",
        "Destinations" : 
        [
            "6495005001"
        ]
    }
}

r = requests.post(url, data=json.dumps(data), headers=headers)

print(r)
print(r.text)                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/json/send/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

import requests
import json

url = "https://www.tnz.co.nz/api/json/send/"

headers = {
    "Content-Type": "application/json",
    "encoding": "utf-8"
}

data = {
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "MessageType": "TextToSpeech",
    "APIVersion": "1.04",
    "MessageID": "ID123456",
    "MessageData" :
    {
        "Reference": "Test1",
        "SendTime": "",
        "TimeZone": "New Zealand",
        "SubAccount": "SubAccount01",
        "Department": "Department01",
        "ChargeCode": "BillingGroup01",
        "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": "Female2",
        "Options": "",
        "Destinations" : 
        [
            {
                "Recipient": "6421000001",
                "Custom1": "",
                "Custom2": ""
            },
            "6495005002",
            "6421000003"
        ]
    }
}

r = requests.post(url, data=json.dumps(data), headers=headers)

print(r)
print(r.text)                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "MessageID": "ID123456"
}                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Missing Sender"
}                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <Sender>application@domain.com</Sender>
  <APIKey>ta8wr7ymd</APIKey>
  <MessageType>TextToSpeech</MessageType>
  <APIVersion>1.04</APIVersion>
  <MessageData>
    <MessageToPeople>Hello, this is a call from test. This is relevant information.</MessageToPeople>
    <Destinations>6495005001</Destinations>
  </MessageData>
</root>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <Sender>application@domain.com</Sender>
  <APIKey>ta8wr7ymd</APIKey>
  <MessageType>TextToSpeech</MessageType>
  <APIVersion>1.04</APIVersion>
  <MessageID>ID123456</MessageID>
  <MessageData>
    <Reference>Test1</Reference>
    <SendTime></SendTime>
    <TimeZone>New Zealand</TimeZone>
    <SubAccount>SubAccount01</SubAccount>
    <Department>Department01</Department>
    <ChargeCode>BillingGroup01</ChargeCode>
    <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>
      <Tone>1</Tone>
      <RouteNumber>64800123123</RouteNumber>
    </Keypads>
    <Keypads>
      <Tone>2</Tone>
	  <Play>You pressed Keypad 2</Play>
      <RouteNumber>6498008000</RouteNumber>
    </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>Female2</Voice>
    <Options></Options>
    <Destinations>
        <Recipient>6421000001</Recipient>
        <Custom1></Custom1>
        <Custom2></Custom2>
    </Destinations>
    <Destinations>6495005002</Destinations>
    <Destinations>6421000003</Destinations>
  </MessageData>
</root>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>ID123456</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/xml/send \
  --header "Content-Type: text/xml; encoding='utf-8'" \
  --data '
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
      <Sender>application@domain.com</Sender>
      <APIKey>ta8wr7ymd</APIKey>
      <MessageType>TextToSpeech</MessageType>
      <APIVersion>1.04</APIVersion>
      <MessageData>
        <MessageToPeople>Hello, this is a call from test. This is relevant information.</MessageToPeople>
        <Destinations>6495005001</Destinations>
      </MessageData>
    </root>
  '                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/xml/send \
  --header "Content-Type: text/xml; encoding='utf-8'" \
  --data '
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
      <Sender>application@domain.com</Sender>
      <APIKey>ta8wr7ymd</APIKey>
      <MessageType>TextToSpeech</MessageType>
      <APIVersion>1.04</APIVersion>
      <MessageID>ID123456</MessageID>
      <MessageData>
        <Reference>Test1</Reference>
        <SendTime></SendTime>
        <TimeZone>New Zealand</TimeZone>
        <SubAccount>SubAccount01</SubAccount>
        <Department>Department01</Department>
        <ChargeCode>BillingGroup01</ChargeCode>
        <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>
          <Tone>1</Tone>
          <RouteNumber>64800123123</RouteNumber>
        </Keypads>
        <Keypads>
          <Tone>2</Tone>
		  <Play>You pressed Keypad 2</Play>
          <RouteNumber>6498008000</RouteNumber>
        </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>Female2</Voice>
        <Options></Options>
        <Destinations>
            <Recipient>6421000001</Recipient>
            <Custom1></Custom1>
            <Custom2></Custom2>
        </Destinations>
        <Destinations>6495005002</Destinations>
        <Destinations>6421000003</Destinations>
      </MessageData>
    </root>
  '                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>ID123456</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?php

$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "TextToSpeech";
$version = "1.04";

$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><root></root>");

$data->addChild("Sender",$sender);
$data->addChild("APIKey",$apikey);
$data->addChild("MessageType",$type);
$data->addChild("APIVersion",$version);

$data->addChild("MessageData");
$data->MessageData->addChild("MessageToPeople","Hello, this is a call from test. This is relevant information.");
$data->MessageData->addChild("Destinations","6495005001");

$headers = array(
  "Content-Type: text/xml",
  "encoding='utf-8'",
  "Content-length: ".strlen($data->asXML()),
  "Connection: close"
);  

try
{
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://www.tnz.co.nz/api/xml/send");
    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();
}

?>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?php

$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "TextToSpeech";
$version = "1.04";
$message_id = "ID123456";

$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><root></root>");

$data->addChild("Sender",$sender);
$data->addChild("APIKey",$apikey);
$data->addChild("MessageType",$type);
$data->addChild("APIVersion",$version);
$data->addChild("MessageID",$message_id);

$data->addChild("MessageData");
$data->MessageData->addChild("Reference","Test1");
$data->MessageData->addChild("SendTime");
$data->MessageData->addChild("TimeZone","New Zealand");
$data->MessageData->addChild("SubAccount","SubAccount01");
$data->MessageData->addChild("Department","Department01");
$data->MessageData->addChild("ChargeCode","BillingGroup01");
$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.");

$keypad1 = $data->MessageData->addChild("Keypads");
$keypad1->addChild("Tone",1);
$keypad1->addChild("RouteNumber","64800123123");

$keypad2 = $data->MessageData->addChild("Keypads");
$keypad2->addChild("Tone",2);
$keypad2->addChild("Play","You pressed Keypad 2");
$keypad2->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","Female2");
$data->MessageData->addChild("Options","");

$destination1 = $data->MessageData->addChild("Destinations");
$destination1->addChild("Recipient","6421000001");
$destination1->addChild("Custom1","");
$destination1->addChild("Custom2","");

$destination2 = $data->MessageData->addChild("Destinations","6495005002");
$destination3 = $data->MessageData->addChild("Destinations","6421000003");

$headers = array(
  "Content-Type: text/xml",
  "encoding='utf-8'",
  "Content-length: ".strlen($data->asXML()),
  "Connection: close"
);  

try
{
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://www.tnz.co.nz/api/xml/send");
    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();
}

?>                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>ID123456</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="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://www.tnz.co.nz/api/xml/send";

            //
            // 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("root");
            xmlDoc.AppendChild(rootNode);

            rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com"));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd"));
            rootNode.AppendChild(addChildNode(xmlDoc, "MessageType", "TextToSpeech"));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIVersion", "1.04"));

            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."));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "Destinations", "6495005001"));

            //
            // 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'";

            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);
        }
    }
}
                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="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://www.tnz.co.nz/api/xml/send";

            //
            // 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("root");
            xmlDoc.AppendChild(rootNode);

            rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com"));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd"));
            rootNode.AppendChild(addChildNode(xmlDoc, "MessageType", "TextToSpeech"));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIVersion", "1.04"));
            rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", "ID123456"));

            XmlNode workingNode = xmlDoc.CreateElement("Sender");

            //
            // MessageData
            //
            XmlNode messageDataNode = xmlDoc.CreateElement("MessageData");

            messageDataNode.AppendChild(addChildNode(xmlDoc, "Reference", "Test1"));
            messageDataNode.AppendChild(addChildNode(xmlDoc, "SendTime", DateTime.Now.ToString("yyyy-MM-dd hh: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, "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");
            workingNode.AppendChild(addChildNode(xmlDoc, "Tone", "1"));
            workingNode.AppendChild(addChildNode(xmlDoc, "RouteNumber", "64800123123"));

            messageDataNode.AppendChild(workingNode);

            //
            // Add Keypad 2 - RouteNumber + Play
            //
            workingNode = xmlDoc.CreateElement("Keypads");
            workingNode.AppendChild(addChildNode(xmlDoc, "Tone", "2"));
            workingNode.AppendChild(addChildNode(xmlDoc, "Play", "You pressed Keypad 2"));
            workingNode.AppendChild(addChildNode(xmlDoc, "RouteNumber", "6498008000"));

            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", "Female2"));
            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, "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'";

            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);
        }
    }
}
                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>ID123456</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

import requests
import xml.etree.ElementTree as ET

url = "https://www.tnz.co.nz/api/xml/send/"

headers = {
    "Content-Type": "text/xml",
    "encoding": "utf-8"
}

root = ET.Element('root')

ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "MessageType").text = "TextToSpeech"
ET.SubElement(root, "APIVersion").text = "1.04"

message_data = ET.SubElement(root,"MessageData")
ET.SubElement(message_data, "MessageToPeople").text = "Hello, this is a call from test. This is relevant information."
ET.SubElement(message_data, "Destinations").text = "6495005001"

r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)

print(r)
print(r.text)                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                
API URL:   https://www.tnz.co.nz/api/xml/send/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

import requests
import xml.etree.ElementTree as ET

url = "https://www.tnz.co.nz/api/xml/send/"

headers = {
    "Content-Type": "text/xml",
    "encoding": "utf-8"
}

root = ET.Element('root')

ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "MessageType").text = "TextToSpeech"
ET.SubElement(root, "APIVersion").text = "1.04"
ET.SubElement(root, "MessageID").text = "ID123456"

message_data = ET.SubElement(root,"MessageData")
ET.SubElement(message_data, "Reference").text = "Test1"
ET.SubElement(message_data, "SendTime").text = ""
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, "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")
ET.SubElement(keypads,"Tone").text = "1"
ET.SubElement(keypads,"RouteNumber").text = "64800123123"

keypads = ET.SubElement(message_data,"Keypads")
ET.SubElement(keypads,"Tone").text = "2"
ET.SubElement(keypads,"Play").text = "You pressed Keypad 2"
ET.SubElement(keypads,"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 = "Female2"
ET.SubElement(message_data, "Options").text = ""

destinations = ET.SubElement(message_data,"Destinations")
ET.SubElement(destinations,"Recipient").text = "6421000001"
ET.SubElement(destinations,"Custom1").text = ""
ET.SubElement(destinations,"Custom2").text = ""

ET.SubElement(message_data, "Destinations").text = "6495005002"
ET.SubElement(message_data, "Destinations").text = "6421000003"

r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)

print(r)
print(r.text)                                                

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>ID123456</MessageID>
</root>                                                

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                                

Required MessageData parameters

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 6495005001
6495005002
6495005003
Telephone number(s) to receive the message (for detailed formatting, see the Destinations parameter below)

Optional MessageData parameters

Parameter Example Value Description
Reference Test1 Tracking ID or message description
SendTime 08/12/2019 13:04 Delay sending until the specified date/time (dd/mm/yyyy HH:mm in your local timezone, specified by your Sender setting or overridden using the TimeZone command)
TimeZone New Zealand Timezone specified using Windows timezone value (default set using Web Dashboard can be overridden here)
See Microsoft Timezones (use the Country value)
SubAccount SubAccount01 Used for reporting, billing and Web Dashboard segmentation
Department Department01 Used for reporting, billing and Web Dashboard segmentation
ChargeCode BillingGroup01 Cost allocation for billing
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)
> Play You pressed Keypad 1 Message played when the keypad is pressed
> RouteNumber +64800123123 Telephone number for call routing in dialling format
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 Female2 Text-to-Speech voice to use (Male1, Female1, Female2, Female3, Female4)
Options Customisable field
Destinations > Recipient 6495005000 Recipient of the call in E.164 internationalised format (for localized or friendly formatting, contact your account manager)
> Attention Recipient One Recipient's friendly name
> Company Example Corp Recipient's company
> Custom1 Recipient One Customisable field
> Custom2 Recipient One Customisable field

Sending messages in test mode

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

API - Edit Messages - Edit a submitted message

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.


Retry Sending - Resubmit a failed message

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://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

{
	"Sender":"application@domain.com",
	"APIKey":"ta8wr7ymd",
	"APIVersion":"1.04",
	"Type":"Resubmit",
	"MessageID":"ID123456"
}                                            

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Transmit",
        "JobNum": "ABCD1234",
        "Action": "Resubmit"
    }
}                                            

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                            
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

{
	"Sender":"application@domain.com",
	"APIKey":"ta8wr7ymd",
	"APIVersion":"1.04",
	"Type":"Resubmit",
	"MessageID":"ID123456"
}                                            

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Transmit",
        "JobNum": "ABCD1234",
        "Action": "Resubmit"
    }
}                                            

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                            
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/json/set \
  --header "Content-Type: application/json; encoding='utf-8'" \
  --data '{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "Resubmit",
    "APIVersion": "1.04",
    "MessageID": "ID123456"
  }'                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Transmit",
        "JobNum": "ABCD1234",
        "Action": "Resubmit"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/json/set \
  --header "Content-Type: application/json; encoding='utf-8'" \
  --data '{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "Resubmit",
    "APIVersion": "1.04",
    "MessageID": "ID123456"
  }'                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Transmit",
        "JobNum": "ABCD1234",
        "Action": "Resubmit"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

<?php

$data = array(
    "Sender"      => "application@domain.com",  // required
    "APIKey"      => "ta8wr7ymd",               // required
    "Type"        => "resubmit",                // required
    "APIVersion"  => "1.04",                    // 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://www.tnz.co.nz/api/json/set");
    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();
}

?>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Transmit",
        "JobNum": "ABCD1234",
        "Action": "Resubmit"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

<?php

$data = array(
    "Sender"      => "application@domain.com",  // required
    "APIKey"      => "ta8wr7ymd",               // required
    "Type"        => "resubmit",                // required
    "APIVersion"  => "1.04",                    // 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://www.tnz.co.nz/api/json/set");
    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();
}

?>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Transmit",
        "JobNum": "ABCD1234",
        "Action": "Resubmit"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Net;
using System.IO;

namespace SetResubmitJSON
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }
        
        private void ResubmitByJSONAPI()
        {
            string apiURL = "https://www.tnz.co.nz/api/json/set";
            
            //
            // Build JSON Data
            //

            string strJSONData = @"{
                ""Sender"": ""application@domain.com"",
                ""APIKey"": ""ta8wr7ymd"",
                ""APIVersion"": ""1.04"",
                ""Type"": ""Resubmit"",
                ""MessageID"": ""ID123456""
            }";
                        
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "application/json; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }
            
            MessageBox.Show(strResponse);
        }
    }
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Transmit",
        "JobNum": "ABCD1234",
        "Action": "Resubmit"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Net;
using System.IO;

namespace SetResubmitJSON
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }
        
        private void ResubmitByJSONAPI()
        {
            string apiURL = "https://www.tnz.co.nz/api/json/set";
            
            //
            // Build JSON Data
            //

            string strJSONData = @"{
                ""Sender"": ""application@domain.com"",
                ""APIKey"": ""ta8wr7ymd"",
                ""APIVersion"": ""1.04"",
                ""Type"": ""Resubmit"",
                ""MessageID"": ""ID123456""
            }";
                        
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "application/json; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }
            
            MessageBox.Show(strResponse);
        }
    }
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Transmit",
        "JobNum": "ABCD1234",
        "Action": "Resubmit"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

import requests
import json

url = "https://www.tnz.co.nz/api/json/set/"

headers = {
    "Content-Type": "application/json",
    "encoding": "utf-8"
}

data = {
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "Resubmit",
    "APIVersion": "1.04",
    "MessageID" : "ID123456"
}

r = requests.post(url, data=json.dumps(data), headers=headers)

print(r)
print(r.text)                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Transmit",
        "JobNum": "ABCD1234",
        "Action": "Resubmit"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

import requests
import json

url = "https://www.tnz.co.nz/api/json/set/"

headers = {
    "Content-Type": "application/json",
    "encoding": "utf-8"
}

data = {
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "Resubmit",
    "APIVersion": "1.04",
    "MessageID" : "ID123456"
}

r = requests.post(url, data=json.dumps(data), headers=headers)

print(r)
print(r.text)                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Transmit",
        "JobNum": "ABCD1234",
        "Action": "Resubmit"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <Sender>application@domain.com</Sender>
  <APIKey>ta8wr7ymd</APIKey>
  <Type>Resubmit</Type>
  <APIVersion>1.04</APIVersion>
  <MessageID>ID123456</MessageID>
</root>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Transmit</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Resubmit</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <Sender>application@domain.com</Sender>
  <APIKey>ta8wr7ymd</APIKey>
  <Type>Resubmit</Type>
  <APIVersion>1.04</APIVersion>
  <MessageID>ID123456</MessageID>
</root>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Transmit</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Resubmit</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/xml/set \
  --header "Content-Type: text/xml; encoding='utf-8'" \
  --data '
  <?xml version="1.0" encoding="UTF-8"?>
  <root>
    <Sender>application@domain.com</Sender>
    <APIKey>ta8wr7ymd</APIKey>
    <Type>Resubmit</Type>
    <APIVersion>1.04</APIVersion>
    <MessageID>ID123456</MessageID>
  </root>
  '                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Transmit</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Resubmit</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/xml/set \
  --header "Content-Type: text/xml; encoding='utf-8'" \
  --data '
  <?xml version="1.0" encoding="UTF-8"?>
  <root>
    <Sender>application@domain.com</Sender>
    <APIKey>ta8wr7ymd</APIKey>
    <Type>Resubmit</Type>
    <APIVersion>1.04</APIVersion>
    <MessageID>ID123456</MessageID>
  </root>
  '                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Transmit</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Resubmit</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="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("Type","Resubmit");                 // required
$data->addChild("APIVersion","1.04");               // required
$data->addChild("MessageID","ID123456");            // required

$headers = array(
  "Content-Type: text/xml",
  "encoding='utf-8'",
  "Content-length: ".strlen($data->asXML()),
  "Connection: close"
);  

try
{
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://www.tnz.co.nz/api/xml/set");
    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();
}

?>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Transmit</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Resubmit</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="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("Type","Resubmit");                 // required
$data->addChild("APIVersion","1.04");               // required
$data->addChild("MessageID","ID123456");            // required

$headers = array(
  "Content-Type: text/xml",
  "encoding='utf-8'",
  "Content-length: ".strlen($data->asXML()),
  "Connection: close"
);  

try
{
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://www.tnz.co.nz/api/xml/set");
    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();
}

?>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Transmit</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Resubmit</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Xml;
using System.Windows.Forms;

using System.IO;
using System.Net;

namespace TestXML
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
        {
            XmlNode workingNode = xmlDoc.CreateElement(name);
            workingNode.InnerText = val;

            return workingNode;
        }
        
        private void btnSendSMS_Click(object sender, EventArgs e)
        {
            string apiURL = "https://www.tnz.co.nz/api/xml/set";

            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("root");
            xmlDoc.AppendChild(rootNode);

            rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com")); // required
            rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd"));              // required
            rootNode.AppendChild(addChildNode(xmlDoc, "Type", "Resubmit"));                 // required
            rootNode.AppendChild(addChildNode(xmlDoc, "APIVersion", "1.04"));               // required
            rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", "ID123456"));            // required

            //
            // Send Raw XML Request
            //
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "text/xml; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }

            MessageBox.Show(strResponse);
        }
    }
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Transmit</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Resubmit</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Xml;
using System.Windows.Forms;

using System.IO;
using System.Net;

namespace TestXML
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
        {
            XmlNode workingNode = xmlDoc.CreateElement(name);
            workingNode.InnerText = val;

            return workingNode;
        }
        
        private void btnSendSMS_Click(object sender, EventArgs e)
        {
            string apiURL = "https://www.tnz.co.nz/api/xml/set";

            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("root");
            xmlDoc.AppendChild(rootNode);

            rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com")); // required
            rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd"));              // required
            rootNode.AppendChild(addChildNode(xmlDoc, "Type", "Resubmit"));                 // required
            rootNode.AppendChild(addChildNode(xmlDoc, "APIVersion", "1.04"));               // required
            rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", "ID123456"));            // required

            //
            // Send Raw XML Request
            //
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "text/xml; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }

            MessageBox.Show(strResponse);
        }
    }
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Transmit</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Resubmit</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

import requests
import xml.etree.ElementTree as ET

url = "https://www.tnz.co.nz/api/xml/set/"

headers = {
    "Content-Type": "text/xml",
    "encoding": "utf-8"
}

root = ET.Element('root')

ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "Type").text = "Resubmit"
ET.SubElement(root, "APIVersion").text = "1.04"
ET.SubElement(root, "MessageID").text = "ID123456"

r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)

print(r)
print(r.text)                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Transmit</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Resubmit</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

import requests
import xml.etree.ElementTree as ET

url = "https://www.tnz.co.nz/api/xml/set/"

headers = {
    "Content-Type": "text/xml",
    "encoding": "utf-8"
}

root = ET.Element('root')

ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "Type").text = "Resubmit"
ET.SubElement(root, "APIVersion").text = "1.04"
ET.SubElement(root, "MessageID").text = "ID123456"

r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)

print(r)
print(r.text)                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Transmit</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Resubmit</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
Required parameters
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
APIVersion 1.04 Version of the API used
Type Resubmit Action to be performed
MessageID ID123456 MessageID the Action should apply to
SUCCESS response parameters
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
FAILED response parameters
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)



Reschedule Sending - Adjust the Delayed Sending Date/Time

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://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

{
    "Sender":"application@domain.com",
    "APIKey":"ta8wr7ymd",
    "APIVersion":"1.04",
    "Type":"Reschedule",
    "MessageID":"ID123456",
    "SendTime":"2020-05-12 12:00:00"
}                                            

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Transmit",
        "JobNum": "ABCD1234",
        "Action": "Reschedule"
    }
}                                            

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                            
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

{
    "Sender":"application@domain.com",
    "APIKey":"ta8wr7ymd",
    "APIVersion":"1.04",
    "Type":"Reschedule",
    "MessageID":"ID123456",
    "SendTime":"2020-05-12 12:00:00"
}                                            

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Transmit",
        "JobNum": "ABCD1234",
        "Action": "Reschedule"
    }
}                                            

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                            
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/json/set \
  --header "Content-Type: application/json; encoding='utf-8'" \
  --data '{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "Reschedule",
    "APIVersion": "1.04",
    "MessageID": "ID123456",
    "SendTime":"2020-05-12 12:00:00"
  }'                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Transmit",
        "JobNum": "ABCD1234",
        "Action": "Reschedule"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/json/set \
  --header "Content-Type: application/json; encoding='utf-8'" \
  --data '{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "Reschedule",
    "APIVersion": "1.04",
    "MessageID": "ID123456",
    "SendTime":"2020-05-12 12:00:00"
  }'                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Transmit",
        "JobNum": "ABCD1234",
        "Action": "Reschedule"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

<?php

$data = array(
    "Sender"      => "application@domain.com",  // required
    "APIKey"      => "ta8wr7ymd",               // required
    "Type"        => "reschedule",              // required
    "APIVersion"  => "1.04",                    // required
    "MessageID"   => "ID123456",                // required
    "SendTime"    => "2020-05-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://www.tnz.co.nz/api/json/set");
    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();
}

?>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Transmit",
        "JobNum": "ABCD1234",
        "Action": "Reschedule"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

<?php

$data = array(
    "Sender"      => "application@domain.com",  // required
    "APIKey"      => "ta8wr7ymd",               // required
    "Type"        => "reschedule",              // required
    "APIVersion"  => "1.04",                    // required
    "MessageID"   => "ID123456",                // required
    "SendTime"    => "2020-05-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://www.tnz.co.nz/api/json/set");
    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();
}

?>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Transmit",
        "JobNum": "ABCD1234",
        "Action": "Reschedule"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Net;
using System.IO;

namespace SetRescheduleJSON
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }
        
        private void RescheduleByJSONAPI()
        {
            string apiURL = "https://www.tnz.co.nz/api/json/set";
            
            //
            // Build JSON Data
            //

            string strJSONData = @"{
                ""Sender"": ""application@domain.com"",
                ""APIKey"": ""ta8wr7ymd"",
                ""APIVersion"": ""1.04"",
                ""Type"": ""Reschedule"",
                ""MessageID"": ""ID123456"",
                ""SendTime"": ""2020-05-12 12:00:00""
            }";
                        
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "application/json; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }
            
            MessageBox.Show(strResponse);
        }
    }
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Transmit",
        "JobNum": "ABCD1234",
        "Action": "Reschedule"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Net;
using System.IO;

namespace SetRescheduleJSON
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }
        
        private void RescheduleByJSONAPI()
        {
            string apiURL = "https://www.tnz.co.nz/api/json/set";
            
            //
            // Build JSON Data
            //

            string strJSONData = @"{
                ""Sender"": ""application@domain.com"",
                ""APIKey"": ""ta8wr7ymd"",
                ""APIVersion"": ""1.04"",
                ""Type"": ""Reschedule"",
                ""MessageID"": ""ID123456"",
                ""SendTime"": ""2020-05-12 12:00:00""
            }";
                        
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "application/json; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }
            
            MessageBox.Show(strResponse);
        }
    }
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Transmit",
        "JobNum": "ABCD1234",
        "Action": "Reschedule"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

import requests
import json

url = "https://www.tnz.co.nz/api/json/set/"

headers = {
    "Content-Type": "application/json",
    "encoding": "utf-8"
}

data = {
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "Reschedule",
    "APIVersion": "1.04",
    "MessageID" : "ID123456",
    "SendTime": "2020-05-12 12:00:00"
}

r = requests.post(url, data=json.dumps(data), headers=headers)

print(r)
print(r.text)                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Transmit",
        "JobNum": "ABCD1234",
        "Action": "Reschedule"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

import requests
import json

url = "https://www.tnz.co.nz/api/json/set/"

headers = {
    "Content-Type": "application/json",
    "encoding": "utf-8"
}

data = {
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "Reschedule",
    "APIVersion": "1.04",
    "MessageID" : "ID123456",
    "SendTime": "2020-05-12 12:00:00"
}

r = requests.post(url, data=json.dumps(data), headers=headers)

print(r)
print(r.text)                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Transmit",
        "JobNum": "ABCD1234",
        "Action": "Reschedule"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <Sender>application@domain.com</Sender>
  <APIKey>ta8wr7ymd</APIKey>
  <Type>Reschedule</Type>
  <APIVersion>1.04</APIVersion>
  <MessageID>ID123456</MessageID>
  <SendTime>2020-05-12 12:00:00</SendTime>
</root>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Transmit</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Reschedule</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <Sender>application@domain.com</Sender>
  <APIKey>ta8wr7ymd</APIKey>
  <Type>Reschedule</Type>
  <APIVersion>1.04</APIVersion>
  <MessageID>ID123456</MessageID>
  <SendTime>2020-05-12 12:00:00</SendTime>
</root>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Transmit</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Reschedule</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/xml/set \
  --header "Content-Type: text/xml; encoding='utf-8'" \
  --data '
  <?xml version="1.0" encoding="UTF-8"?>
  <root>
    <Sender>application@domain.com</Sender>
    <APIKey>ta8wr7ymd</APIKey>
    <Type>Reschedule</Type>
    <APIVersion>1.04</APIVersion>
    <MessageID>ID123456</MessageID>
    <SendTime>2020-05-12 12:00:00</SendTime>
  </root>
  '                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Transmit</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Reschedule</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/xml/set \
  --header "Content-Type: text/xml; encoding='utf-8'" \
  --data '
  <?xml version="1.0" encoding="UTF-8"?>
  <root>
    <Sender>application@domain.com</Sender>
    <APIKey>ta8wr7ymd</APIKey>
    <Type>Reschedule</Type>
    <APIVersion>1.04</APIVersion>
    <MessageID>ID123456</MessageID>
    <SendTime>2020-05-12 12:00:00</SendTime>
  </root>
  '                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Transmit</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Reschedule</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="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("Type","Reschedule");               // required
$data->addChild("APIVersion","1.04");               // required
$data->addChild("MessageID","ID123456");            // required
$data->addChild("SendTime","2020-05-12 12:00:00");  // required

$headers = array(
  "Content-Type: text/xml",
  "encoding='utf-8'",
  "Content-length: ".strlen($data->asXML()),
  "Connection: close"
);  

try
{
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://www.tnz.co.nz/api/xml/set");
    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();
}

?>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Transmit</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Reschedule</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="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("Type","Reschedule");               // required
$data->addChild("APIVersion","1.04");               // required
$data->addChild("MessageID","ID123456");            // required
$data->addChild("SendTime","2020-05-12 12:00:00");  // required

$headers = array(
  "Content-Type: text/xml",
  "encoding='utf-8'",
  "Content-length: ".strlen($data->asXML()),
  "Connection: close"
);  

try
{
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://www.tnz.co.nz/api/xml/set");
    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();
}

?>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Transmit</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Reschedule</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Xml;
using System.Windows.Forms;

using System.IO;
using System.Net;

namespace TestXML
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
        {
            XmlNode workingNode = xmlDoc.CreateElement(name);
            workingNode.InnerText = val;

            return workingNode;
        }
        
        private void btnSendSMS_Click(object sender, EventArgs e)
        {
            string apiURL = "https://www.tnz.co.nz/api/xml/set";

            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("root");
            xmlDoc.AppendChild(rootNode);

            rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com")); // required
            rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd"));              // required
            rootNode.AppendChild(addChildNode(xmlDoc, "Type", "Reschedule"));               // required
            rootNode.AppendChild(addChildNode(xmlDoc, "APIVersion", "1.04"));               // required
            rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", "ID123456"));            // required
            rootNode.AppendChild(addChildNode(xmlDoc, "SendTime", "2020-05-12 12:00:00"));  // required

            //
            // Send Raw XML Request
            //
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "text/xml; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }

            MessageBox.Show(strResponse);
        }
    }
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Transmit</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Reschedule</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Xml;
using System.Windows.Forms;

using System.IO;
using System.Net;

namespace TestXML
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
        {
            XmlNode workingNode = xmlDoc.CreateElement(name);
            workingNode.InnerText = val;

            return workingNode;
        }
        
        private void btnSendSMS_Click(object sender, EventArgs e)
        {
            string apiURL = "https://www.tnz.co.nz/api/xml/set";

            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("root");
            xmlDoc.AppendChild(rootNode);

            rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com")); // required
            rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd"));              // required
            rootNode.AppendChild(addChildNode(xmlDoc, "Type", "Reschedule"));               // required
            rootNode.AppendChild(addChildNode(xmlDoc, "APIVersion", "1.04"));               // required
            rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", "ID123456"));            // required
            rootNode.AppendChild(addChildNode(xmlDoc, "SendTime", "2020-05-12 12:00:00"));  // required

            //
            // Send Raw XML Request
            //
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "text/xml; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }

            MessageBox.Show(strResponse);
        }
    }
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Transmit</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Reschedule</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

import requests
import xml.etree.ElementTree as ET

url = "https://www.tnz.co.nz/api/xml/set/"

headers = {
    "Content-Type": "text/xml",
    "encoding": "utf-8"
}

root = ET.Element('root')

ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "Type").text = "Reschedule"
ET.SubElement(root, "APIVersion").text = "1.04"
ET.SubElement(root, "MessageID").text = "ID123456"
ET.SubElement(root, "SendTime").text = "2020-05-12 12:00:00"

r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)

print(r)
print(r.text)                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Transmit</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Reschedule</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

import requests
import xml.etree.ElementTree as ET

url = "https://www.tnz.co.nz/api/xml/set/"

headers = {
    "Content-Type": "text/xml",
    "encoding": "utf-8"
}

root = ET.Element('root')

ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "Type").text = "Reschedule"
ET.SubElement(root, "APIVersion").text = "1.04"
ET.SubElement(root, "MessageID").text = "ID123456"
ET.SubElement(root, "SendTime").text = "2020-05-12 12:00:00"

r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)

print(r)
print(r.text)                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Transmit</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Reschedule</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
Required parameters
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
APIVersion 1.04 Version of the API used
Type Reschedule Action to be performed
MessageID ID123456 MessageID the Action should apply to
SendTime 2020-05-12 14:05:00 Reschedule sending for the specified date/time (dd/mm/yyyy HH:mm in your Account/Sender's default timezone setting)
SUCCESS response parameters
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
FAILED response parameters
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)



Abort Sending - Cancel/Delete a Message from the Queue

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://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

{
	"Sender":"application@domain.com",
	"APIKey":"ta8wr7ymd",
	"APIVersion":"1.04",
	"Type":"Abort",
	"MessageID":"ID123456"
}                                            

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Pending",
        "JobNum": "ABCD1234",
        "Action": "Abort"
    }
}                                            

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                            
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

{
	"Sender":"application@domain.com",
	"APIKey":"ta8wr7ymd",
	"APIVersion":"1.04",
	"Type":"Abort",
	"MessageID":"ID123456"
}                                            

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Pending",
        "JobNum": "ABCD1234",
        "Action": "Abort"
    }
}                                            

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                            
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/json/set \
  --header "Content-Type: application/json; encoding='utf-8'" \
  --data '{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "Abort",
    "APIVersion": "1.04",
    "MessageID": "ID123456"
  }'                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Pending",
        "JobNum": "ABCD1234",
        "Action": "Abort"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/json/set \
  --header "Content-Type: application/json; encoding='utf-8'" \
  --data '{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "Abort",
    "APIVersion": "1.04",
    "MessageID": "ID123456"
  }'                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Pending",
        "JobNum": "ABCD1234",
        "Action": "Abort"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

<?php

$data = array(
    "Sender"      => "application@domain.com",  // required
    "APIKey"      => "ta8wr7ymd",               // required
    "Type"        => "abort",                   // required
    "APIVersion"  => "1.04",                    // 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://www.tnz.co.nz/api/json/set");
    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();
}

?>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Pending",
        "JobNum": "ABCD1234",
        "Action": "Abort"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

<?php

$data = array(
    "Sender"      => "application@domain.com",  // required
    "APIKey"      => "ta8wr7ymd",               // required
    "Type"        => "abort",                   // required
    "APIVersion"  => "1.04",                    // 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://www.tnz.co.nz/api/json/set");
    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();
}

?>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Pending",
        "JobNum": "ABCD1234",
        "Action": "Abort"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Net;
using System.IO;

namespace SetAbortJSON
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }
        
        private void AbortByJSONAPI()
        {
            string apiURL = "https://www.tnz.co.nz/api/json/set";
            
            //
            // Build JSON Data
            //

            string strJSONData = @"{
                ""Sender"": ""application@domain.com"",
                ""APIKey"": ""ta8wr7ymd"",
                ""APIVersion"": ""1.04"",
                ""Type"": ""Abort"",
                ""MessageID"": ""ID123456""
            }";
                        
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "application/json; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }
            
            MessageBox.Show(strResponse);
        }
    }
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Pending",
        "JobNum": "ABCD1234",
        "Action": "Abort"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Net;
using System.IO;

namespace SetAbortJSON
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }
        
        private void AbortByJSONAPI()
        {
            string apiURL = "https://www.tnz.co.nz/api/json/set";
            
            //
            // Build JSON Data
            //

            string strJSONData = @"{
                ""Sender"": ""application@domain.com"",
                ""APIKey"": ""ta8wr7ymd"",
                ""APIVersion"": ""1.04"",
                ""Type"": ""Abort"",
                ""MessageID"": ""ID123456""
            }";
                        
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "application/json; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }
            
            MessageBox.Show(strResponse);
        }
    }
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Pending",
        "JobNum": "ABCD1234",
        "Action": "Abort"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

import requests
import json

url = "https://www.tnz.co.nz/api/json/set/"

headers = {
    "Content-Type": "application/json",
    "encoding": "utf-8"
}

data = {
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "Abort",
    "APIVersion": "1.04",
    "MessageID" : "ID123456"
}

r = requests.post(url, data=json.dumps(data), headers=headers)

print(r)
print(r.text)                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Pending",
        "JobNum": "ABCD1234",
        "Action": "Abort"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

import requests
import json

url = "https://www.tnz.co.nz/api/json/set/"

headers = {
    "Content-Type": "application/json",
    "encoding": "utf-8"
}

data = {
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "Abort",
    "APIVersion": "1.04",
    "MessageID" : "ID123456"
}

r = requests.post(url, data=json.dumps(data), headers=headers)

print(r)
print(r.text)                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Pending",
        "JobNum": "ABCD1234",
        "Action": "Abort"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <Sender>application@domain.com</Sender>
  <APIKey>ta8wr7ymd</APIKey>
  <Type>Abort</Type>
  <APIVersion>1.04</APIVersion>
  <MessageID>ID123456</MessageID>
</root>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Pending</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Abort</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <Sender>application@domain.com</Sender>
  <APIKey>ta8wr7ymd</APIKey>
  <Type>Abort</Type>
  <APIVersion>1.04</APIVersion>
  <MessageID>ID123456</MessageID>
</root>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Pending</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Abort</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/xml/set \
  --header "Content-Type: text/xml; encoding='utf-8'" \
  --data '
  <?xml version="1.0" encoding="UTF-8"?>
  <root>
    <Sender>application@domain.com</Sender>
    <APIKey>ta8wr7ymd</APIKey>
    <Type>Abort</Type>
    <APIVersion>1.04</APIVersion>
    <MessageID>ID123456</MessageID>
  </root>
  '                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Pending</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Abort</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/xml/set \
  --header "Content-Type: text/xml; encoding='utf-8'" \
  --data '
  <?xml version="1.0" encoding="UTF-8"?>
  <root>
    <Sender>application@domain.com</Sender>
    <APIKey>ta8wr7ymd</APIKey>
    <Type>Abort</Type>
    <APIVersion>1.04</APIVersion>
    <MessageID>ID123456</MessageID>
  </root>
  '                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Pending</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Abort</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="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("Type","Abort");                    // required
$data->addChild("APIVersion","1.04");               // required
$data->addChild("MessageID","ID123456");            // required

$headers = array(
  "Content-Type: text/xml",
  "encoding='utf-8'",
  "Content-length: ".strlen($data->asXML()),
  "Connection: close"
);  

try
{
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://www.tnz.co.nz/api/xml/set");
    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();
}

?>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Pending</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Abort</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="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("Type","Abort");                    // required
$data->addChild("APIVersion","1.04");               // required
$data->addChild("MessageID","ID123456");            // required

$headers = array(
  "Content-Type: text/xml",
  "encoding='utf-8'",
  "Content-length: ".strlen($data->asXML()),
  "Connection: close"
);  

try
{
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://www.tnz.co.nz/api/xml/set");
    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();
}

?>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Pending</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Abort</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Xml;
using System.Windows.Forms;

using System.IO;
using System.Net;

namespace TestXML
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
        {
            XmlNode workingNode = xmlDoc.CreateElement(name);
            workingNode.InnerText = val;

            return workingNode;
        }
        
        private void btnSendSMS_Click(object sender, EventArgs e)
        {
            string apiURL = "https://www.tnz.co.nz/api/xml/set";

            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("root");
            xmlDoc.AppendChild(rootNode);

            rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com")); // required
            rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd"));              // required
            rootNode.AppendChild(addChildNode(xmlDoc, "Type", "Abort"));                    // required
            rootNode.AppendChild(addChildNode(xmlDoc, "APIVersion", "1.04"));               // required
            rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", "ID123456"));            // required

            //
            // Send Raw XML Request
            //
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "text/xml; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }

            MessageBox.Show(strResponse);
        }
    }
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Pending</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Abort</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Xml;
using System.Windows.Forms;

using System.IO;
using System.Net;

namespace TestXML
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
        {
            XmlNode workingNode = xmlDoc.CreateElement(name);
            workingNode.InnerText = val;

            return workingNode;
        }
        
        private void btnSendSMS_Click(object sender, EventArgs e)
        {
            string apiURL = "https://www.tnz.co.nz/api/xml/set";

            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("root");
            xmlDoc.AppendChild(rootNode);

            rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com")); // required
            rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd"));              // required
            rootNode.AppendChild(addChildNode(xmlDoc, "Type", "Abort"));                    // required
            rootNode.AppendChild(addChildNode(xmlDoc, "APIVersion", "1.04"));               // required
            rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", "ID123456"));            // required

            //
            // Send Raw XML Request
            //
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "text/xml; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }

            MessageBox.Show(strResponse);
        }
    }
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Pending</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Abort</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

import requests
import xml.etree.ElementTree as ET

url = "https://www.tnz.co.nz/api/xml/set/"

headers = {
    "Content-Type": "text/xml",
    "encoding": "utf-8"
}

root = ET.Element('root')

ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "Type").text = "Abort"
ET.SubElement(root, "APIVersion").text = "1.04"
ET.SubElement(root, "MessageID").text = "ID123456"

r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)

print(r)
print(r.text)                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Pending</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Abort</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

import requests
import xml.etree.ElementTree as ET

url = "https://www.tnz.co.nz/api/xml/set/"

headers = {
    "Content-Type": "text/xml",
    "encoding": "utf-8"
}

root = ET.Element('root')

ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "Type").text = "Abort"
ET.SubElement(root, "APIVersion").text = "1.04"
ET.SubElement(root, "MessageID").text = "ID123456"

r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)

print(r)
print(r.text)                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Pending</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Abort</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
Required parameters
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
APIVersion 1.04 Version of the API used
Type Abort Action to be performed
MessageID ID123456 MessageID the Action should apply to
SUCCESS response parameters
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
FAILED response parameters
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)



Adjust NumberOfOperators - Change the Voice/Text-to-Speech NumberOfOperators Value

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://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

{
    "Sender":"application@domain.com",
    "APIKey":"ta8wr7ymd",
    "APIVersion":"1.04",
    "Type":"Pacing",
    "MessageID":"ID123456",
    "NumberOfOperators": 1
}                                            

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Pending",
        "JobNum": "ABCD1234",
        "Action": "Pacing"
    }
}                                            

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                            
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

{
    "Sender":"application@domain.com",
    "APIKey":"ta8wr7ymd",
    "APIVersion":"1.04",
    "Type":"Pacing",
    "MessageID":"ID123456",
    "NumberOfOperators": 1
}                                            

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Pending",
        "JobNum": "ABCD1234",
        "Action": "Pacing"
    }
}                                            

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                            
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/json/set \
  --header "Content-Type: application/json; encoding='utf-8'" \
  --data '{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "Pacing",
    "APIVersion": "1.04",
    "MessageID": "ID123456",
    "NumberOfOperators": 1
  }'                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Pending",
        "JobNum": "ABCD1234",
        "Action": "Pacing"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/json/set \
  --header "Content-Type: application/json; encoding='utf-8'" \
  --data '{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "Pacing",
    "APIVersion": "1.04",
    "MessageID": "ID123456",
    "NumberOfOperators": 1
  }'                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Pending",
        "JobNum": "ABCD1234",
        "Action": "Pacing"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

<?php

$data = array(
    "Sender"      => "application@domain.com",  // required
    "APIKey"      => "ta8wr7ymd",               // required
    "Type"        => "Pacing",                  // required
    "APIVersion"  => "1.04",                    // required
    "MessageID"   => "ID123456",                // 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://www.tnz.co.nz/api/json/set");
    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();
}

?>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Pending",
        "JobNum": "ABCD1234",
        "Action": "Pacing"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

<?php

$data = array(
    "Sender"      => "application@domain.com",  // required
    "APIKey"      => "ta8wr7ymd",               // required
    "Type"        => "Pacing",                  // required
    "APIVersion"  => "1.04",                    // required
    "MessageID"   => "ID123456",                // 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://www.tnz.co.nz/api/json/set");
    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();
}

?>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Pending",
        "JobNum": "ABCD1234",
        "Action": "Pacing"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Net;
using System.IO;

namespace SetNumberOfOperatorsJSON
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }
        
        private void NumberOfOperatorsByJSONAPI()
        {
            string apiURL = "https://www.tnz.co.nz/api/json/set";
            
            //
            // Build JSON Data
            //

            string strJSONData = @"{
                ""Sender"": ""application@domain.com"",
                ""APIKey"": ""ta8wr7ymd"",
                ""APIVersion"": ""1.04"",
                ""Type"": ""Pacing"",
                ""MessageID"": ""ID123456"",
                ""NumberOfOperators"": ""1""
            }";
                        
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "application/json; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }
            
            MessageBox.Show(strResponse);
        }
    }
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Pending",
        "JobNum": "ABCD1234",
        "Action": "Pacing"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Net;
using System.IO;

namespace SetNumberOfOperatorsJSON
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }
        
        private void NumberOfOperatorsByJSONAPI()
        {
            string apiURL = "https://www.tnz.co.nz/api/json/set";
            
            //
            // Build JSON Data
            //

            string strJSONData = @"{
                ""Sender"": ""application@domain.com"",
                ""APIKey"": ""ta8wr7ymd"",
                ""APIVersion"": ""1.04"",
                ""Type"": ""Pacing"",
                ""MessageID"": ""ID123456"",
                ""NumberOfOperators"": ""1""
            }";
                        
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "application/json; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }
            
            MessageBox.Show(strResponse);
        }
    }
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Pending",
        "JobNum": "ABCD1234",
        "Action": "Pacing"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

import requests
import json

url = "https://www.tnz.co.nz/api/json/set/"

headers = {
    "Content-Type": "application/json",
    "encoding": "utf-8"
}

data = {
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "Pacing",
    "APIVersion": "1.04",
    "MessageID" : "ID123456",
    "NumberOfOperators" : 1
}

r = requests.post(url, data=json.dumps(data), headers=headers)

print(r)
print(r.text)                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Pending",
        "JobNum": "ABCD1234",
        "Action": "Pacing"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/set/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

import requests
import json

url = "https://www.tnz.co.nz/api/json/set/"

headers = {
    "Content-Type": "application/json",
    "encoding": "utf-8"
}

data = {
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "Pacing",
    "APIVersion": "1.04",
    "MessageID" : "ID123456",
    "NumberOfOperators" : 1
}

r = requests.post(url, data=json.dumps(data), headers=headers)

print(r)
print(r.text)                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "MessageID": "ID123456",
        "Status": "Pending",
        "JobNum": "ABCD1234",
        "Action": "Pacing"
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "ID123456",
    "Message": "Message not found"
}                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <Sender>application@domain.com</Sender>
  <APIKey>ta8wr7ymd</APIKey>
  <Type>Pacing</Type>
  <APIVersion>1.04</APIVersion>
  <MessageID>ID123456</MessageID>
  <NumberOfOperators>1</NumberOfOperators>
</root>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Pending</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Pacing</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <Sender>application@domain.com</Sender>
  <APIKey>ta8wr7ymd</APIKey>
  <Type>Pacing</Type>
  <APIVersion>1.04</APIVersion>
  <MessageID>ID123456</MessageID>
  <NumberOfOperators>1</NumberOfOperators>
</root>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Pending</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Pacing</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/xml/set \
  --header "Content-Type: text/xml; encoding='utf-8'" \
  --data '
  <?xml version="1.0" encoding="UTF-8"?>
  <root>
    <Sender>application@domain.com</Sender>
    <APIKey>ta8wr7ymd</APIKey>
    <Type>Pacing</Type>
    <APIVersion>1.04</APIVersion>
    <MessageID>ID123456</MessageID>
    <NumberOfOperators>1</NumberOfOperators>
  </root>
  '                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Pending</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Pacing</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/xml/set \
  --header "Content-Type: text/xml; encoding='utf-8'" \
  --data '
  <?xml version="1.0" encoding="UTF-8"?>
  <root>
    <Sender>application@domain.com</Sender>
    <APIKey>ta8wr7ymd</APIKey>
    <Type>Pacing</Type>
    <APIVersion>1.04</APIVersion>
    <MessageID>ID123456</MessageID>
    <NumberOfOperators>1</NumberOfOperators>
  </root>
  '                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Pending</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Pacing</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="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("Type","Pacing");                   // required
$data->addChild("APIVersion","1.04");               // required
$data->addChild("MessageID","ID123456");            // required
$data->addChild("NumberOfOperators","1");                      // required

$headers = array(
  "Content-Type: text/xml",
  "encoding='utf-8'",
  "Content-length: ".strlen($data->asXML()),
  "Connection: close"
);  

try
{
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://www.tnz.co.nz/api/xml/set");
    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();
}

?>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Pending</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Pacing</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="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("Type","Pacing");                   // required
$data->addChild("APIVersion","1.04");               // required
$data->addChild("MessageID","ID123456");            // required
$data->addChild("NumberOfOperators","1");                      // required

$headers = array(
  "Content-Type: text/xml",
  "encoding='utf-8'",
  "Content-length: ".strlen($data->asXML()),
  "Connection: close"
);  

try
{
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://www.tnz.co.nz/api/xml/set");
    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();
}

?>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Pending</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Pacing</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Xml;
using System.Windows.Forms;

using System.IO;
using System.Net;

namespace TestXML
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
        {
            XmlNode workingNode = xmlDoc.CreateElement(name);
            workingNode.InnerText = val;

            return workingNode;
        }
        
        private void btnSendSMS_Click(object sender, EventArgs e)
        {
            string apiURL = "https://www.tnz.co.nz/api/xml/set";

            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("root");
            xmlDoc.AppendChild(rootNode);

            rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com")); // required
            rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd"));              // required
            rootNode.AppendChild(addChildNode(xmlDoc, "Type", "Pacing"));                   // required
            rootNode.AppendChild(addChildNode(xmlDoc, "APIVersion", "1.04"));               // required
            rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", "ID123456"));            // required
            rootNode.AppendChild(addChildNode(xmlDoc, "NumberOfOperators", "1"));                      // required

            //
            // Send Raw XML Request
            //
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "text/xml; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }

            MessageBox.Show(strResponse);
        }
    }
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Pending</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Pacing</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Xml;
using System.Windows.Forms;

using System.IO;
using System.Net;

namespace TestXML
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
        {
            XmlNode workingNode = xmlDoc.CreateElement(name);
            workingNode.InnerText = val;

            return workingNode;
        }
        
        private void btnSendSMS_Click(object sender, EventArgs e)
        {
            string apiURL = "https://www.tnz.co.nz/api/xml/set";

            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("root");
            xmlDoc.AppendChild(rootNode);

            rootNode.AppendChild(addChildNode(xmlDoc, "Sender", "application@domain.com")); // required
            rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", "ta8wr7ymd"));              // required
            rootNode.AppendChild(addChildNode(xmlDoc, "Type", "Pacing"));                   // required
            rootNode.AppendChild(addChildNode(xmlDoc, "APIVersion", "1.04"));               // required
            rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", "ID123456"));            // required
            rootNode.AppendChild(addChildNode(xmlDoc, "NumberOfOperators", "1"));                      // required

            //
            // Send Raw XML Request
            //
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "text/xml; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }

            MessageBox.Show(strResponse);
        }
    }
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Pending</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Pacing</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

import requests
import xml.etree.ElementTree as ET

url = "https://www.tnz.co.nz/api/xml/set/"

headers = {
    "Content-Type": "text/xml",
    "encoding": "utf-8"
}

root = ET.Element('root')

ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "Type").text = "Pacing"
ET.SubElement(root, "APIVersion").text = "1.04"
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)                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Pending</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Pacing</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/set/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

import requests
import xml.etree.ElementTree as ET

url = "https://www.tnz.co.nz/api/xml/set/"

headers = {
    "Content-Type": "text/xml",
    "encoding": "utf-8"
}

root = ET.Element('root')

ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "Type").text = "Pacing"
ET.SubElement(root, "APIVersion").text = "1.04"
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)                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
        <MessageID>ID123456</MessageID>
        <Status>Pending</Status>
        <JobNum>ABCD1234</JobNum>
        <Action>Pacing</Action>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>ID123456</MessageID>
    <Message>Message not found</Message>
</root>                                          
Required parameters
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
APIVersion 1.04 Version of the API used
Type Pacing Action to be performed
MessageID ID123456 MessageID the Action should apply to
NumberOfOperators 4 NumberOfOperators value to apply
SUCCESS response parameters
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
FAILED response parameters
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)

API - Status Reporting - Reporting and event tracking

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.



Web Dashboard - Tracking message statuses via the online dashboard

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.



SMTP Email - Receive message statuses via email

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.



Webhook - Message statuses delivered via a webhook

To receive Delivery Reports via Webhook, please advise the URL to submit to.
Webhooks are provided as an HTTP POST in either XML or JSON format (your preference).

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', 'TextToSpeech', or 'SMSReply')
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
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 This field will only contain data if 'Type=SMSReply'
Price 0.20 Your cost for this transaction, charged by us to you
Detail SMSParts:2 Additional billing detail: "SMSParts", "FaxPages", "VoiceMinutes", "Size", "Prompts"


GET Status Poll - Track message statuses using a GET poll

API users are able to poll for the status of a message via the GET Status API.

 
 
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "status",
    "APIVersion": "1.04",
    "MessageID": "ID123456",
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

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

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                          
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "status",
    "APIVersion": "1.04",
    "MessageID": "ID123456",
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

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

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                          
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/json/get \
  --header "Content-Type: application/json; encoding='utf-8'" \
  --data '{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "status",
    "APIVersion": "1.04",
    "MessageID": "ID123456",
  }'                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

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

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                          
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/json/get \
  --header "Content-Type: application/json; encoding='utf-8'" \
  --data '{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "status",
    "APIVersion": "1.04",
    "MessageID": "ID123456",
  }'                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

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

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                          
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

<?php

$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "status";
$version = "1.04";
$message_id = "ID123456";           // required

$data = array(
    "Sender" => $sender,
    "APIKey" => $apikey,
    "Type" => $type,
    "APIVersion" => $version,
    "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://www.tnz.co.nz/api/json/get");
    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();
}

?>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

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

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                          
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

<?php

$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "status";
$version = "1.04";
$message_id = "ID123456";           // required

$data = array(
    "Sender" => $sender,
    "APIKey" => $apikey,
    "Type" => $type,
    "APIVersion" => $version,
    "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://www.tnz.co.nz/api/json/get");
    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();
}

?>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

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

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                          
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Net;
using System.IO;

namespace GetStatusJSON
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }
        
        private void GetStatusByJSONAPI()
        {
            string apiURL = "https://www.tnz.co.nz/api/json/get";

            string strSender = "application@domain.com";
            string strAPIKey = "ta8wr7ymd";
            string strAPIVersion = "1.04";
            string strType = "Status";
            string strMessageID = "ID123456";             // required

            string strJSONData = "{" +
                "\"Sender\": \"" + strSender + "\"," +
                "\"APIKey\": \"" + strAPIKey + "\"," +
                "\"Type\":\"" + strType + "\"," +
                "\"APIVersion\":\"" + strAPIVersion + "\"," +
                "\"MessageID\":\"" + strMessageID + "\"," +
            "}";
                        
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "application/json; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }
            
            MessageBox.Show(strResponse);
        }
    }
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

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

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                          
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Net;
using System.IO;

namespace GetStatusJSON
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }
        
        private void GetStatusByJSONAPI()
        {
            string apiURL = "https://www.tnz.co.nz/api/json/get";

            string strSender = "application@domain.com";
            string strAPIKey = "ta8wr7ymd";
            string strAPIVersion = "1.04";
            string strType = "Status";
            string strMessageID = "ID123456";             // required

            string strJSONData = "{" +
                "\"Sender\": \"" + strSender + "\"," +
                "\"APIKey\": \"" + strAPIKey + "\"," +
                "\"Type\":\"" + strType + "\"," +
                "\"APIVersion\":\"" + strAPIVersion + "\"," +
                "\"MessageID\":\"" + strMessageID + "\"," +
            "}";
                        
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "application/json; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }
            
            MessageBox.Show(strResponse);
        }
    }
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

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

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                          
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

import requests
import json

url = "https://www.tnz.co.nz/api/json/get/"

headers = {
    "Content-Type": "application/json",
    "encoding": "utf-8"
}

data = {
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "Status",
    "APIVersion": "1.04",
    "MessageID" : "ID123456"
}

r = requests.post(url, data=json.dumps(data), headers=headers)

print(r)
print(r.text)                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

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

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                          
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

import requests
import json

url = "https://www.tnz.co.nz/api/json/get/"

headers = {
    "Content-Type": "application/json",
    "encoding": "utf-8"
}

data = {
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "Status",
    "APIVersion": "1.04",
    "MessageID" : "ID123456"
}

r = requests.post(url, data=json.dumps(data), headers=headers)

print(r)
print(r.text)                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

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

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <Sender>application@domain.com</Sender>
  <APIKey>ta8wr7ymd</APIKey>
  <Type>status</Type>
  <APIVersion>1.04</APIVersion>
  <MessageID>ID123456</MessageID>
</root>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?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>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <Sender>application@domain.com</Sender>
  <APIKey>ta8wr7ymd</APIKey>
  <Type>status</Type>
  <APIVersion>1.04</APIVersion>
  <MessageID>ID123456</MessageID>
</root>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?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>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/xml/get \
  --header "Content-Type: text/xml; encoding='utf-8'" \
  --data '
  <?xml version="1.0" encoding="UTF-8"?>
  <root>
    <Sender>application@domain.com</Sender>
    <APIKey>ta8wr7ymd</APIKey>
    <Type>status</Type>
    <APIVersion>1.04</APIVersion>
    <MessageID>ID123456</MessageID>
  </root>
  '                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?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>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/xml/get \
  --header "Content-Type: text/xml; encoding='utf-8'" \
  --data '
  <?xml version="1.0" encoding="UTF-8"?>
  <root>
    <Sender>application@domain.com</Sender>
    <APIKey>ta8wr7ymd</APIKey>
    <Type>status</Type>
    <APIVersion>1.04</APIVersion>
    <MessageID>ID123456</MessageID>
  </root>
  '                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?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>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?php

$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "status";
$version = "1.04";
$message_id = "ID123456";           // required

$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><root></root>");

$data->addChild("Sender",$sender);
$data->addChild("APIKey",$apikey);
$data->addChild("Type",$type);
$data->addChild("APIVersion",$version);
$data->addChild("MessageID",$message_id);

$headers = array(
  "Content-Type: text/xml",
  "encoding='utf-8'",
  "Content-length: ".strlen($data->asXML()),
  "Connection: close"
);  

try
{
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://www.tnz.co.nz/api/xml/get");
    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();
}

?>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?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>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?php

$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "status";
$version = "1.04";
$message_id = "ID123456";           // required

$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><root></root>");

$data->addChild("Sender",$sender);
$data->addChild("APIKey",$apikey);
$data->addChild("Type",$type);
$data->addChild("APIVersion",$version);
$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",
  "encoding='utf-8'",
  "Content-length: ".strlen($data->asXML()),
  "Connection: close"
);  

try
{
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://www.tnz.co.nz/api/xml/get");
    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();
}

?>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?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>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Xml;
using System.Windows.Forms;

using System.IO;
using System.Net;

namespace TestXML
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
        {
            XmlNode workingNode = xmlDoc.CreateElement(name);
            workingNode.InnerText = val;

            return workingNode;
        }
        
        private void btnSendSMS_Click(object sender, EventArgs e)
        {
            string apiURL = "https://www.tnz.co.nz/api/xml/get";

            string strSender = "application@domain.com";
            string strAPIKey = "ta8wr7ymd";
            string strType = "status";
            string strAPIVersion = "1.04";
            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("root");
            xmlDoc.AppendChild(rootNode);

            rootNode.AppendChild(addChildNode(xmlDoc, "Sender", strSender));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", strAPIKey));
            rootNode.AppendChild(addChildNode(xmlDoc, "Type", strType));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIVersion", strAPIVersion));
            rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", strMessageID));

            XmlNode workingNode = xmlDoc.CreateElement("Sender");

            //
            // Send Raw XML Request
            //
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "text/xml; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }

            MessageBox.Show(strResponse);
        }
    }
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?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>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Xml;
using System.Windows.Forms;

using System.IO;
using System.Net;

namespace TestXML
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
        {
            XmlNode workingNode = xmlDoc.CreateElement(name);
            workingNode.InnerText = val;

            return workingNode;
        }
        
        private void btnSendSMS_Click(object sender, EventArgs e)
        {
            string apiURL = "https://www.tnz.co.nz/api/xml/get";

            string strSender = "application@domain.com";
            string strAPIKey = "ta8wr7ymd";
            string strType = "status";
            string strAPIVersion = "1.04";
            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("root");
            xmlDoc.AppendChild(rootNode);

            rootNode.AppendChild(addChildNode(xmlDoc, "Sender", strSender));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", strAPIKey));
            rootNode.AppendChild(addChildNode(xmlDoc, "Type", strType));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIVersion", strAPIVersion));
            rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", strMessageID));

            XmlNode workingNode = xmlDoc.CreateElement("Sender");

            //
            // Send Raw XML Request
            //
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "text/xml; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }

            MessageBox.Show(strResponse);
        }
    }
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?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>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

import requests
import xml.etree.ElementTree as ET

url = "https://www.tnz.co.nz/api/xml/get/"

headers = {
    "Content-Type": "text/xml",
    "encoding": "utf-8"
}

root = ET.Element('root')

ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "Type").text = "Status"
ET.SubElement(root, "APIVersion").text = "1.04"
ET.SubElement(root, "MessageID").text = "ID123456"

r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)

print(r)
print(r.text)                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?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>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

import requests
import xml.etree.ElementTree as ET

url = "https://www.tnz.co.nz/api/xml/get/"

headers = {
    "Content-Type": "text/xml",
    "encoding": "utf-8"
}

root = ET.Element('root')

ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "Type").text = "Status"
ET.SubElement(root, "APIVersion").text = "1.04"
ET.SubElement(root, "MessageID").text = "ID123456"

r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)

print(r)
print(r.text)                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?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>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                          
Required parameters
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
APIVersion 1.04 Version of the API used
Type Status Type of API request
MessageID ID123456 Your provided Message ID or TNZ Group generated Message ID
SUCCESS response parameters
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
FAILED response parameters
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)

API - Receive Messages - Track messages received

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.



Web Dashboard - Tracking messages received via the online dashboard

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.



SMTP Email - Track messages received via email

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.



Webhook - Messages received data delivered via a webhook

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 provided as an HTTP POST in either XML or JSON format (your preference).

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', or 'SMSReply')
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
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. This field will only contain data if '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)


GET Inbound SMS Poll - View all Inbound SMS using a GET poll

API users are able to poll for all received SMS messages in a given time-frame.

 
 
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "InboundSMS",
    "APIVersion": "1.04",
    "TimePeriod": "1440",
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "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."
            }
        ]
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "Message": "Message(s) NOT Found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "InboundSMS",
    "APIVersion": "1.04",
    "TimePeriod": "1440",
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "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."
            }
        ]
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "Message": "Message(s) NOT Found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/json/get \
  --header "Content-Type: application/json; encoding='utf-8'" \
  --data '{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "InboundSMS",
    "APIVersion": "1.04",
    "TimePeriod": "1440",
  }'                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "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."
            }
        ]
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "Message": "Message(s) NOT Found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/json/get \
  --header "Content-Type: application/json; encoding='utf-8'" \
  --data '{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "InboundSMS",
    "APIVersion": "1.04",
    "TimePeriod": "1440",
  }'                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "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."
            }
        ]
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "Message": "Message(s) NOT Found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

<?php

$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "InboundSMS";
$version = "1.04";
$timeperiod = "1440";           // required

$data = array(
    "Sender" => $sender,
    "APIKey" => $apikey,
    "Type" => $type,
    "APIVersion" => $version,
    "TimePeriod" => $timeperiod,
);

$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://www.tnz.co.nz/api/json/get");
    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();
}

?>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "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."
            }
        ]
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "Message": "Message(s) NOT Found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

<?php

$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "InboundSMS";
$version = "1.04";
$timeperiod = "1440";           // required

$data = array(
    "Sender" => $sender,
    "APIKey" => $apikey,
    "Type" => $type,
    "APIVersion" => $version,
    "TimePeriod" => $timeperiod,
);

$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://www.tnz.co.nz/api/json/get");
    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();
}

?>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "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."
            }
        ]
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "Message": "Message(s) NOT Found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Net;
using System.IO;

namespace GetInboundSMSJSON
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }
        
        private void GetInboundSMSByJSONAPI()
        {
            string apiURL = "https://www.tnz.co.nz/api/json/get";

            string strSender = "application@domain.com";
            string strAPIKey = "ta8wr7ymd";
            string strAPIVersion = "1.04";
            string strType = "InboundSMS";
            string strTimePeriod = "1440";             // required

            string strJSONData = "{" +
                "\"Sender\": \"" + strSender + "\"," +
                "\"APIKey\": \"" + strAPIKey + "\"," +
                "\"Type\":\"" + strType + "\"," +
                "\"APIVersion\":\"" + strAPIVersion + "\"," +
                "\"TimePeriod\":\"" + strTimePeriod + "\"," +
            "}";
                        
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "application/json; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }
            
            MessageBox.Show(strResponse);
        }
    }
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "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."
            }
        ]
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "Message": "Message(s) NOT Found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Net;
using System.IO;

namespace GetInboundSMSJSON
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }
        
        private void GetInboundSMSByJSONAPI()
        {
            string apiURL = "https://www.tnz.co.nz/api/json/get";

            string strSender = "application@domain.com";
            string strAPIKey = "ta8wr7ymd";
            string strAPIVersion = "1.04";
            string strType = "InboundSMS";
            string strTimePeriod = "1440";             // required

            string strJSONData = "{" +
                "\"Sender\": \"" + strSender + "\"," +
                "\"APIKey\": \"" + strAPIKey + "\"," +
                "\"Type\":\"" + strType + "\"," +
                "\"APIVersion\":\"" + strAPIVersion + "\"," +
                "\"TimePeriod\":\"" + strTimePeriod + "\"," +
            "}";
                        
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "application/json; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }
            
            MessageBox.Show(strResponse);
        }
    }
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "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."
            }
        ]
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "Message": "Message(s) NOT Found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

import requests
import json

url = "https://www.tnz.co.nz/api/json/get/"

headers = {
    "Content-Type": "application/json",
    "encoding": "utf-8"
}

data = {
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "InboundSMS",
    "APIVersion": "1.04",
    "TimePeriod": "1440"
}

r = requests.post(url, data=json.dumps(data), headers=headers)

print(r)
print(r.text)                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "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."
            }
        ]
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "Message": "Message(s) NOT Found"
}                                          
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

import requests
import json

url = "https://www.tnz.co.nz/api/json/get/"

headers = {
    "Content-Type": "application/json",
    "encoding": "utf-8"
}

data = {
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "InboundSMS",
    "APIVersion": "1.04",
    "TimePeriod": "1440"
}

r = requests.post(url, data=json.dumps(data), headers=headers)

print(r)
print(r.text)                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "Result": "Success",
    "Data": {
        "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."
            }
        ]
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "Message": "Message(s) NOT Found"
}                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <Sender>application@domain.com</Sender>
  <APIKey>ta8wr7ymd</APIKey>
  <Type>InboundSMS</Type>
  <APIVersion>1.04</APIVersion>
  <TimePeriod>1440</TimePeriod>
</root>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
		<MessageReceived>
			<Date>2019-12-01 14:02:03</Date>
			<From>+6421000001</Destination>
			<MessageText>This is a reply back from the mobile phone.</MessageText>
		</MessageReceived>
		<MessageReceived>
			<Date>2019-12-01 14:04:14</Date>
			<From>+6421000001</Destination>
			<MessageText>This is a second reply.</MessageText>
		</MessageReceived>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <Message>Message(s) NOT Found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <Sender>application@domain.com</Sender>
  <APIKey>ta8wr7ymd</APIKey>
  <Type>InboundSMS</Type>
  <APIVersion>1.04</APIVersion>
  <TimePeriod>1440</TimePeriod>
</root>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
		<MessageReceived>
			<Date>2019-12-01 14:02:03</Date>
			<From>+6421000001</Destination>
			<MessageText>This is a reply back from the mobile phone.</MessageText>
		</MessageReceived>
		<MessageReceived>
			<Date>2019-12-01 14:04:14</Date>
			<From>+6421000001</Destination>
			<MessageText>This is a second reply.</MessageText>
		</MessageReceived>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <Message>Message(s) NOT Found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/xml/get \
  --header "Content-Type: text/xml; encoding='utf-8'" \
  --data '
  <?xml version="1.0" encoding="UTF-8"?>
  <root>
    <Sender>application@domain.com</Sender>
    <APIKey>ta8wr7ymd</APIKey>
    <Type>InboundSMS</Type>
    <APIVersion>1.04</APIVersion>
    <TimePeriod>1440</TimePeriod>
  </root>
  '                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
		<MessageReceived>
			<Date>2019-12-01 14:02:03</Date>
			<From>+6421000001</Destination>
			<MessageText>This is a reply back from the mobile phone.</MessageText>
		</MessageReceived>
		<MessageReceived>
			<Date>2019-12-01 14:04:14</Date>
			<From>+6421000001</Destination>
			<MessageText>This is a second reply.</MessageText>
		</MessageReceived>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <Message>Message(s) NOT Found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/xml/get \
  --header "Content-Type: text/xml; encoding='utf-8'" \
  --data '
  <?xml version="1.0" encoding="UTF-8"?>
  <root>
    <Sender>application@domain.com</Sender>
    <APIKey>ta8wr7ymd</APIKey>
    <Type>InboundSMS</Type>
    <APIVersion>1.04</APIVersion>
    <TimePeriod>1440</TimePeriod>
  </root>
  '                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
		<MessageReceived>
			<Date>2019-12-01 14:02:03</Date>
			<From>+6421000001</Destination>
			<MessageText>This is a reply back from the mobile phone.</MessageText>
		</MessageReceived>
		<MessageReceived>
			<Date>2019-12-01 14:04:14</Date>
			<From>+6421000001</Destination>
			<MessageText>This is a second reply.</MessageText>
		</MessageReceived>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <Message>Message(s) NOT Found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?php

$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "InboundSMS";
$version = "1.04";
$timeperiod = "1440";           // required

$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><root></root>");

$data->addChild("Sender",$sender);
$data->addChild("APIKey",$apikey);
$data->addChild("Type",$type);
$data->addChild("APIVersion",$version);
$data->addChild("TimePeriod",$timeperiod);

$headers = array(
  "Content-Type: text/xml",
  "encoding='utf-8'",
  "Content-length: ".strlen($data->asXML()),
  "Connection: close"
);  

try
{
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://www.tnz.co.nz/api/xml/get");
    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();
}

?>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
		<MessageReceived>
			<Date>2019-12-01 14:02:03</Date>
			<From>+6421000001</Destination>
			<MessageText>This is a reply back from the mobile phone.</MessageText>
		</MessageReceived>
		<MessageReceived>
			<Date>2019-12-01 14:04:14</Date>
			<From>+6421000001</Destination>
			<MessageText>This is a second reply.</MessageText>
		</MessageReceived>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <Message>Message(s) NOT Found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?php

$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "InboundSMS";
$version = "1.04";
$timeperiod = "1440";           // required

$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><root></root>");

$data->addChild("Sender",$sender);
$data->addChild("APIKey",$apikey);
$data->addChild("Type",$type);
$data->addChild("APIVersion",$version);
$data->addChild("TimePeriod",$timeperiod);

$options = array(
    'http' => array(
        'method' => 'POST',
        'content' => $data->asXML(),
        'header' => "Content-Type: text/xml; encoding='utf-8'\n"
    )
);

$headers = array(
  "Content-Type: text/xml",
  "encoding='utf-8'",
  "Content-length: ".strlen($data->asXML()),
  "Connection: close"
);  

try
{
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://www.tnz.co.nz/api/xml/get");
    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();
}

?>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
		<MessageReceived>
			<Date>2019-12-01 14:02:03</Date>
			<From>+6421000001</Destination>
			<MessageText>This is a reply back from the mobile phone.</MessageText>
		</MessageReceived>
		<MessageReceived>
			<Date>2019-12-01 14:04:14</Date>
			<From>+6421000001</Destination>
			<MessageText>This is a second reply.</MessageText>
		</MessageReceived>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <Message>Message(s) NOT Found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Xml;
using System.Windows.Forms;

using System.IO;
using System.Net;

namespace TestXML
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
        {
            XmlNode workingNode = xmlDoc.CreateElement(name);
            workingNode.InnerText = val;

            return workingNode;
        }
        
        private void btnSendSMS_Click(object sender, EventArgs e)
        {
            string apiURL = "https://www.tnz.co.nz/api/xml/get";

            string strSender = "application@domain.com";
            string strAPIKey = "ta8wr7ymd";
            string strType = "InboundSMS";
            string strAPIVersion = "1.04";
            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("root");
            xmlDoc.AppendChild(rootNode);

            rootNode.AppendChild(addChildNode(xmlDoc, "Sender", strSender));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", strAPIKey));
            rootNode.AppendChild(addChildNode(xmlDoc, "Type", strType));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIVersion", strAPIVersion));
            rootNode.AppendChild(addChildNode(xmlDoc, "TimePeriod", strTimePeriod));

            XmlNode workingNode = xmlDoc.CreateElement("Sender");

            //
            // Send Raw XML Request
            //
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "text/xml; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }

            MessageBox.Show(strResponse);
        }
    }
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
		<MessageReceived>
			<Date>2019-12-01 14:02:03</Date>
			<From>+6421000001</Destination>
			<MessageText>This is a reply back from the mobile phone.</MessageText>
		</MessageReceived>
		<MessageReceived>
			<Date>2019-12-01 14:04:14</Date>
			<From>+6421000001</Destination>
			<MessageText>This is a second reply.</MessageText>
		</MessageReceived>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <Message>Message(s) NOT Found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Xml;
using System.Windows.Forms;

using System.IO;
using System.Net;

namespace TestXML
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
        {
            XmlNode workingNode = xmlDoc.CreateElement(name);
            workingNode.InnerText = val;

            return workingNode;
        }
        
        private void btnSendSMS_Click(object sender, EventArgs e)
        {
            string apiURL = "https://www.tnz.co.nz/api/xml/get";

            string strSender = "application@domain.com";
            string strAPIKey = "ta8wr7ymd";
            string strType = "InboundSMS";
            string strAPIVersion = "1.04";
            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("root");
            xmlDoc.AppendChild(rootNode);

            rootNode.AppendChild(addChildNode(xmlDoc, "Sender", strSender));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", strAPIKey));
            rootNode.AppendChild(addChildNode(xmlDoc, "Type", strType));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIVersion", strAPIVersion));
            rootNode.AppendChild(addChildNode(xmlDoc, "TimePeriod", strTimePeriod));

            XmlNode workingNode = xmlDoc.CreateElement("Sender");

            //
            // Send Raw XML Request
            //
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "text/xml; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }

            MessageBox.Show(strResponse);
        }
    }
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
		<MessageReceived>
			<Date>2019-12-01 14:02:03</Date>
			<From>+6421000001</Destination>
			<MessageText>This is a reply back from the mobile phone.</MessageText>
		</MessageReceived>
		<MessageReceived>
			<Date>2019-12-01 14:04:14</Date>
			<From>+6421000001</Destination>
			<MessageText>This is a second reply.</MessageText>
		</MessageReceived>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <Message>Message(s) NOT Found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

import requests
import xml.etree.ElementTree as ET

url = "https://www.tnz.co.nz/api/xml/get/"

headers = {
    "Content-Type": "text/xml",
    "encoding": "utf-8"
}

root = ET.Element('root')

ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "Type").text = "InboundSMS"
ET.SubElement(root, "APIVersion").text = "1.04"
ET.SubElement(root, "TimePeriod").text = "1440"

r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)

print(r)
print(r.text)                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
		<MessageReceived>
			<Date>2019-12-01 14:02:03</Date>
			<From>+6421000001</Destination>
			<MessageText>This is a reply back from the mobile phone.</MessageText>
		</MessageReceived>
		<MessageReceived>
			<Date>2019-12-01 14:04:14</Date>
			<From>+6421000001</Destination>
			<MessageText>This is a second reply.</MessageText>
		</MessageReceived>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <Message>Message(s) NOT Found</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

import requests
import xml.etree.ElementTree as ET

url = "https://www.tnz.co.nz/api/xml/get/"

headers = {
    "Content-Type": "text/xml",
    "encoding": "utf-8"
}

root = ET.Element('root')

ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "Type").text = "InboundSMS"
ET.SubElement(root, "APIVersion").text = "1.04"
ET.SubElement(root, "TimePeriod").text = "1440"

r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)

print(r)
print(r.text)                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <Data>
		<MessageReceived>
			<Date>2019-12-01 14:02:03</Date>
			<From>+6421000001</Destination>
			<MessageText>This is a reply back from the mobile phone.</MessageText>
		</MessageReceived>
		<MessageReceived>
			<Date>2019-12-01 14:04:14</Date>
			<From>+6421000001</Destination>
			<MessageText>This is a second reply.</MessageText>
		</MessageReceived>
    </Data>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <Message>Message(s) NOT Found</Message>
</root>                                          
Required parameters
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
APIVersion 1.04 Version of the API used
Type InboundSMS Type of API request
TimePeriod 1440 Return results from the last x minutes
SUCCESS response parameters
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
FAILED response parameters
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)


GET Received Poll - Track individual reply SMS messages using a GET poll

API users are able to poll for replies to a specific SMS message, tracked using the MessageID on the outbound message.

 
 
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "SMSReceived",
    "APIVersion": "1.04",
    "MessageID": "ID123456",
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "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."
            }
        ]
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                          
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "SMSReceived",
    "APIVersion": "1.04",
    "MessageID": "ID123456",
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "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."
            }
        ]
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                          
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/json/get \
  --header "Content-Type: application/json; encoding='utf-8'" \
  --data '{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "SMSReceived",
    "APIVersion": "1.04",
    "MessageID": "ID123456",
  }'                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "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."
            }
        ]
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                          
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/json/get \
  --header "Content-Type: application/json; encoding='utf-8'" \
  --data '{
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "SMSReceived",
    "APIVersion": "1.04",
    "MessageID": "ID123456",
  }'                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "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."
            }
        ]
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                          
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

<?php

$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "SMSReceived";
$version = "1.04";
$message_id = "ID123456";           // required

$data = array(
    "Sender" => $sender,
    "APIKey" => $apikey,
    "Type" => $type,
    "APIVersion" => $version,
    "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://www.tnz.co.nz/api/json/get");
    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();
}

?>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "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."
            }
        ]
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                          
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

<?php

$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "SMSReceived";
$version = "1.04";
$message_id = "ID123456";           // required

$data = array(
    "Sender" => $sender,
    "APIKey" => $apikey,
    "Type" => $type,
    "APIVersion" => $version,
    "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://www.tnz.co.nz/api/json/get");
    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();
}

?>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "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."
            }
        ]
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                          
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Net;
using System.IO;

namespace GetSMSReceivedJSON
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }
        
        private void GetSMSReceivedByJSONAPI()
        {
            string apiURL = "https://www.tnz.co.nz/api/json/get";

            string strSender = "application@domain.com";
            string strAPIKey = "ta8wr7ymd";
            string strAPIVersion = "1.04";
            string strType = "SMSReceived";
            string strMessageID = "ID123456";             // required

            string strJSONData = "{" +
                "\"Sender\": \"" + strSender + "\"," +
                "\"APIKey\": \"" + strAPIKey + "\"," +
                "\"Type\":\"" + strType + "\"," +
                "\"APIVersion\":\"" + strAPIVersion + "\"," +
                "\"MessageID\":\"" + strMessageID + "\"," +
            "}";
                        
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "application/json; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }
            
            MessageBox.Show(strResponse);
        }
    }
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "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."
            }
        ]
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                          
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Net;
using System.IO;

namespace GetSMSReceivedJSON
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }
        
        private void GetSMSReceivedByJSONAPI()
        {
            string apiURL = "https://www.tnz.co.nz/api/json/get";

            string strSender = "application@domain.com";
            string strAPIKey = "ta8wr7ymd";
            string strAPIVersion = "1.04";
            string strType = "SMSReceived";
            string strMessageID = "ID123456";             // required

            string strJSONData = "{" +
                "\"Sender\": \"" + strSender + "\"," +
                "\"APIKey\": \"" + strAPIKey + "\"," +
                "\"Type\":\"" + strType + "\"," +
                "\"APIVersion\":\"" + strAPIVersion + "\"," +
                "\"MessageID\":\"" + strMessageID + "\"," +
            "}";
                        
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "application/json; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(strJSONData);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }
            
            MessageBox.Show(strResponse);
        }
    }
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "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."
            }
        ]
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                          
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

import requests
import json

url = "https://www.tnz.co.nz/api/json/get/"

headers = {
    "Content-Type": "application/json",
    "encoding": "utf-8"
}

data = {
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "SMSReceived",
    "APIVersion": "1.04",
    "MessageID" : "ID123456"
}

r = requests.post(url, data=json.dumps(data), headers=headers)

print(r)
print(r.text)                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "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."
            }
        ]
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                          
API URL:   https://www.tnz.co.nz/api/json/get/
HTTP Header:   Content-Type="application/json; encoding='utf-8'"

import requests
import json

url = "https://www.tnz.co.nz/api/json/get/"

headers = {
    "Content-Type": "application/json",
    "encoding": "utf-8"
}

data = {
    "Sender": "application@domain.com",
    "APIKey": "ta8wr7ymd",
    "Type": "SMSReceived",
    "APIVersion": "1.04",
    "MessageID" : "ID123456"
}

r = requests.post(url, data=json.dumps(data), headers=headers)

print(r)
print(r.text)                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

{
    "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."
            }
        ]
    }
}                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

{
    "Result": "Failed",
    "MessageID": "AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD",
    "Message": "Missing Sender"
}                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <Sender>application@domain.com</Sender>
  <APIKey>ta8wr7ymd</APIKey>
  <Type>SMSReceived</Type>
  <APIVersion>1.04</APIVersion>
  <MessageID>ID123456</MessageID>
</root>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Status>Received</Status>
    <JobNum>10AB20CD</JobNum>
    <Account>Account#</Account>
    <SubAccount></SubAccount>
    <Department></Department>
    <MessageSent>
	    <Date>2019-12-01 13:45:54</Date>
	    <Destination>6421000001</Destination>
	    <MessageText>This is an outbound message sent via API.</MessageText>
	</MessageSent>
    <MessageReceived>
	    <Date>2019-12-01 14:02:03</Date>
	    <From>+6421000001</Destination>
	    <MessageText>This is a reply back from the mobile phone.</MessageText>
	</MessageReceived>
    <MessageReceived>
	    <Date>2019-12-01 14:04:14</Date>
	    <From>+6421000001</Destination>
	    <MessageText>This is a second reply.</MessageText>
	</MessageReceived>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <Sender>application@domain.com</Sender>
  <APIKey>ta8wr7ymd</APIKey>
  <Type>SMSReceived</Type>
  <APIVersion>1.04</APIVersion>
  <MessageID>ID123456</MessageID>
</root>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Status>Received</Status>
    <JobNum>10AB20CD</JobNum>
    <Account>Account#</Account>
    <SubAccount></SubAccount>
    <Department></Department>
    <MessageSent>
	    <Date>2019-12-01 13:45:54</Date>
	    <Destination>6421000001</Destination>
	    <MessageText>This is an outbound message sent via API.</MessageText>
	</MessageSent>
    <MessageReceived>
	    <Date>2019-12-01 14:02:03</Date>
	    <From>+6421000001</Destination>
	    <MessageText>This is a reply back from the mobile phone.</MessageText>
	</MessageReceived>
    <MessageReceived>
	    <Date>2019-12-01 14:04:14</Date>
	    <From>+6421000001</Destination>
	    <MessageText>This is a second reply.</MessageText>
	</MessageReceived>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/xml/get \
  --header "Content-Type: text/xml; encoding='utf-8'" \
  --data '
  <?xml version="1.0" encoding="UTF-8"?>
  <root>
    <Sender>application@domain.com</Sender>
    <APIKey>ta8wr7ymd</APIKey>
    <Type>SMSReceived</Type>
    <APIVersion>1.04</APIVersion>
    <MessageID>ID123456</MessageID>
  </root>
  '                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Status>Received</Status>
    <JobNum>10AB20CD</JobNum>
    <Account>Account#</Account>
    <SubAccount></SubAccount>
    <Department></Department>
    <MessageSent>
	    <Date>2019-12-01 13:45:54</Date>
	    <Destination>6421000001</Destination>
	    <MessageText>This is an outbound message sent via API.</MessageText>
	</MessageSent>
    <MessageReceived>
	    <Date>2019-12-01 14:02:03</Date>
	    <From>+6421000001</Destination>
	    <MessageText>This is a reply back from the mobile phone.</MessageText>
	</MessageReceived>
    <MessageReceived>
	    <Date>2019-12-01 14:04:14</Date>
	    <From>+6421000001</Destination>
	    <MessageText>This is a second reply.</MessageText>
	</MessageReceived>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

curl --request POST \
  --url https://www.tnz.co.nz/api/xml/get \
  --header "Content-Type: text/xml; encoding='utf-8'" \
  --data '
  <?xml version="1.0" encoding="UTF-8"?>
  <root>
    <Sender>application@domain.com</Sender>
    <APIKey>ta8wr7ymd</APIKey>
    <Type>SMSReceived</Type>
    <APIVersion>1.04</APIVersion>
    <MessageID>ID123456</MessageID>
  </root>
  '                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Status>Received</Status>
    <JobNum>10AB20CD</JobNum>
    <Account>Account#</Account>
    <SubAccount></SubAccount>
    <Department></Department>
    <MessageSent>
	    <Date>2019-12-01 13:45:54</Date>
	    <Destination>6421000001</Destination>
	    <MessageText>This is an outbound message sent via API.</MessageText>
	</MessageSent>
    <MessageReceived>
	    <Date>2019-12-01 14:02:03</Date>
	    <From>+6421000001</Destination>
	    <MessageText>This is a reply back from the mobile phone.</MessageText>
	</MessageReceived>
    <MessageReceived>
	    <Date>2019-12-01 14:04:14</Date>
	    <From>+6421000001</Destination>
	    <MessageText>This is a second reply.</MessageText>
	</MessageReceived>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?php

$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "SMSReceived";
$version = "1.04";
$message_id = "ID123456";           // required

$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><root></root>");

$data->addChild("Sender",$sender);
$data->addChild("APIKey",$apikey);
$data->addChild("Type",$type);
$data->addChild("APIVersion",$version);
$data->addChild("MessageID",$message_id);

$headers = array(
  "Content-Type: text/xml",
  "encoding='utf-8'",
  "Content-length: ".strlen($data->asXML()),
  "Connection: close"
);  

try
{
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://www.tnz.co.nz/api/xml/get");
    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();
}

?>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Status>Received</Status>
    <JobNum>10AB20CD</JobNum>
    <Account>Account#</Account>
    <SubAccount></SubAccount>
    <Department></Department>
    <MessageSent>
	    <Date>2019-12-01 13:45:54</Date>
	    <Destination>6421000001</Destination>
	    <MessageText>This is an outbound message sent via API.</MessageText>
	</MessageSent>
    <MessageReceived>
	    <Date>2019-12-01 14:02:03</Date>
	    <From>+6421000001</Destination>
	    <MessageText>This is a reply back from the mobile phone.</MessageText>
	</MessageReceived>
    <MessageReceived>
	    <Date>2019-12-01 14:04:14</Date>
	    <From>+6421000001</Destination>
	    <MessageText>This is a second reply.</MessageText>
	</MessageReceived>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

<?php

$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "SMSReceived";
$version = "1.04";
$message_id = "ID123456";           // required

$data = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><root></root>");

$data->addChild("Sender",$sender);
$data->addChild("APIKey",$apikey);
$data->addChild("Type",$type);
$data->addChild("APIVersion",$version);
$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",
  "encoding='utf-8'",
  "Content-length: ".strlen($data->asXML()),
  "Connection: close"
);  

try
{
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://www.tnz.co.nz/api/xml/get");
    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();
}

?>                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Status>Received</Status>
    <JobNum>10AB20CD</JobNum>
    <Account>Account#</Account>
    <SubAccount></SubAccount>
    <Department></Department>
    <MessageSent>
	    <Date>2019-12-01 13:45:54</Date>
	    <Destination>6421000001</Destination>
	    <MessageText>This is an outbound message sent via API.</MessageText>
	</MessageSent>
    <MessageReceived>
	    <Date>2019-12-01 14:02:03</Date>
	    <From>+6421000001</Destination>
	    <MessageText>This is a reply back from the mobile phone.</MessageText>
	</MessageReceived>
    <MessageReceived>
	    <Date>2019-12-01 14:04:14</Date>
	    <From>+6421000001</Destination>
	    <MessageText>This is a second reply.</MessageText>
	</MessageReceived>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Xml;
using System.Windows.Forms;

using System.IO;
using System.Net;

namespace TestXML
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
        {
            XmlNode workingNode = xmlDoc.CreateElement(name);
            workingNode.InnerText = val;

            return workingNode;
        }
        
        private void btnSendSMS_Click(object sender, EventArgs e)
        {
            string apiURL = "https://www.tnz.co.nz/api/xml/get";

            string strSender = "application@domain.com";
            string strAPIKey = "ta8wr7ymd";
            string strType = "SMSReceived";
            string strAPIVersion = "1.04";
            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("root");
            xmlDoc.AppendChild(rootNode);

            rootNode.AppendChild(addChildNode(xmlDoc, "Sender", strSender));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", strAPIKey));
            rootNode.AppendChild(addChildNode(xmlDoc, "Type", strType));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIVersion", strAPIVersion));
            rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", strMessageID));

            XmlNode workingNode = xmlDoc.CreateElement("Sender");

            //
            // Send Raw XML Request
            //
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "text/xml; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }

            MessageBox.Show(strResponse);
        }
    }
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Status>Received</Status>
    <JobNum>10AB20CD</JobNum>
    <Account>Account#</Account>
    <SubAccount></SubAccount>
    <Department></Department>
    <MessageSent>
	    <Date>2019-12-01 13:45:54</Date>
	    <Destination>6421000001</Destination>
	    <MessageText>This is an outbound message sent via API.</MessageText>
	</MessageSent>
    <MessageReceived>
	    <Date>2019-12-01 14:02:03</Date>
	    <From>+6421000001</Destination>
	    <MessageText>This is a reply back from the mobile phone.</MessageText>
	</MessageReceived>
    <MessageReceived>
	    <Date>2019-12-01 14:04:14</Date>
	    <From>+6421000001</Destination>
	    <MessageText>This is a second reply.</MessageText>
	</MessageReceived>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Xml;
using System.Windows.Forms;

using System.IO;
using System.Net;

namespace TestXML
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
        {
            XmlNode workingNode = xmlDoc.CreateElement(name);
            workingNode.InnerText = val;

            return workingNode;
        }
        
        private void btnSendSMS_Click(object sender, EventArgs e)
        {
            string apiURL = "https://www.tnz.co.nz/api/xml/get";

            string strSender = "application@domain.com";
            string strAPIKey = "ta8wr7ymd";
            string strType = "SMSReceived";
            string strAPIVersion = "1.04";
            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("root");
            xmlDoc.AppendChild(rootNode);

            rootNode.AppendChild(addChildNode(xmlDoc, "Sender", strSender));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIKey", strAPIKey));
            rootNode.AppendChild(addChildNode(xmlDoc, "Type", strType));
            rootNode.AppendChild(addChildNode(xmlDoc, "APIVersion", strAPIVersion));
            rootNode.AppendChild(addChildNode(xmlDoc, "MessageID", strMessageID));

            XmlNode workingNode = xmlDoc.CreateElement("Sender");

            //
            // Send Raw XML Request
            //
            HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(apiURL);
            getRequest.Method = WebRequestMethods.Http.Post;
            getRequest.ContentType = "text/xml; encoding='utf-8'";

            byte[] byteArray = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
            getRequest.ContentLength = byteArray.Length;
            Stream newStream = getRequest.GetRequestStream(); //open connection
            newStream.Write(byteArray, 0, byteArray.Length); // Send the data.
            newStream.Close();

            string strResponse = "";

            HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
            using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
            {
                strResponse = sr.ReadToEnd();
            }

            MessageBox.Show(strResponse);
        }
    }
}                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Status>Received</Status>
    <JobNum>10AB20CD</JobNum>
    <Account>Account#</Account>
    <SubAccount></SubAccount>
    <Department></Department>
    <MessageSent>
	    <Date>2019-12-01 13:45:54</Date>
	    <Destination>6421000001</Destination>
	    <MessageText>This is an outbound message sent via API.</MessageText>
	</MessageSent>
    <MessageReceived>
	    <Date>2019-12-01 14:02:03</Date>
	    <From>+6421000001</Destination>
	    <MessageText>This is a reply back from the mobile phone.</MessageText>
	</MessageReceived>
    <MessageReceived>
	    <Date>2019-12-01 14:04:14</Date>
	    <From>+6421000001</Destination>
	    <MessageText>This is a second reply.</MessageText>
	</MessageReceived>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

import requests
import xml.etree.ElementTree as ET

url = "https://www.tnz.co.nz/api/xml/get/"

headers = {
    "Content-Type": "text/xml",
    "encoding": "utf-8"
}

root = ET.Element('root')

ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "Type").text = "SMSReceived"
ET.SubElement(root, "APIVersion").text = "1.04"
ET.SubElement(root, "MessageID").text = "ID123456"

r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)

print(r)
print(r.text)                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Status>Received</Status>
    <JobNum>10AB20CD</JobNum>
    <Account>Account#</Account>
    <SubAccount></SubAccount>
    <Department></Department>
    <MessageSent>
	    <Date>2019-12-01 13:45:54</Date>
	    <Destination>6421000001</Destination>
	    <MessageText>This is an outbound message sent via API.</MessageText>
	</MessageSent>
    <MessageReceived>
	    <Date>2019-12-01 14:02:03</Date>
	    <From>+6421000001</Destination>
	    <MessageText>This is a reply back from the mobile phone.</MessageText>
	</MessageReceived>
    <MessageReceived>
	    <Date>2019-12-01 14:04:14</Date>
	    <From>+6421000001</Destination>
	    <MessageText>This is a second reply.</MessageText>
	</MessageReceived>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                          
API URL:   https://www.tnz.co.nz/api/xml/get/
HTTP Header:   Content-Type="text/xml; encoding='utf-8'"

import requests
import xml.etree.ElementTree as ET

url = "https://www.tnz.co.nz/api/xml/get/"

headers = {
    "Content-Type": "text/xml",
    "encoding": "utf-8"
}

root = ET.Element('root')

ET.SubElement(root, "Sender").text = "application@domain.com"
ET.SubElement(root, "APIKey").text = "ta8wr7ymd"
ET.SubElement(root, "Type").text = "SMSReceived"
ET.SubElement(root, "APIVersion").text = "1.04"
ET.SubElement(root, "MessageID").text = "ID123456"

r = requests.post(url, data=ET.tostring(root,'utf-8'), headers=headers)

print(r)
print(r.text)                                          

Sample SUCCESS Response [HTTP Response Status: 200 OK]:

<?xml version="1.0"?>
<root>
    <Result>Success</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Status>Received</Status>
    <JobNum>10AB20CD</JobNum>
    <Account>Account#</Account>
    <SubAccount></SubAccount>
    <Department></Department>
    <MessageSent>
	    <Date>2019-12-01 13:45:54</Date>
	    <Destination>6421000001</Destination>
	    <MessageText>This is an outbound message sent via API.</MessageText>
	</MessageSent>
    <MessageReceived>
	    <Date>2019-12-01 14:02:03</Date>
	    <From>+6421000001</Destination>
	    <MessageText>This is a reply back from the mobile phone.</MessageText>
	</MessageReceived>
    <MessageReceived>
	    <Date>2019-12-01 14:04:14</Date>
	    <From>+6421000001</Destination>
	    <MessageText>This is a second reply.</MessageText>
	</MessageReceived>
</root>                                          

Sample FAILURE Response [HTTP Response Status: 400 Bad Request]:

<?xml version="1.0"?>
<root>
    <Result>Failed</Result>
    <MessageID>AAAAAAAA-BBBB-BBBB-CCCC-DDDDDDDDDDDD</MessageID>
    <Message>Missing or empty sender</Message>
</root>                                          
Required parameters
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
APIVersion 1.04 Version of the API used
Type SMSReceived Type of API request
MessageID ID123456 Your provided Message ID or TNZ Group generated Message ID
SUCCESS response parameters
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
FAILED response parameters
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)

Versioning

When a new version of the API is released, the APIVersion parameter is incremented.
This allows you to use a different API version based on the MessageType, limiting the testing you require should you wish to update one MessageType 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.

For example, you may be using:

"MessageType": "SMS",
"APIVersion": "1.03", 
                                            
However, you may also dynamically use:

"MessageType": "Email",
"APIVersion": "1.01", 
                                            

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


Frequently Asked Questions

Yes, full international delivery is supported.
The maximum request size supported is 20MB. This is our server side limitation. Your client side limitation may be smaller.
There is no limit to the number of Destinations (in either format), provided you do not breach the 20MB maximum REST request size.
There is a limit of 10 files specified in a single request. There is no file size limitation, provided you do not breach the 20MB maximum REST request size.
Yes, we support email security measures. Contact us for further information on setting up your own security measures for whitelabeled messages delivered with the API.
You can send a wide range of file types, including Microsoft Office® documents (doc, docx, ppt, pptx, xls, xlsx, etc), Openoffice/Libreoffice documents (odt, ods, etc), Adobe® documents (pdf, etc), image file types (jpg, gif, tif, bmp, etc) and more (txt, html, etc).
SMS messages are sent and charged in blocks of characters. One text message is 160 characters. By default, we will limit your message to three-message-parts in length (459 characters using the GSM character set, or 210 characters using Unicode/UCS-2). This can be increased on request. See the SMS Message Parts and Concatenated SMS guide for further information.
Yes, we can provide a daily or monthly email report (as an attached CSV file) containing data on messages sent. This can be used for billing (contains costs) or for reporting (doesn’t contain costs).
Yes, encrypted submissions are accepted across the API via HTTPS. SSL/TLS is also supported for outbound email messages provided the receiving email server supports this.
Some networks support customised SMS Caller IDs. This can be configured using your Web Dashboard.
Your Fax Caller ID can be configured using your Web Dashboard.
Your Voice and TextToSpeech Caller ID is specified on a per-message basis using the 'CallerID' parameter.
"); ");