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 = new TNZAPI({
"AuthToken": "[Your Auth Token]"
});
...
Send Message
Send SMS/Email/Voice/Fax through tnzapi
library.
Send SMS:
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
"AuthToken": "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response: ",JSON.stringify(data, null, " "));
};
client.Messaging.SMS.SendMessage({
Reference: "Test",
Message: "Test SMS",
Destinations: [
{ Recipient: "+64211111111" },
{ Recipient: "+64222222222" }
]
}).then(callback);
Send Email:
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
"AuthToken": "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response: ",JSON.stringify(data, null, " "));
};
client.Messaging.Email.SendMessage({
FromEmail: "from@test.com",
EmailSubject: "Test Email",
MessagePlain: "Test Email Body",
Destinations: [
{ Recipient: "email.one@test.com" },
{ Recipient: "email.two@test.com" }
]
}).then(callback);
Send Fax:
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
"AuthToken": "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
};
client.Messaging.Fax.SendMessage({
Reference: "Test",
Destinations: [
{ Recipient:"+6491111111" },
{ Recipient:"+6492222222" }
],
Attachments: [
"D:/File1.pdf"
]
}).then(callback);
Make Call - Text-to-Speech (TTS):
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
"AuthToken": "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
client.Messaging.TTS.SendMessage({
MessageToPeople: "Hi there!",
Destinations: [
{ Recipient: "+6491111111" },
{ Recipient: "+6492222222" }
]
}).then(callback);
Make Call - Upload MP3 / Wav File:
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
"AuthToken": "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
};
client.Messaging.Voice.SendMessage({
Destinations: [
{ Recipient: "+6491111111" },
{ Recipient: "+6492222222" }
],
VoiceFiles: [
{
Name: "MessageToPeople",
File: "D:/File1.wav"
}
]
}).then(callback);
Reports
Retrieve your message status using tnzapi
library.
Reports - Get Message Status
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
AuthToken: "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
client.Reports.Status.Poll({
MessageID: "ID123456",
}).then(callback);
Reports - Get SMS Reply
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
AuthToken: "[Your Auth Token]"
});
request.Poll(callback);
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
client.Reports.SMSReply.Poll({
MessageID: "ID123456",
Page: 1
}).then(callback);
Reports - Get SMS Received List
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
AuthToken: "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
client.Reports.SMSReceived.Poll({
TimePeriod: 1440
RecordsPerPage: 10,
Page: 1
}).then(callback);
Actions
Amend your message using tnzapi
library.
Actions - Abort Pending/Delayed Job
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
AuthToken: "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
client.Actions.Abort.SendRequest({
MessageID: "ID123456"
}).then(callback);
Actions - Resubmit Failed Job
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
AuthToken: "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
client.Actions.Resubmit.SendRequest({
MessageID: "ID123456",
}).then(callback);
Actions - Reschedule DELAYED Job
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
AuthToken: "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
client.Actions.Reschedule.SendRequest({
MessageID: "ID123456",
SendTime: "2023-09-01T00:00"
}).then(callback);
Actions - Set Number of Operators on TTS/Voice Job
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
AuthToken: "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
client.Actions.Pacing.SendRequest({
MessageID: "ID123456",
NumberOfOperators: 1
}).then(callback);
Addressbook - Contacts
Manage your contacts using tnzapi
library.
Contacts - List
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
AuthToken: "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
client.Addressbook.Contact.List({
RecordsPerPage: 10,
Page: 1
}).then(callback);
Contacts - Detail
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
AuthToken: "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
client.Addressbook.Contact.Detail({
ContactID: "[Contact ID]"
}).then(callback);
Contacts - Create
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
AuthToken: "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
client.Addressbook.Contact.Create({
Title: "Mr",
Company: "TNZ Group",
FirstName: "First",
LastName: "Last",
MobilePhone: "+6421000001",
ViewBy: "Account",
EditBy: "Account"
}).then(callback);
Contacts - Update
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
AuthToken: "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
client.Addressbook.Contact.Update({
ContactID: "[Contact ID]",
Attention: "Test Attention"
Title: "Mr",
Company: "TNZ Group",
FirstName: "First",
LastName: "Last",
MobilePhone: "+64212223333",
ViewPublic: "Account",
EditPublid: "Account"
}).then(callback);
Contacts - Delete
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
AuthToken: "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
client.Addressbook.Contact.Delete({
ContactID: "[Contact ID]"
}).then(callback);
Addressbook - Contact Group
Manage your contact group relationship using tnzapi
library.
Contact Group - List
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
AuthToken: "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
client.Addressbook.ContactGroup.List({
ContactID: "[Contact ID]",
RecordsPerPage: 10,
Page: 1
}).then(callback);
Contact Group - Detail
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
AuthToken: "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
client.Addressbook.ContactGroup.Detail({
ContactID: "[Contact ID]",
GroupCode: "[Group Code]"
}).then(callback);
Contact Group - Create
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
AuthToken: "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
client.Addressbook.ContactGroup.Create({
ContactID: "[Contact ID]",
GroupCode: "[Group Code]"
}).then(callback);
Contact Group - Delete
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
AuthToken: "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
client.Addressbook.ContactGroup.Delete({
ContactID: "[Contact ID]",
GroupCode: "[Group Code]"
}).then(callback);
Addressbook - Group
Manage your group using tnzapi
library.
Group - List
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
AuthToken: "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
client.Addressbook.Group.List({
RecordsPerPage: 10,
Page: 1
}).then(callback);
Group - Detail
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
AuthToken: "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
client.Addressbook.Group.Detail({
GroupCode: "[Group Code]"
}).then(callback);
Group - Create
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
AuthToken: "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
client.Addressbook.Group.Create({
GroupName: "Test Group",
ViewEditBy: "Account"
}).then(callback);
Group - Update
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
AuthToken: "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
client.Addressbook.Group.Update({
GroupCode: "[Group Code]",
GroupName: "Test Group 123",
SubAccount: "Test",
ViewEditBy: "Account"
}).then(callback);
Group - Delete
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
AuthToken: "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
client.Addressbook.Group.Delete({
GroupCode: "[Group Code]"
}).then(callback);
Addressbook - Group Contact
Manage your group contact relationship using tnzapi
library.
Group Contact - List
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
AuthToken: "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
client.Addressbook.GroupContact.List({
GroupCode: "[Group Code]",
RecordsPerPage: 10,
Page: 1
}).then(callback);
Group Contact - Detail
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
AuthToken: "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
client.Addressbook.ContactGroup.Create({
ContactID: "[Contact ID]",
GroupCode: "[Group Code]"
}).then(callback);
Group Contact - Create
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
AuthToken: "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
client.Addressbook.GroupContact.Create({
GroupCode: "[Group Code]",
ContactID: "[Contact ID]"
}).then(callback);
Group Contact - Delete
const TNZAPI = require('tnzapi');
const client = new TNZAPI({
AuthToken: "[Your Auth Token]"
});
var callback = function(data) {
console.log("Response:",JSON.stringify(data, null, " "));
}
client.Addressbook.GroupContact.Delete({
GroupCode: "[Group Code]",
ContactID: "[Contact ID]"
}).then(callback);
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.