Send SMS from your own software
The KiwiTxt API lets your booking system, CRM, practice software or website send SMS with one HTTPS request. Every message, and every reply, also appears in your KiwiTxt Conversations inbox so your team can carry on the conversation there.
Subscribe to Silver Read the quick startBase URL
https://www.kiwitxt.co.nz/wp-json/kiwitxt/v1
Quick start
- Subscribe to KiwiTxt on the Silver plan. API access is included with Silver. Subscribe to Silver
- Once you're subscribed, KiwiTxt sets up your account and sends you an API key. It starts with
ktx_live_and is only shown once, so store it securely. - Check your key works with
GET /ping(it shows"authenticated": true) orGET /account. - Send your first SMS with
POST /sms:
curl -X POST https://www.kiwitxt.co.nz/wp-json/kiwitxt/v1/sms \
-H "Authorization: Bearer ktx_live_YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: booking-889-reminder" \
-d '{"to": "021 123 4567", "message": "Hi Sam, your appointment is tomorrow at 10am. Reply STOP to opt out."}'On Windows, use the PowerShell example instead. Windows PowerShell changes the quotes inside curl commands, which breaks the request.
Authentication
Send your API key with every request in the Authorization header:
Authorization: Bearer ktx_live_YOUR_API_KEYIf your software can't set an Authorization header, use X-API-Key: ktx_live_YOUR_API_KEY instead.
To test your connection and key without sending anything, call GET https://www.kiwitxt.co.nz/wp-json/kiwitxt/v1/ping with your key. The response includes "authenticated": true when the key is valid.
Send an SMS
POST/sms
| Field | Type | Required | Description |
|---|---|---|---|
to | string | Yes | Mobile number. Local (021 123 4567) or international (+64211234567) format. |
message | string | Yes | The SMS text, up to 1,600 characters. Messages over 160 characters are sent as one message and billed per segment (see Message length and billing). |
first_name | string | No | Saves the recipient's first name on their contact. |
last_name | string | No | Saves the recipient's last name on their contact. |
email | string | No | Saves the recipient's email on their contact. |
reference | string | No | Your own ID for this message (e.g. a booking number), up to 100 characters. Returned in responses. |
Example request
{
"to": "021 123 4567",
"message": "Hi Sam, your appointment is tomorrow at 10am. Reply YES to confirm or STOP to opt out.",
"first_name": "Sam",
"reference": "booking-889"
}Response: 201 Created
{
"id": 1042,
"status": "queued",
"to": "+64211234567",
"message": "Hi Sam, your appointment is tomorrow at 10am. Reply YES to confirm or STOP to opt out.",
"reference": "booking-889",
"error": null,
"created_at": "2026-11-25T01:15:02+00:00",
"updated_at": "2026-11-25T01:15:03+00:00"
}Save the id if you want to check delivery later. If the recipient isn't already a contact, they are added automatically.
Retrying safely (recommended)
Add an Idempotency-Key header with a unique value for each message, such as your booking or order ID. If a request times out and you send it again with the same key within 24 hours, the message is not sent twice: you get the original message back (status 201) with an Idempotent-Replayed: true header. If the first attempt failed, the retry sends normally.
Idempotency-Key: booking-48213-reminderMessage length and billing
You can send up to 1,600 characters in one request. The recipient receives it as one message, but SMS is billed in segments, so longer messages cost more.
- A message of up to 160 characters is 1 segment.
- Over 160 characters, each segment holds 153 characters. The other 7 are used by the phone to join the parts back together.
- If the message contains any emoji or special characters (for example ’ “ ” or non-English letters), the whole message uses the smaller limits: 70 characters for 1 segment, then 67 per segment.
| Message length (standard characters) | Segments billed |
|---|---|
| 1 to 160 | 1 |
| 161 to 306 | 2 |
| 307 to 459 | 3 |
| 460 to 612 | 4 |
| 1,600 (maximum) | 11 |
| Message length (with emoji or special characters) | Segments billed |
|---|---|
| 1 to 70 | 1 |
| 71 to 134 | 2 |
| 135 to 201 | 3 |
Example: a 300-character reminder is sent as one message and billed as 2 segments. The same message with one emoji is billed as 5 segments. Tip: use straight quotes (' ") rather than curly ones, and avoid emoji, to keep costs down.
Check message status
GET/sms/{id}
{id} is the id returned when you sent the message.
curl https://www.kiwitxt.co.nz/wp-json/kiwitxt/v1/sms/1042 \
-H "Authorization: Bearer ktx_live_YOUR_API_KEY"The response has the same shape as the send response, with the latest status.
| Status | Meaning |
|---|---|
queued | Accepted and handed to the network for sending. |
pending / sent | On its way to the recipient's phone. |
delivered | Delivered to the recipient's phone. Final. |
undelivered / failed | Could not be delivered, e.g. the number is switched off or not in service. Final. |
You can only look up messages sent with your own API key. Please don't check status more than once every 30 seconds per message.
Check your account
GET/account
Confirms your key works and whether you can send right now. It's a good health check to run when your software starts.
{
"name": "Spine Clinic",
"status": "active",
"can_send": true,
"credit_balance": 24.86,
"country_code": "+64",
"rate_limit": 60
}| Field | Description |
|---|---|
status | active, paused (account paused for non-payment) or no_credit (top-up needed). |
can_send | true if a send would be accepted now. |
credit_balance | Your SMS credit balance in NZD. |
country_code | Country code added to numbers sent without one. |
rate_limit | Maximum messages you can send per minute. |
Receiving replies
Replies always appear in your KiwiTxt Conversations inbox. If you also want replies sent to your own software, give KiwiTxt a webhook URL (an HTTPS address on your server). We'll then POST each reply to it:
{
"event": "sms.received",
"id": 1043,
"from": "+64211234567",
"message": "YES",
"first_name": "Sam",
"last_name": null,
"received_at": "2026-11-25T01:17:40+00:00"
}Respond with any 2xx status within 10 seconds to confirm receipt.
- Which replies you get: every SMS reply to your KiwiTxt number, including replies to messages you sent from your Conversations inbox, not only replies to API messages.
- Matching a reply to your message: replies don't include the
idorreferenceof the message being answered. Match them on the sender's number (from), e.g. to the latest message you sent that number. - If your server is down: if it doesn't answer with a
2xxwithin 10 seconds, we try again after about 1 minute, 5 minutes, 15 minutes, 1 hour and 3 hours (6 attempts in total). The reply is always kept in your Conversations inbox either way. - Duplicates: because of retries, the same reply can occasionally arrive twice (for example if your server saved it but answered too slowly). Every attempt has the same
id, so ignore anidyou have already processed. TheX-KiwiTxt-Attemptheader shows the attempt number.
Authenticating webhooks on your side
If your endpoint needs its own authentication, send us the header it expects, for example Authorization: Bearer <your token> or X-Api-Key: <your key>. We add it to every reply webhook (including retries), store it encrypted, and never follow redirects when it's set, so use the final URL of your endpoint. Every webhook is also signed as below, so you can use either check, or both.
Verify the reply came from KiwiTxt
Each webhook carries two headers: X-KiwiTxt-Timestamp and X-KiwiTxt-Signature. KiwiTxt gives you a signing secret (starts with whsec_). To verify a webhook:
- Join the timestamp, a full stop and the raw request body:
timestamp + "." + body. - Compute an HMAC-SHA256 of that string using your signing secret, as lowercase hex.
- Compare
sha256=plus your result withX-KiwiTxt-Signature. Reject the request if they differ, or if the timestamp is more than 5 minutes old.
$body = file_get_contents('php://input');
$timestamp = $_SERVER['HTTP_X_KIWITXT_TIMESTAMP'] ?? '';
$signature = $_SERVER['HTTP_X_KIWITXT_SIGNATURE'] ?? '';
$expected = 'sha256=' . hash_hmac('sha256', $timestamp . '.' . $body, 'whsec_YOUR_SIGNING_SECRET');
if (!hash_equals($expected, $signature) || abs(time() - (int) $timestamp) > 300) {
http_response_code(401);
exit;
}
$reply = json_decode($body, true);Errors
Errors return a non-2xx HTTP status and this body:
{
"code": "insufficient_credit",
"message": "Not enough SMS credit. Please top up to keep sending.",
"data": { "status": 402 }
}Use code in your software's logic. message is written to be shown to staff.
| HTTP | Code | What to do |
|---|---|---|
| 401 | missing_api_key | Add the Authorization header. |
| 401 | invalid_api_key | Check the key. Contact KiwiTxt if it was replaced. |
| 402 | insufficient_credit | Top up your credit, then retry. |
| 402 | account_paused | Account paused for non-payment. Pay the outstanding balance, then retry. |
| 403 | account_disabled | API access is turned off. Contact KiwiTxt. |
| 403 | account_not_found | Billing account not linked. Contact KiwiTxt. |
| 404 | not_found | No message with that id on your account. |
| 422 | missing_to | Add the "to" field. |
| 422 | missing_message | Add the "message" field. |
| 422 | invalid_number | The number isn't a valid mobile number. Don't retry. |
| 422 | message_too_long | Shorten the message to 1,600 characters or fewer. |
| 409 | request_in_progress | The same Idempotency-Key is still being sent. Wait a few seconds, then retry with the same key. |
| 429 | rate_limited | Too many messages this minute. Wait the number of seconds in the Retry-After header, then retry. |
| 502 | send_failed | Temporary problem sending. Retry once after a short wait. If it fails again, contact KiwiTxt with the message id in the error. |
| 503 | credit_check_failed | Temporary problem. Retry shortly. |
| 503 | account_not_configured | Your account setup isn't finished. Contact KiwiTxt. |
Only retry 409, 429, 502 and 503 errors, and send the same Idempotency-Key when you do. Retrying the others will fail the same way.
Numbers, limits and good practice
- Phone numbers: local NZ numbers like
021 123 4567are converted to+64211234567automatically. For overseas numbers, include the country code (e.g.+61412345678). Spaces, dashes and brackets are fine. - Message length: up to 1,600 characters per message, billed per segment of 160 characters (153 each once a message is longer than 160). See Message length and billing.
- Rate limit: 60 messages per minute by default. Ask KiwiTxt if you need more.
- Credit: sends are refused when your account is out of credit or paused, so your software should handle
402errors (see Errors). - Opt-outs: NZ anti-spam law requires marketing messages to name your business and offer an opt-out, e.g. "Reply STOP to opt out". Contacts who reply STOP are not sent further messages.
- Duplicates: each successful
POST /smssends a message. Send anIdempotency-Keyheader (see Send an SMS) so a retried request never sends the message twice. Allow up to 30 seconds before treating a request as timed out.
Code examples
Replace ktx_live_YOUR_API_KEY with your key, and use your own unique ID (such as the order or booking number) for Idempotency-Key so a retried request is never sent twice.
PHP
$ch = curl_init('https://www.kiwitxt.co.nz/wp-json/kiwitxt/v1/sms');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ktx_live_YOUR_API_KEY',
'Content-Type: application/json',
'Idempotency-Key: order-1042', // Same key on a retry = never sent twice
],
CURLOPT_TIMEOUT => 30,
CURLOPT_POSTFIELDS => json_encode([
'to' => '021 123 4567',
'message' => 'Your order is ready to collect.',
]),
]);
$result = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE); // 201 = accepted
if ($status !== 201) {
error_log($result['code'] . ': ' . $result['message']);
}JavaScript (Node.js 18+)
const res = await fetch('https://www.kiwitxt.co.nz/wp-json/kiwitxt/v1/sms', {
method: 'POST',
headers: {
'Authorization': 'Bearer ktx_live_YOUR_API_KEY',
'Content-Type': 'application/json',
'Idempotency-Key': 'order-1042', // Same key on a retry = never sent twice
},
body: JSON.stringify({ to: '021 123 4567', message: 'Your order is ready to collect.' }),
});
const data = await res.json();
if (!res.ok) console.error(data.code, data.message);Python
import requests
r = requests.post(
"https://www.kiwitxt.co.nz/wp-json/kiwitxt/v1/sms",
headers={
"Authorization": "Bearer ktx_live_YOUR_API_KEY",
"Idempotency-Key": "order-1042", # Same key on a retry = never sent twice
},
json={"to": "021 123 4567", "message": "Your order is ready to collect."},
timeout=30,
)
if not r.ok:
print(r.json()["code"], r.json()["message"])Windows PowerShell
Use Invoke-RestMethod on Windows. Windows PowerShell changes the quotes inside curl commands, which breaks the JSON.
$key = "ktx_live_YOUR_API_KEY"
$body = @{ to = "021 123 4567"; message = "Your order is ready to collect." } | ConvertTo-Json
Invoke-RestMethod -Method Post -Uri "https://www.kiwitxt.co.nz/wp-json/kiwitxt/v1/sms" `
-Headers @{ Authorization = "Bearer $key"; "Idempotency-Key" = "order-1042" } `
-ContentType "application/json" -Body $bodySupport
Email info@kiwitxt.co.nz for help, a new API key or to set up reply webhooks. If a send fails, include the message id from the error so we can trace it quickly.