KiwiTxt ← Back to KiwiTxt
KiwiTxt

API

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 start

Base URL
https://www.kiwitxt.co.nz/wp-json/kiwitxt/v1

Quick start

  1. Subscribe to KiwiTxt on the Silver plan. API access is included with Silver. Subscribe to Silver
  2. 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.
  3. Check your key works with GET /ping (it shows "authenticated": true) or GET /account.
  4. Send your first SMS with POST /sms:
bash
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:

http
Authorization: Bearer ktx_live_YOUR_API_KEY

If 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.

Keep your key secret. Only call the API from your server, never from a web page or mobile app where the key could be seen. If a key is exposed, contact KiwiTxt and we'll issue a new one straight away. The old key stops working as soon as the new one is created.

Send an SMS

POST/sms

FieldTypeRequiredDescription
tostringYesMobile number. Local (021 123 4567) or international (+64211234567) format.
messagestringYesThe 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_namestringNoSaves the recipient's first name on their contact.
last_namestringNoSaves the recipient's last name on their contact.
emailstringNoSaves the recipient's email on their contact.
referencestringNoYour own ID for this message (e.g. a booking number), up to 100 characters. Returned in responses.

Example request

json
{
  "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

json
{
  "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.

http
Idempotency-Key: booking-48213-reminder

Message 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 1601
161 to 3062
307 to 4593
460 to 6124
1,600 (maximum)11
Message length (with emoji or special characters)Segments billed
1 to 701
71 to 1342
135 to 2013

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.

bash
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.

StatusMeaning
queuedAccepted and handed to the network for sending.
pending / sentOn its way to the recipient's phone.
deliveredDelivered to the recipient's phone. Final.
undelivered / failedCould 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.

json
{
  "name": "Spine Clinic",
  "status": "active",
  "can_send": true,
  "credit_balance": 24.86,
  "country_code": "+64",
  "rate_limit": 60
}
FieldDescription
statusactive, paused (account paused for non-payment) or no_credit (top-up needed).
can_sendtrue if a send would be accepted now.
credit_balanceYour SMS credit balance in NZD.
country_codeCountry code added to numbers sent without one.
rate_limitMaximum 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:

json
{
  "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 id or reference of 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 2xx within 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 an id you have already processed. The X-KiwiTxt-Attempt header 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:

  1. Join the timestamp, a full stop and the raw request body: timestamp + "." + body.
  2. Compute an HMAC-SHA256 of that string using your signing secret, as lowercase hex.
  3. Compare sha256= plus your result with X-KiwiTxt-Signature. Reject the request if they differ, or if the timestamp is more than 5 minutes old.
php
$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:

json
{
  "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.

HTTPCodeWhat to do
401missing_api_keyAdd the Authorization header.
401invalid_api_keyCheck the key. Contact KiwiTxt if it was replaced.
402insufficient_creditTop up your credit, then retry.
402account_pausedAccount paused for non-payment. Pay the outstanding balance, then retry.
403account_disabledAPI access is turned off. Contact KiwiTxt.
403account_not_foundBilling account not linked. Contact KiwiTxt.
404not_foundNo message with that id on your account.
422missing_toAdd the "to" field.
422missing_messageAdd the "message" field.
422invalid_numberThe number isn't a valid mobile number. Don't retry.
422message_too_longShorten the message to 1,600 characters or fewer.
409request_in_progressThe same Idempotency-Key is still being sent. Wait a few seconds, then retry with the same key.
429rate_limitedToo many messages this minute. Wait the number of seconds in the Retry-After header, then retry.
502send_failedTemporary problem sending. Retry once after a short wait. If it fails again, contact KiwiTxt with the message id in the error.
503credit_check_failedTemporary problem. Retry shortly.
503account_not_configuredYour 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 4567 are converted to +64211234567 automatically. 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 402 errors (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 /sms sends a message. Send an Idempotency-Key header (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

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+)

javascript
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

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.

powershell
$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 $body

Support

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.

Subscribe to Silver