tnzapi
Documentation
The documentation for the TNZ API can be found here.
Versions
tnzapi
uses a modified version of Semantic Versioning for all changes. See this document for details.
Supported NodeJS Versions
This library supports the following NodeJS implementations:
Installation
Install from npm using npm, a
package manager for NodeJS.
npm i tnzapi
You may need to run the above commands with sudo
.
Getting Started
Getting started with the TNZ API couldn't be easier. Create a
Client
and you're ready to go.
API Credentials
The TNZAPI
needs your TNZ API credentials. You can either pass these
directly to the constructor (see the code below) or via environment variables.
const tnzapi = require('./tnzapi');
const client = tnzapi()
client.Sender = "user@example.com"
client.APIKey = "ABC123"
Send an Email
const tnzapi = require('tnzapi');
const client = new tnzapi({
"Sender": "user@example.com",
"APIKey": "ABC123"
});
var request = client.Send.Email({
"EmailSubject": "NodeJS Test",
"MessagePlain": "Test Email",
"Destinations": [{"Recipient":"recipient@example.com"}]
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
request.SendMessage(callback);
Send a SMS
const tnzapi = require('tnzapi');
const client = new tnzapi({
"Sender": "user@example.com",
"APIKey": "ABC123"
});
var request = client.Send.SMS({
"Reference": "Test",
"Message": "Test SMS Message click [[Reply]] to opt out",
"Destinations": [{"Recipient":"+64211231234"}]
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
request.SendMessage(callback);
Send a Fax Document
const tnzapi = require('tnzapi');
const client = new tnzapi({
"Sender": "user@example.com",
"APIKey": "ABC123"
});
var request = client.Send.Fax({
"Reference": "Test Fax",
"Destinations": [{"Recipient":"+6491232345"}]
});
request.AddAttachment("C:\\Document.pdf");
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
request.SendMessage(callback);
Make a Call - Text-to-Speech (TTS)
const tnzapi = require('./tnzapi');
const client = new tnzapi({
"Sender": "user@example.com",
"APIKey": "ABC123"
});
var request = client.Send.TTS({
"Reference": "Voice Test - 64211232345",
"MessageToPeople": "Hi there!",
"Destinations": [{"Recipient":"+64211232345"}]
});
request.AddKeypad(1,"+6499293000","You pressed 1");
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
request.SendMessage(callback);
Make a Call - Upload MP3 / Wav File
const tnzapi = require('tnzapi');
const client = new tnzapi({
"Sender": "user@example.com",
"APIKey": "ABC123"
});
var request = client.Send.Voice({
"Reference": "Voice Test - 64211232345",
"Destinations": [{"Recipient":"+64211232345"}]
});
request.AddVoiceFile("MessageToPeople","C:\\file1.wav");
request.AddVoiceFile("MessageToAnswerPhones","C:\\file2.wav");
request.AddKeypad(1,"+6491232345","C:\\file3.wav");
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
Getting help
If you need help installing or using the library, please check the TNZ Contact if you don't find an answer to your question.