Flexi API Introduction
The Flexi API accepts a range of inputs and dynamically determines how to process your SMS message.
It is designed to be an ultra simple API integration specifically for SMS so that you can seamlessly redirect your existing endpoints into the TNZ network by simply changing the URL and Authorization header.
The Flexi API has been tested with Twilio, eTXT, mTXT, GroupText, MessageMedia, 3CX, Detrack and a range of other tools.
What are you connecting?
I’m using an existing SMS API that I want to point to TNZ
Your sending app already uses common SMS message fields.
You can point it to TNZ by changing the URL and adding the Authorization header.
{
"to": "+6421001234",
"body": "Your order is ready."
}
I’m using a third-party app and can't change the Webhook content
The app sends a fixed webhook with a bunch of values.
Point the webhook to TNZ, using custom HTTP headers to compose your SMS.
X-TNZ-Destination: [[phone_number]]
X-TNZ-Message: Hi [[name]], your [[product_name]] order [[order_number]] is ready.
Flexi API supports SMS only. For the full toolkit, see the REST API. For form-data HTTP POST or GET, see the HTTPS API.
Authentication
Register your account
If you don't have an account, head to https://www.tnz.co.nz/Customer/SignUp/ and register.
Create & Export Your API Auth Token
To use the API, an Auth Token is required in the Authorization HTTP header.
To export your Auth Token:
- Login to the TNZ Dashboard
- Navigate to 'Users'
- Create a new user or select an existing one
- Enable API access (if it's not already enabled)
- Click on the 'API' tab
- Enable 'Auth Token' and create a new Auth Token
- Click the ' Copy' button to copy it to your clipboard
- Paste the Auth Token into the Authorization Header in your application or code
At any time, you can refresh your Auth Token by clicking the button and exporting your new Auth Token. This action will invalidate any apps using your old Auth Token.
Auth Tokens can be used for multiple use-cases, with SubAccount and Department values helping in tracking reporting and billing.
API v3.00 utilizes JWT token Authentication. For OAuth2 authentication options, contact your TNZ representative.
JSON Body
For applications that send common JSON fields like "to" or "mobile" and "body" or "message".
API basics
This flexible API allows you to send multiple message types. For a brief overview of the API, see the TNZ API Structure guide.
The API URL:
https://flexiapi.tnz.co.nz/api/v3.00/flexi/sms
[Version]is the API Version ('v3.00')[MessageType]is the type of message (currently only 'sms' is supported)
The API HTTP Headers:
The HTTP Headers define the API call's formatting -
Content-Type: application/json
Accept: application/json
Authorization: Bearer [Auth Token]
** The 'Accept' header is optional but encouraged
You can find your Auth Token in the TNZ Dashboard.
The API Body:
The Body contains your message details.
The Flexi API is designed to be flexible! Input any parameters and the API will do its best to match and send your SMS.
{
"to": "+6421000001",
"body": "Hello, this is a test."
}
Send SMS
- Change your application's current SMS URL to the Flexi API URL.
- Add or edit the Authorization header to match TNZ's Auth Token.
- Send a test. If the test fails, advise TNZ Support (we'll check the API parameters received).
Request:
API URL: https://flexiapi.tnz.co.nz/api/v3.00/flexi/sms
HTTP Method: POST
HTTP Headers:
Content-Type: application/json
Accept: application/json
Authorization: Bearer [Your Auth Token]
{
"to": "+6421000001",
"body": "Hello, this is a test."
}
Response:
200 OK- Message Accepted400 BAD REQUEST- Invalid Variables401 Unauthorized- Invalid Auth Token500 Internal Server Error- API Server Fault
Examples
Flexible Parameters
Any of the examples listed below will be ingested by the API.
If variable names are mixed-and-matched, the API will attempt to identify possible variable names merge them into a known schema.
If you require different parameter names, Contact Us and we can review your requirements.
{
"to": "+6421000001",
"from": "+0000",
"body": "Hello, this is a test."
}
{
"to_number": "+6421000001",
"from_number": "+0000",
"message": "Hello, this is a test."
}
{
"mobile": "+6421000001",
"message": "Hello, this is a test."
}
{
"destination": "+6421000001",
"message": "Hello, this is a test."
}
{
"messages": [
{
"destination_number": "+6421000001",
"content": "Hello, this is a test."
}
]
}
{
"destination_number": "+6421000001",
"format": "SMS",
"content": "Hello, this is a test.",
"message_id": "877c19ef-fa2e-4cec-827a-e1df9b5509f7",
"callback_url": "https://www.example.com/webhook"
}
Parameter aliases
Aliases for To:
to |
tonumber |
to_number |
tosms |
to_sms |
tomobile |
to_mobile |
mobile |
mobilenumber |
mobile_number |
handset |
number |
destination |
destinationnumber |
destination_number |
destinationmobile |
recipient |
msisdn |
target |
contact |
receiver |
dst |
Aliases for From:
from |
fromnumber |
from_number |
fromsms |
from_sms |
frommobile |
from_mobile |
source |
sourcenumber |
source_number |
sourcemobile |
Aliases for Message:
message |
message_text |
messagetext |
text |
body |
sms |
content |
Aliases for MessageID:
messageid |
message_id |
message-id |
message_uuid |
message-uuid |
Sid |
MessageSid |
batch_id |
id |
Aliases for WebhookCallbackURL:
WebhookCallbackURL |
callback |
callback-url |
callback_url |
StatusCallback |
status_callback |
Status-Callback |
CallbackData |
notifyUrl |
webhookurl |
webhook_url |
webhook-url |
Fixed Webhook
For applications that send a fixed webhook.
API basics
When the event occurs in your application, it will send a webhook to the TNZ API. TNZ will receive the webhook, populate the [[values]] with data from the webhook, and send your SMS message.
API URL:
https://api.tnz.co.nz/api/v3.00/flexi/header
Use POST with Content-Type: application/json.
API HTTP Headers:
| Header | Example | Required | Explanation |
|---|---|---|---|
Authorization | Bearer [Auth Token] | Yes | See Your Auth Token for export instructions. |
X-TNZ-MessageType | SMS | Yes | Supports "SMS", "Email" and "TTS". |
X-TNZ-Message | Hi [[name]], your order [[order_number]] is [[status]]. | Yes | The SMS message. TNZ replaces the [[values]] with data from the webhook. |
X-TNZ-Destination | [[phone_number]] | Yes | The message recipient (mobile number or email address). |
X-TNZ-FromNumber | [[from]] | No | The sending SMS number. Omit this header to use the account default. Using an invalid value will cause TNZ to reject the request. |
API Body:
Not editable and managed by the application submitting the webhook event. The webhook will contain values which are mapped to the headers using [[values]].
See the placeholder rules for rules around nested fields, arrays and missing values.
Send SMS
- Configure a new webhook in your application.
- Set the webhook method to
POST - Enter the API URL above.
- Enter the HTTP headers as specified in the table above.
- Send a test.
Example request:
This illustrative delivery event uses a small JSON payload. Replace TEST_MOBILE with a mobile you control before testing. A valid request submits an SMS and normal charges apply.
API URL: https://api.tnz.co.nz/api/v3.00/flexi/header
HTTP Method: POST
HTTP Headers:
Content-Type: application/json
Authorization: Bearer [Your Auth Token]
X-TNZ-MessageType: SMS
X-TNZ-Message: Hi [[name]], your order [[order_number]] is [[status]]
X-TNZ-Destination: [[phone_number]]
{
"name": "John Doe",
"order_number": "ORD123",
"status": "completed",
"phone_number": "021001234",
"address": "123 Main Street",
"items": [
{
"description": "Apple",
"quantity": 10
},
{
"description": "Banana",
"quantity": 2
}
]
}
Rendered SMS:
To: 021001234
Hi John Doe, your order ORD123 is completed.
Response:
200 OK- Message Accepted400 BAD REQUEST- Invalid Variables. Check headers and placeholders.401 Unauthorized- Invalid Auth Token. Check Authorization header.403 FORBIDDEN- Insufficient Permissions. Check SMS permission and authorization for the requested sender.405 Method Not Allowed- Invalid Method. Check the webhook method is POST.415 Unsupported Media Type- Invalid Content-Type. Check the webhook is JSON.422 Unprocessable Entity- Invalid Content. Check the webhook schema is valid.500 Internal Server Error- API Server Fault
Examples
Use placeholders to personalise your SMS
A placeholder tells TNZ which detail to copy from the application's webhook into the SMS. For example [[order_number]].
When the webhook body is flat, this is quite simple:
Example: Flat Webhook Body
{
"name": "John Doe",
"order_number": "ORD123",
"status": "completed",
"phone_number": "021001234"
}
Valid placeholders for this webhook are:
[[name]][[order_number]][[status]][[phone_number]]
When the webhook body includes nested objects, use a dot to separate the field names:
Example: Nested Object Webhook Body
{
"name": "John Doe",
"order_data": {
"order_number": "ORD123",
"status": "completed"
},
"phone_number": "021001234"
}
Valid placeholders for this webhook are:
[[name]][[order_data.order_number]][[order_data.status]][[phone_number]]
When the webhook includes arrays, specify the index of the item to use:
Example: Array Webhook Body
{
"name": "John Doe",
"order_number": "ORD123",
"status": "completed",
"items": [
{
"quantity": 10,
"description": "Apple"
},
{
"quantity": 3,
"description": "Banana"
}
],
"phone_number": "021001234"
}
Valid placeholders for this webhook are:
[[name]][[order_number]][[status]][[phone_number]][[items[0].quantity]](First item's quantity)[[items[0].description]](First item's description)[[items[1].quantity]](Second item's quantity)[[items[1].description]](Second item's description)
Frequently Asked Questions
Can messages be sent internationally?
Yes, full international delivery is supported.
Is there a maximum request size?
The maximum request size supported is 20MB. This is our server side limitation. Your client side limitation may be smaller.
When I send SMS messages, the text is cut off at 160 characters. Why?
SMS messages are sent and charged in blocks of characters. One text message is 160 characters. By default, we will limit your message to three-message-parts in length (459 characters using the GSM character set, or 210 characters using Unicode/UCS-2). This can be increased on request. See the SMS Message Parts and Concatenated SMS guide for further information.
Is HTTPS, SSL, or TLS supported?
Yes, encrypted submissions are accepted across the API via HTTPS. SSL/TLS is also supported for outbound email messages provided the receiving email server supports this.