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).
Mode parameter to cause your message to fail delivering (it will not be attempted and you will not be charged). The API will treat it as a normal failed message, but will skip the actual message delivery. 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.
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
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.
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.01 | Version of the API used; can differ based on MessageType |
| MessageID | ID123456 | A message tracking identifier (maximum 40 characters). If you do not supply this field, the API will return one for you in the response body (UUID v4 of 36 characters) |
| MessageType | Available message types referenced in Adding variables based on the MessageType, eg Email, Fax, SMS, 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
Available MessageType values are: Email, SMS, Fax, TextToSpeech
Each message type has it’s own variables specified in MessageDataRed sections are required fields
MessageType=Email,MessageData=
Content-Type: "application/json; encoding='utf-8'"
{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageType": "Email",
"APIVersion": "1.01",
"MessageData" :
{
"EmailSubject": "Test Email Subject",
"From": "noreply",
"MessagePlain": "Hello, This is a test message. Thank you.",
"Destinations" :
[
"recipient.four@example.com"
]
}
}
Content-Type: "application/json; encoding='utf-8'"
{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageType": "Email",
"APIVersion": "1.01",
"MessageID": "ID123456",
"MessageData" :
{
"Reference": "Test1",
"SendTime": "",
"TimeZone": "New Zealand",
"SubAccount": "SubAccount01",
"Department": "Department01",
"ChargeCode": "BillingGroup01",
"EmailSubject": "Test Email Subject",
"From": "noreply",
"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%%"
}
]
}
}
curl --request POST \
--url https://api.tnz.net.nz/api/json/send \
--header "Content-Type: application/json; encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageType": "Email",
"APIVersion": "1.01",
"MessageData" :
{
"EmailSubject": "Test Email Subject",
"From": "noreply",
"MessagePlain": "Hello, This is a test message. Thank you.",
"Destinations" :
[
"recipient.four@example.com"
]
}
}'
curl --request POST \
--url https://api.tnz.net.nz/api/json/send \
--header "Content-Type: application/json; encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageType": "Email",
"APIVersion": "1.01",
"MessageID": "ID123456",
"MessageData" :
{
"Reference": "Test1",
"SendTime": "",
"TimeZone": "New Zealand",
"SubAccount": "SubAccount01",
"Department": "Department01",
"ChargeCode": "BillingGroup01",
"EmailSubject": "Test Email Subject",
"From": "noreply",
"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%%"
}
]
}
}'
<?php
$data = array(
"Sender" => "application@domain.com", // your user id
"APIKey" => "ta8wr7ymd", // your api key
"MessageType" => "Email",
"APIVersion" => "1.01",
"MessageData" => array(
"EmailSubject" => "Test Email Subject",
"From" => "noreply",
"MessagePlain" => "Hello, This is a test message. Thank you.",
"Destinations" => array(
"recipient.four@example.com"
),
)
);
$options = array(
'http' => array(
'method' => 'POST',
'content' => json_encode($data),
'header' => "Content-Type: application/json; encoding='utf-8'\n"
)
);
$context = stream_context_create($options);
$result = file_get_contents("https://api.tnz.net.nz/api/json/send", false, $context);
header('Content-Type: application/json');
echo $result;
?>
<?php
$sender = "application@domain.com"; // your user id
$apikey = "ta8wr7ymd"; // your api key
$type = "Email";
$version = "1.01";
$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",
"From" => "noreply",
"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)
)
),
)
);
$options = array(
'http' => array(
'method' => 'POST',
'content' => json_encode($data),
'header' => "Content-Type: application/json; encoding='utf-8'\n"
)
);
$context = stream_context_create($options);
$result = file_get_contents("https://api.tnz.net.nz/api/json/send", false, $context);
header('Content-Type: application/json');
echo $result;
?>
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 EmailJSON
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
#region CustomFunctions
private void SendEmail()
{
string apiURL = "https://api.tnz.net.nz/api/json/send";
//
// Send Email by JSON API interface
//
string EOL = "\r\n";
string strJSONData = "{" + EOL +
"\"Sender\": \"application@domain.com\"," + EOL +
"\"APIKey\": \"ta8wr7ymd\"," + EOL +
"\"MessageType\": \"Email\"," + EOL +
"\"APIVersion\": \"1.01\"," + EOL +
"\"MessageData\": {" + EOL +
"\"EmailSubject\": \"Test Email Subject\"," + EOL +
"\"From\": \"noreply\"," + EOL +
"\"MessagePlain\": \"Hello, This is a test message. Thank you.\"," + EOL +
"\"Destinations\": [\"recipient.one@example.com\"]" + 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);
}
#endregion
}
}
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 EmailJSON
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
#region CustomFunctions
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 SendEmail()
{
string apiURL = "https://api.tnz.net.nz/api/json/send";
string strSender = "application@domain.com";
string strAPIKey = "ta8wr7ymd";
string strMessageType = "Email";
string strAPIVersion = "1.01";
string strMessageID = "ID123456"; // optional
string strReference = "Test1";
string strSendTime = "";
string strTimeZone = "New Zealand";
string strSubAcocunt = "SubAccount01";
string strDepartment = "Department01";
string strChargeCode = "BillingGroup01";
string strEmailSubject = "Test Email Subject";
string strFrom = "noreply";
string strMessagePlain = "Hello,\r\nThis is a test message.\r\nThank you.";
string strMessageHTML = "Hello,
This is a test message.
Thank you.";
string strRecipient = "recipient.one@example.com";
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)));
}
//
// Send Email 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\": \"" + strAPIKey + "\"," + EOL +
"\"MessageType\": \"" + strMessageType + "\"," + EOL +
"\"APIVersion\": \"" + strAPIVersion + "\"," + EOL +
"\"MessageID\": \"" + strMessageID + "\"," + EOL +
"\"MessageData\": {" + EOL +
"\"Reference\": \"" + strReference + "\"," + EOL +
"\"SendTime\": \"" + strSendTime + "\"," + EOL +
"\"TimeZone\": \"" + strTimeZone + "\"," + EOL +
"\"SubAccount\": \"" + strSubAcocunt + "\"," + EOL +
"\"Department\": \"" + strDepartment + "\"," + EOL +
"\"ChargeCode\": \"" + strChargeCode + "\"," + EOL +
"\"EmailSubject\": \"" + strEmailSubject + "\"," + EOL +
"\"From\": \"" + strFrom + "\"," + EOL +
"\"MessagePlain\": \"" + addslashes(strMessagePlain) + "\"," + EOL +
"\"MessageHTML\": \"" + addslashes(strMessageHTML) + "\"," + EOL +
"\"Passthrough\" : \"" + strPassthrough + "\"," + 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);
}
#endregion
}
}
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.01</APIVersion>
<MessageData>
<EmailSubject>Test Email Subject</EmailSubject>
<From>noreply</From>
<MessagePlain>Hello, This is a test message. Thank you.</MessagePlain>
<Destinations>recipient.one@example.com</Destinations>
</MessageData>
</root>
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.01</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>
<From>noreply</From>
<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>
curl --request POST \
--url https://api.tnz.net.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.01</APIVersion>
<MessageData>
<EmailSubject>Test Email Subject</EmailSubject>
<From>noreply</From>
<MessagePlain>Hello, This is a test message. Thank you.</MessagePlain>
<Destinations>recipient@example.com</Destinations>
</MessageData>
</root>
'
curl --request POST \
--url https://api.tnz.net.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.01</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>
<From>noreply</From>
<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>
'
<?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.01");
$data->addChild("APIVersion","Email");
$data->addChild("MessageData");
$data->MessageData->addChild("EmailSubject","Test Email Subject");
$data->MessageData->addChild("From","noreply");
$data->MessageData->addChild("MessaePlain","Hello, This is a test message. Thank you.");
$data->MessageData->addChild("Destinations","recipient@example.com");
$options = array(
'http' => array(
'method' => 'POST',
'content' => $data->asXML(),
'header' => "Content-Type: text/xml; encoding='utf-8'\n"
)
);
$context = stream_context_create($options);
$result = file_get_contents("https://api.tnz.net.nz/api/xml/send", false, $context);
header("Content-Type: text/xml; encoding='utf-8'");
echo $result;
?>
<?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.01";
$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("From","noreply");
$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));
}
$options = array(
'http' => array(
'method' => 'POST',
'content' => $data->asXML(),
'header' => "Content-Type: text/xml; encoding='utf-8'\n"
)
);
$context = stream_context_create($options);
$result = file_get_contents("https://api.tnz.net.nz/api/xml/send", false, $context);
header("Content-Type: text/xml; encoding='utf-8'");
echo $result;
?>
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 btnSendEmail_Click(object sender, EventArgs e)
{
string apiURL = "https://api.tnz.net.nz/api/xml/send";
//
// Send Email 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", "Email"));
rootNode.AppendChild(addChildNode(xmlDoc, "APIVersion", "1.01"));
XmlNode workingNode = xmlDoc.CreateElement("Sender");
//
// MessageData
//
XmlNode messageDataNode = xmlDoc.CreateElement("MessageData");
messageDataNode.AppendChild(addChildNode(xmlDoc, "EmailSubject", "Test Email Subject"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "From", "noreply"));
messageDataNode.AppendChild(addChildNode(xmlDoc, "MessagePlain", "Hello, This is a test message. Thank you."));
messageDataNode.AppendChild(addChildNode(xmlDoc, "Destinations", "recipient@example.com"));
//
// 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);
}
}
}
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 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 XmlNode addChildNode(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerText = val;
return workingNode;
}
private XmlNode addChildNodeCDATA(XmlDocument xmlDoc, string name, string val)
{
XmlNode workingNode = xmlDoc.CreateElement(name);
workingNode.InnerXml = @"<![CDATA[" + val + "]]>";
return workingNode;
}
private void btnSendEmail_Click(object sender, EventArgs e)
{
string apiURL = "https://api.tnz.net.nz/api/xml/send";
string strSender = "application@domain.com";
string strAPIKey = "ta8wr7ymd";
string strMessageType = "Email";
string strAPIVersion = "1.01";
string strMessageID = "ID123456"; // optional
string strReference = "Test1";
string strSendTime = "";
string strTimeZone = "New Zealand";
string strSubAcocunt = "SubAccount01";
string strDepartment = "Department01";
string strChargeCode = "BillingGroup01";
string strSubject = "Test Email Subject";
string strFrom = "noreply";
string strMessagePlain = "Hello,\r\nThis is a test message.\r\nThank you.";
string strMessageHTML = "<html>Hello,<br /><br />This is a test message.<br /><br />Thank you.</html>";
string strRecipient = "recipient.one@example.com";
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)));
}
//
// Send Email 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", strSubAcocunt));
messageDataNode.AppendChild(addChildNode(xmlDoc, "Department", strDepartment));
messageDataNode.AppendChild(addChildNode(xmlDoc, "ChargeCode", strChargeCode));
messageDataNode.AppendChild(addChildNode(xmlDoc, "EmailSubject", strSubject));
messageDataNode.AppendChild(addChildNode(xmlDoc, "From", strFrom));
messageDataNode.AppendChild(addChildNode(xmlDoc, "MessagePlain", strMessagePlain));
messageDataNode.AppendChild(addChildNodeCDATA(xmlDoc, "MessageHTML", strMessageHTML)); // wrap with <![CDATA[]]>
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);
}
}
}
| Parameter | Example Value | Description | |
|---|---|---|---|
| EmailSubject | Test Email Subject | Subject field used in the email | |
| From | noreply | Sets the email sender's Friendly Name (seen by the email recipient) | |
| 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 |
Simpler formatting for Destinations parameter. For more options, refer to Optional MessageData Parameter Destinations section | |
| 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) | |
| TimeZone | New Zealand | Timezone specified using Windows timezone index value (default set using Web Dashboard can be overridden here). See Microsoft Timezones | |
| 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 | |
| MessageID | js82hn8n | Additional tracking ID for message tracking | |
| 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 | |
| Passthrough | Yes | Always use 'Yes' unless you need to enable Attachment Linking (ensure to include {{HREF}} in your MessagePlain and MessageHTML sections) |
|
MessageType=SMS,MessageData=
Content-Type="application/json; encoding='utf-8'"
{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageType": "sms",
"APIVersion": "1.01",
"MessageData" :
{
"Message": "Hello, this is a test message from Department01. Thank you.",
"Destinations" :
[
"6421000002"
]
}
}
Content-Type="application/json; encoding='utf-8'"
{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageType": "sms",
"APIVersion": "1.01",
"MessageID": "ID123456",
"MessageData" :
{
"Reference": "Test1",
"SendTime": "",
"TimeZone": "New Zealand",
"SubAccount": "SubAccount01",
"Department": "Department01",
"ChargeCode": "BillingGroup01",
"MessageID": "js82hn8n",
"SMSEmailReply": "person.one@domain.com",
"Message": "Hello, this is a test message from Department01. Thank you.",
"Destinations" :
[
{
"Recipient": "6421000001",
"Attention": "Recipient One",
"Company": "Example Corp",
"Custom1": "",
"Custom2": ""
},
"6421000002",
"6421000003",
"6421000004"
],
}
}
curl --request POST \
--url https://api.tnz.net.nz/api/json/send \
--header "Content-Type: application/json; encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageType": "sms",
"APIVersion": "1.01",
"MessageData" :
{
"Message": "Hello, this is a test message from Department01. Thank you.",
"Destinations" :
[
"6421000001"
]
}
}'
curl --request POST \
--url https://api.tnz.net.nz/api/json/send \
--header "Content-Type: application/json; encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageType": "sms",
"APIVersion": "1.01",
"MessageID": "ID123456",
"MessageData" :
{
"Reference": "Test1",
"SendTime": "",
"TimeZone": "New Zealand",
"SubAccount": "SubAccount01",
"Department": "Department01",
"ChargeCode": "BillingGroup01",
"MessageID": "js82hn8n",
"SMSEmailReply": "person.one@domain.com",
"Message": "Hello, this is a test message from Department01. Thank you.",
"Destinations" :
[
{
"Recipient": "6421000001",
"Attention": "Recipient One",
"Company": "Example Corp",
"Custom1": "",
"Custom2": ""
},
"6421000002",
"6421000003",
"6421000004"
]
}
}'
<?php
$data = array(
"Sender" => "application@domain.com",
"APIKey" => "ta8wr7ymd",
"MessageType" => "sms",
"APIVersion" => "1.01",
"MessageData" => array(
"Message" => "Hello, this is a test message from Department01. Thank you.",
"Destinations" => array(
"6421000001",
),
)
);
$options = array(
'http' => array(
'method' => 'POST',
'content' => json_encode($data),
'header' => "Content-Type: application/json; encoding='utf-8'\n"
)
);
$context = stream_context_create($options);
$result = file_get_contents("https://api.tnz.net.nz/api/json/send", false, $context);
header('Content-Type: application/json');
echo $result;
?>
<?php
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "sms";
$version = "1.01";
$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",
"MessageID" => "js82hn8n",
"SMSEmailReply" => "person.one@domain.com",
"Message" => "Hello, this is a test message from Department01. Thank you.",
"Destinations" => array(
array(
"Recipient" => "6421000001",
"Attention" => "Recipient One",
"Company" => "Example Corp",
"Custom1" => "",
"Custom2" => ""
),
"6421000002",
"6421000003",
"6421000004"
),
)
);
$options = array(
'http' => array(
'method' => 'POST',
'content' => json_encode($data),
'header' => "Content-Type: application/json; encoding='utf-8'\n"
)
);
$context = stream_context_create($options);
$result = file_get_contents("https://api.tnz.net.nz/api/json/send", false, $context);
header('Content-Type: application/json');
echo $result;
?>
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://api.tnz.net.nz/api/json/send";
string strJSONData = "{" +
"\"Sender\": \"application@domain.com\"," +
"\"APIKey\": \"ta8wr7ymd\"," +
"\"MessageType\":\"SMS\"," +
"\"APIVersion\":\"1.01\"," +
"\"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);
}
}
}
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://api.tnz.net.nz/api/json/send";
string strSender = "application@domain.com";
string strAPIKey = "ta8wr7ymd";
string strMessageType = "SMS";
string strAPIVersion = "1.01";
string strMessageID = "ID123456"; // optional
string strReference = "Test1";
string strSendTime = "";
string strTimeZone = "New Zealand";
string strSubAccount = "SubAccount01";
string strDepartment = "Department01";
string strChargeCode = "BillingGroup01";
string strMessageID = "js82hn8n";
string strSMSEmailReply = "person.one@domain.com";
string strMessage = addslashes("Hello, this is a test message from Department01. Thank you.");
string strRecipient = "6421000001";
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 + "\"," +
"\"MessageID\": \"" + strMessageID + "\"," +
"\"SMSEmailReply\":\"" + strSMSEmailReply + "\","+
"\"Message\": \"" + strMessage + "\"," + // escape special characters (ie. \r\n to \\r\\n)
"\"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);
}
}
}
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.01</APIVersion>
<MessageData>
<Message>Hello, this is a test message from Department01. Thank you.</Message>
<Destinations>6421000001</Destinations>
</MessageData>
</root>
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.01</APIVersion>
<MessageID>ID123456</MessageID>
<MessageData>
<Reference>Test1</Reference>
<SendTime></SendTime>
<TimeZone>New Zealand</TimeZone>
<SubAccount>SubAccount01</SubAccount>
<Department>Department01</Department>
<ChargeCode>BillingGroup01</ChargeCode>
<MessageID>js82hn8n</MessageID>
<SMSEmailReply>person.one@domain.com</SMSEmailReply>
<Message>Hello, this is a test message from Department01. Thank you.</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>
</MessageData>
</root>
curl --request POST \
--url https://api.tnz.net.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.01</APIVersion>
<MessageData>
<Message>Hello, this is a test message from Department01. Thank you.</Message>
<Destinations>6421000001</Destinations>
</MessageData>
</root>
'
curl --request POST \
--url https://api.tnz.net.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.01</APIVersion>
<MessageID>ID123456</MessageID>
<MessageData>
<Reference>Test1</Reference>
<SendTime></SendTime>
<TimeZone>New Zealand</TimeZone>
<SubAccount>SubAccount01</SubAccount>
<Department>Department01</Department>
<ChargeCode>BillingGroup01</ChargeCode>
<MessageID>js82hn8n</MessageID>
<SMSEmailReply>person.one@domain.com</SMSEmailReply>
<Message>Hello, this is a test message from Department01. Thank you.</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>
</MessageData>
</root>
'
<?php
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "SMS";
$version = "1.01";
$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");
$options = array(
'http' => array(
'method' => 'POST',
'content' => $data->asXML(),
'header' => "Content-Type: text/xml; encoding='utf-8'\n"
)
);
$context = stream_context_create($options);
$result = file_get_contents("https://api.tnz.net.nz/api/xml/send", false, $context);
header("Content-Type: text/xml; encoding='utf-8'");
echo $result;
?>
<?php
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "SMS";
$version = "1.01";
$message_id = "ID123456"; // optional
$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("MessageID","js82hn8n");
$data->MessageData->addChild("SMSEmailReply","person.one@domain.com");
$data->MessageData->addChild("Message","Hello, this is a test message from Department01. Thank you.");
$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");
$options = array(
'http' => array(
'method' => 'POST',
'content' => $data->asXML(),
'header' => "Content-Type: text/xml; encoding='utf-8'\n"
)
);
$context = stream_context_create($options);
$result = file_get_contents("https://api.tnz.net.nz/api/xml/send", false, $context);
header("Content-Type: text/xml; encoding='utf-8'");
echo $result;
?>
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://api.tnz.net.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.01"));
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);
}
}
}
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://api.tnz.net.nz/api/xml/send";
string strSender = "application@domain.com";
string strAPIKey = "ta8wr7ymd";
string strMessageType = "SMS";
string strAPIVersion = "1.01";
string strMessageID = "ID123456"; // optional
string strReference = "Test1";
string strSendTime = "";
string strTimeZone = "New Zealand";
string strSubAccount = "SubAccount01";
string strDepartment = "Department01";
string strChargeCode = "BillingGroup01";
string strMessageID = "js82hn8n";
string strSMSEmailReply = "person.one@domain.com";
string strMessage = "Hello, this is a test message from Department01. Thank you.";
string strRecipient = "6421000001";
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, "MessageID", strMessageID));
messageDataNode.AppendChild(addChildNode(xmlDoc, "SMSEmailReply", strSMSEmailReply));
messageDataNode.AppendChild(addChildNode(xmlDoc, "Message", strMessage));
messageDataNode.AppendChild(addChildNode(xmlDoc, "Destinations", strRecipient));
//
// 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);
}
}
}
| 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 |
Simpler formatting for Destinations parameter. For more options, refer to Optional MessageData Parameter Destinations section | |
| 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) | |
| TimeZone | New Zealand | Timezone specified using Windows timezone index value (default set using Web Dashboard can be overridden here). See Microsoft Timezones | |
| 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 | |
| MessageID | js82hn8n | Additional tracking ID for message tracking | |
| SMSEmailReply | person.one@domain.com | For email (SMTP) reply receipt notifications | |
| Destinations | > Recipient | 6421000001 | Recipient of the SMS in E.164 internationalised format |
| > Attention | Recipient One | Recipient's friendly name | |
| > Company | Example Corp | Recipient's company | |
| > Custom1 | Recipient One | Customisable field | |
| > Custom2 | Recipient One | Customisable field | |
MessageType=Fax,MessageData=
Content-Type="application/json; encoding='utf-8'"
{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageType": "Fax",
"APIVersion": "1.01",
"MessageData" :
{
"Destinations" :
[
"6495005001",
],
"Files":
[
{
"Name": "Sample.pdf",
"Data": "%%BASE-64 CONTENT%%"
}
]
}
}
Content-Type="application/json; encoding='utf-8'"
{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageType": "Fax",
"APIVersion": "1.01",
"MessageID": "ID123456",
"MessageData" :
{
"Reference": "Test1",
"SendTime": "",
"TimeZone": "New Zealand",
"SubAccount": "SubAccount01",
"Department": "Department01",
"ChargeCode": "BillingGroup01",
"Resolution": "high",
"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%%"
}
]
}
}
curl --request POST \
--url https://api.tnz.net.nz/api/json/send \
--header "Content-Type: application/json; encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageType": "Fax",
"APIVersion": "1.01",
"MessageData" :
{
"Destinations" :
[
"6495005001"
],
"Files":
[
{
"Name": "Sample.pdf",
"Data": "%%BASE-64 CONTENT%%"
}
]
}
}'
curl --request POST \
--url https://api.tnz.net.nz/api/json/send \
--header "Content-Type: application/json; encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageType": "Fax",
"APIVersion": "1.01",
"MessageID" : "ID123456",
"MessageData" :
{
"Reference": "Test1",
"SendTime": "",
"TimeZone": "New Zealand",
"SubAccount": "SubAccount01",
"Department": "Department01",
"ChargeCode": "BillingGroup01",
"Resolution": "high",
"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%%"
}
]
}
}'
<?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.01",
"MessageData" => array(
"Destinations" => array(
"6495005001"
),
"Files" => array(
array(
"Name" => $file1,
"Data" => base64_encode($file_content1)
)
),
)
);
$options = array(
'http' => array(
'method' => 'POST',
'content' => json_encode($data),
'header' => "Content-Type: application/json; encoding='utf-8'\n"
)
);
$context = stream_context_create($options);
$result = file_get_contents("https://api.tnz.net.nz/api/json/send", false, $context);
header('Content-Type: application/json');
echo $result;
?>
<?php
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "Fax";
$version = "1.01";
$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",
"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)
)
),
)
);
$options = array(
'http' => array(
'method' => 'POST',
'content' => json_encode($data),
'header' => "Content-Type: application/json; encoding='utf-8'\n"
)
);
$context = stream_context_create($options);
$result = file_get_contents("https://api.tnz.net.nz/api/json/send", false, $context);
header('Content-Type: application/json');
echo $result;
?>
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://api.tnz.net.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.01\"," + 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);
}
}
}
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://api.tnz.net.nz/api/json/send";
string strSender = "application@domain.com";
string strToken = "ta8wr7ymd";
string strMessageType = "Fax";
string strAPIVersion = "1.01";
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 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 +
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);
}
}
}
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.01</APIVersion>
<MessageData>
<Destinations>6495005001</Destinations>
<Files>
<Name>Sample.pdf</Name>
<Data>%%BASE-64 CONTENT%%</Data>
</Files>
</MessageData>
</root>
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.01</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>
<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>
curl --request POST \
--url https://api.tnz.net.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.01</APIVersion>
<MessageData>
<Destinations>6495005001</Destinations>
<Files>
<Name>Sample.pdf</Name>
<Data>%%BASE-64 CONTENT%%</Data>
</Files>
</MessageData>
</root>
'
curl --request POST \
--url https://api.tnz.net.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.01</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>
<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>
'
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.01");
$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));
}
$options = array(
'http' => array(
'method' => 'POST',
'content' => $data->asXML(),
'header' => "Content-Type: text/xml; encoding='utf-8'\n"
)
);
$context = stream_context_create($options);
$result = file_get_contents("https://api.tnz.net.nz/api/xml/send", false, $context);
header("Content-Type: text/xml; encoding='utf-8'");
echo $result;
?>
Content-Type="text/xml; encoding='utf-8'"
<?php
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "Fax";
$version = "1.01";
$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");
$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));
}
$options = array(
'http' => array(
'method' => 'POST',
'content' => $data->asXML(),
'header' => "Content-Type: text/xml; encoding='utf-8'\n"
)
);
$context = stream_context_create($options);
$result = file_get_contents("https://api.tnz.net.nz/api/xml/send", false, $context);
header("Content-Type: text/xml; encoding='utf-8'");
echo $result;
?>
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://api.tnz.net.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.01"));
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);
}
}
}
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://api.tnz.net.nz/api/xml/send";
string strMessageType = "Fax";
string strAPIVersion = "1.01";
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";
//
// 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, "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);
}
}
}
| Parameter | Example Value | Description | |
|---|---|---|---|
| Destinations | 6495005001 6495005002 6495005003 |
Simpler formatting for Destinations parameter. For more options, refer to Optional MessageData Parameter Destinations section | |
| Files | > Name | Sample.pdf | Fax document's filename |
| > Data | %%Base-64%% | Base-64 encoded value of the document | |
| 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) | |
| TimeZone | New Zealand | Timezone specified using Windows timezone index value (default set using Web Dashboard can be overridden here). See Microsoft Timezones | |
| 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 | |
| MessageID | js82hn8n | Additional tracking ID for message tracking | |
| 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) | |
| Destinations | > Recipient | 6495005000 | Recipient of the Fax in E.164 internationalised format |
| > 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,MessageData=
Content-Type="application/json; encoding='utf-8'"
{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageType": "TextToSpeech",
"APIVersion": "1.01",
"MessageData" :
{
"MessageToPeople": "Hello, this is a call from test. This is relevant information.",
"Destinations" :
[
"6495005001"
]
}
}
Content-Type="application/json; encoding='utf-8'"
{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageType": "TextToSpeech",
"APIVersion": "1.01",
"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",
"RouteNumber": "6498008000"
}
],
"CallRouteMessageToPeople": "Connecting you now.",
"CallRouteMessageToOperators": "Incoming Text To Speech call.",
"CallRouteMessageOnWrongKey": "Sorry, you have pressed an invalid key. Please try again.",
"NumberOfOperators": "5",
"Voice": "Female2",
"Options": "",
"Destinations" :
[
{
"Recipient": "6421000001",
"Custom1": "",
"Custom2": ""
},
"6495005002",
"6421000003"
]
}
}
curl --request POST \
--url https://api.tnz.net.nz/api/json/send \
--header "Content-Type: application/json; encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageType": "TextToSpeech",
"APIVersion": "1.01",
"MessageData" :
{
"MessageToPeople": "Hello, this is a call from test. This is relevant information.",
"Destinations" :
[
"6495005001"
]
}
}'
curl --request POST \
--url https://api.tnz.net.nz/api/json/send \
--header "Content-Type: application/json; encoding='utf-8'" \
--data '{
"Sender": "application@domain.com",
"APIKey": "ta8wr7ymd",
"MessageType": "TextToSpeech",
"APIVersion": "1.01",
"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",
"RouteNumber": "6498008000"
}
],
"CallRouteMessageToPeople": "Connecting you now.",
"CallRouteMessageToOperators": "Incoming Text To Speech call.",
"CallRouteMessageOnWrongKey": "Sorry, you have pressed an invalid key. Please try again.",
"NumberOfOperators": "5",
"Voice": "Female2",
"Options": "",
"Destinations" :
[
{
"Recipient": "6421000001",
"Custom1": "",
"Custom2": ""
},
"6495005002",
"6421000003"
]
}
}'
<?php
$data = array(
"Sender" => "application@domain.com",
"APIKey" => "ta8wr7ymd",
"MessageType" => "TextToSpeech",
"APIVersion" => "1.01",
"MessageData" => array(
"MessageToPeople" => "Hello, this is a call from test. This is relevant information.",
"Destinations" => array(
"6495005001"
),
)
);
$options = array(
'http' => array(
'method' => 'POST',
'content' => json_encode($data),
'header' => "Content-Type: application/json; encoding='utf-8'\n"
)
);
$context = stream_context_create($options);
$result = file_get_contents("https://api.tnz.net.nz/api/json/send", false, $context);
header('Content-Type: application/json');
echo $result;
?>
<?php
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "TextToSpeech";
$version = "1.01";
$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,
"RouteNumber" => "6498008000"
)
),
"CallRouteMessageToPeople" => "Connecting you now.",
"CallRouteMessageToOperators" => "Incoming Text To Speech call.",
"CallRouteMessageOnWrongKey" => "Sorry, you have pressed an invalid key. Please try again.",
"NumberOfOperators" => "5",
"Voice" => "Female2",
"Options" => "",
"Destinations" => array(
array(
"Recipient" => "6421000001",
"Custom1" => "",
"Custom2" => ""
),
"6495005002",
"6495005003"
),
)
);
$options = array(
'http' => array(
'method' => 'POST',
'content' => json_encode($data),
'header' => "Content-Type: application/json; encoding='utf-8'\n"
)
);
$context = stream_context_create($options);
$result = file_get_contents("https://api.tnz.net.nz/api/json/send", false, $context);
header('Content-Type: application/json');
echo $result;
?>
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 SendTextToSpeechJSON
{
public partial class frmMain : Form
{
public frmMain()
{
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 SendTextToSpeech()
{
string apiURL = "https://api.tnz.net.nz/api/json/send";
string strSender = "application@domain.com";
string strToken = "ta8wr7ymd";
string strMessageType = "TextToSpeech";
string strAPIVersion = "1.01";
string strMsgToPeople = "Hello, this is a call from test. This is relevant information.";
string strRecipient = "6421000001";
//
// Send TTS 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\": \"" + addslashes(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);
}
}
}
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 SendTextToSpeechJSON
{
public partial class frmMain : Form
{
public frmMain()
{
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 SendTextToSpeech()
{
string apiURL = "https://api.tnz.net.nz/api/json/send";
string strSender = "application@domain.com";
string strToken = "ta8wr7ymd";
string strMessageType = "TextToSpeech";
string strAPIVersion = "1.01";
string strMessageID = "ID123456"; // optional
string strReference = "Test1";
string strSendTime = "";
string strTimeZone = "New Zealand";
string strSubAccount = "SubAccount01";
string strDepartment = "Department01";
string strChargeCode = "BillingGroup01";
string strMsgToPeople = "Hello, this is a call from Department01. This is relevant information. Press one to be connected to our call centre.";
string strMsgToAnswerPhones = "Hello, sorry we missed you. This is a call from Department 01. Please contact us on 0800 123123.";
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 = "Connecting you now.";
string strCallRouteMsgToOperators = "Incoming Text To Speech call.";
string strCallRouteMsgOnWrongKey = "Sorry, you have pressed an invalid key. Please try again.";
string strNumberOfOperators = "5";
string strVoice = "Female2";
string strOptions = "";
string strRecipient = "6421000001";
//
// Send TTS 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\": \"" + addslashes(strMsgToPeople) + "\"," + EOL +
"\"MessageToAnswerphones\": \"" + addslashes(strMsgToAnswerPhones) + "\"," + EOL +
strKeypads +
"\"CallRouteMessageToPeople\": \"" + addslashes(strCallRouteMsgToPeople) + "\"," + EOL +
"\"CallRouteMessageToOperators\": \"" + addslashes(strCallRouteMsgToOperators) + "\"," + EOL +
"\"CallRouteMessageOnWrongKey\": \"" + addslashes(strCallRouteMsgOnWrongKey) + "\"," + EOL +
"\"NumberOfOperators\": \"" + strNumberOfOperators + "\"," + 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);
}
}
}
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.01</APIVersion>
<MessageData>
<MessageToPeople>Hello, this is a call from test. This is relevant information.</MessageToPeople>
<Destinations>6495005001</Destinations>
</MessageData>
</root>
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.01</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>
<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>
<Voice>Female2</Voice>
<Options></Options>
<Destinations>
<Recipient>6421000001</Recipient>
<Custom1></Custom1>
<Custom2></Custom2>
</Destinations>
<Destinations>6495005002</Destinations>
<Destinations>6421000003</Destinations>
</MessageData>
</root>
curl --request POST \
--url https://api.tnz.net.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.01</APIVersion>
<MessageData>
<MessageToPeople>Hello, this is a call from test. This is relevant information.</MessageToPeople>
<Destinations>6495005001</Destinations>
</MessageData>
</root>
'
curl --request POST \
--url https://api.tnz.net.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.01</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>
<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>
<Voice>Female2</Voice>
<Options></Options>
<Destinations>
<Recipient>6421000001</Recipient>
<Custom1></Custom1>
<Custom2></Custom2>
</Destinations>
<Destinations>6495005002</Destinations>
<Destinations>6421000003</Destinations>
</MessageData>
</root>
'
<?php
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "TextToSpeech";
$version = "1.01";
$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");
$options = array(
'http' => array(
'method' => 'POST',
'content' => $data->asXML(),
'header' => "Content-Type: text/xml; encoding='utf-8'\n"
)
);
$context = stream_context_create($options);
$result = file_get_contents("https://api.tnz.net.nz/api/xml/send", false, $context);
header("Content-Type: text/xml; encoding='utf-8'");
echo $result;
?>
<?php
$sender = "application@domain.com";
$apikey = "ta8wr7ymd";
$type = "TextToSpeech";
$version = "1.01";
$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("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("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");
$options = array(
'http' => array(
'method' => 'POST',
'content' => $data->asXML(),
'header' => "Content-Type: text/xml; encoding='utf-8'\n"
)
);
$context = stream_context_create($options);
$result = file_get_contents("https://api.tnz.net.nz/api/xml/send", false, $context);
header("Content-Type: text/xml; encoding='utf-8'");
echo $result;
?>
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 btnSendTextToSpeech_Click(object sender, EventArgs e)
{
//
// Populating values from frmMain
//
string apiURL = "https://api.tnz.net.nz/api/xml/send";
string strSender = "application@domain.com";
string strAPIKey = "ta8wr7ymd";
string strMessageType = "TextToSpeech";
string strAPIVersion = "1.01";
string strMsgToPeople = "Hello, this is a call from test. This is relevant information.";
string strRecipient = "6421000001";
//
// 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", 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);
}
}
}
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 btnSendTextToSpeech_Click(object sender, EventArgs e)
{
//
// Populating values from frmMain
//
string apiURL = "https://api.tnz.net.nz/api/xml/send";
string strSender = "application@domain.com";
string strAPIKey = "ta8wr7ymd";
string strMessageType = "TextToSpeech";
string strAPIVersion = "1.01";
string strMessageID = "ID123456"; // optional
string strReference = "Test1";
string strSendTime = "";
string strTimeZone = "New Zealand";
string strSubAccount = "SubAccount01";
string strDepartment = "Department01";
string strChargeCode = "BillingGroup01";
string strMsgToPeople = "Hello, this is a call from Department01. This is relevant information. Press one to be connected to our call centre.";
string strMsgToAnswerPhones = "Hello, sorry we missed you. This is a call from Department 01. Please contact us on 0800 123123.";
Dictionary<int, string> Keypads = new Dictionary<int, string>();
Keypads.Add(1, "64800123123");
Keypads.Add(2, "6498008000");
string strCallRouteMsgToPeople = "Connecting you now.";
string strCallRouteMsgToOperators = "Incoming Text To Speech call.";
string strCallRouteMsgOnWrongKey = "Sorry, you have pressed an invalid key. Please try again.";
string strNumberOfOperators = "5";
string strVoice = "Female2";
string strOptions = "";
string strRecipient = "6421000001";
//
// 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", 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, "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);
}
}
}
| 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 | |
| Destinations | 6495005001 6495005002 6495005003 |
Simpler formatting for Destinations parameter. For more options, refer to Optional MessageData Parameter Destinations section | |
| 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) | |
| TimeZone | New Zealand | Timezone specified using Windows timezone index value (default set using Web Dashboard can be overridden here). See Microsoft Timezones | |
| 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 | |
| MessageID | js82hn8n | Additional tracking ID for message tracking | |
| 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 | |
| Keypads | > Tone | 1 | Keypad for call connection (supports buttons 1-9) |
| > 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) | |
| Voice | Female2 | Text-to-Speech voice to use (Male1, Female1, Female2, Female3, Female4) | |
| Options | Customisable field | ||
| Destinations | > Recipient | 6495005000 | Recipient of the Fax in E.164 internationalised format |
| > Attention | Recipient One | Recipient's friendly name | |
| > Company | Example Corp | Recipient's company | |
| > Custom1 | Recipient One | Customisable field | |
| > Custom2 | Recipient One | Customisable field | |
Delivery Reports advise whether a message’s delivery was successful. If not, it will describe why. Delivery reports can be supplied via Webhook or SMTP Email, or accessed by logging into the Web 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.
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 | SMSReply | Type of Message ('Email', 'SMS', 'Fax', '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/2018 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 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 this transaction, charged by us to you |
| Detail | FaxPages:2 | Additional billing detail: "SMSParts", "FaxPages", "VoiceMinutes", "Size", "Prompts" |
A Webhook is preferred, however Delivery Reports can be emailed if desired (analytics reports are not sent via SMTP Email).
Please advise the email address to email these to.
The email address to receive SMS Reply reports can be specified on the original message submission using the SMSEmailReply parameter.
Whitelabelling of SMTP Email reports is available.
To resend or retry sending a message via the REST API, this will need to be submitted as a new, unique message.
To resend or retry sending a message via the Web Dashboard, once logged in and viewing an individual message, you will see Resubmit and Forward buttons.
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"
}
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.
"MessageType": "SMS",
"APIVersion": "1.02",
"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
If you wish to be notified when new versions of the API are released, you can register your email address here:
{{Name}} and {{HREF}} commands inside your MessagePlain and MessageHTML parameters. See the Attachment Linking and Passthrough guide for further information.