WhatsApp API for developers: send your first message in minutes
One endpoint, one header, one JSON body. This walkthrough starts with a test key that can't message anyone, so you can get the whole loop working before a single customer is involved.
You have a WhatsApp number connected to Avox, a terminal open, and about ten minutes. This is the WhatsApp API for developers walkthrough we'd want if we were you: no Meta access tokens, no phone number ids in the URL, and a test mode so your first experiments can't reach a real person.
Everything below comes from the Avox API docs. Where this post is shorter than the docs, the docs win.
WhatsApp API for developers: what you need first
- A WhatsApp number connected to Avox, and a plan that includes API access.
- Permission to create keys: an Admin, or a member given Manage API keys.
- Somewhere to keep a secret, such as an environment variable on a server. Never a browser page or a mobile app.
The shape of the API is simple. You send POST /api/messages/send with an Authorization: Bearer header. Each key belongs to exactly one connected number, which is why the URL needs no phone number id. The body is WhatsApp's own Cloud API message format: to, type, and one object named after the type.
Step 1: create a test key
In the dashboard open Settings > API Keys and click Create a key. Pick the number, choose Test key, keep Send messages switched on, name the key, and click Email me a code. Enter the 6-digit code from your email.
The full key appears once. Copy it before you click Done. A test key starts with avx_test_, a live key with avx_live_. Put it in your shell:
export AVOX_TEST_KEY="avx_test_your_key_here"
export AVOX_API_URL="paste the address shown on the API Keys tab"The API Keys tab prints the full address of the send endpoint, so use that as the base URL rather than trusting a blog post, including this one. You can also click Test next to the key: it confirms the key works and which number it sends from, without sending anything.
Step 2: send a message that goes nowhere
A test key runs every check a live key runs (the key, its number, your plan, rate limits, the body, idempotency) and then answers with a pretend result instead of sending.
curl -X POST "$AVOX_API_URL/api/messages/send" \
-H "Authorization: Bearer $AVOX_TEST_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 6f1d2c1e-8a4b-4c7e-9a51-3b0f2d9e7c10" \
-d '{
"to": "15551234567",
"type": "text",
"text": { "body": "Hello from Avox" }
}'to is the recipient's full international number, 7 to 15 digits. A leading +, spaces and dashes are stripped for you. The answer is a 200:
{
"ok": true,
"request_id": "req_3f9c2a7b1d4e5f60718293a4",
"message_id": "wamid.TEST8F3A1C0B9D2E4F5A6B7C8D9E0F1A2B3C",
"test": true,
"result": {
"messaging_product": "whatsapp",
"messages": [{ "id": "wamid.TEST8F3A1C0B9D2E4F5A6B7C8D9E0F1A2B3C", "message_status": "accepted" }]
}
}Three things to notice. ok is the first thing to branch on. test: true (and an Avox-Test-Mode: true header) tells you a test key answered. And the message_id starts with wamid.TEST, so it can never be confused with a real one. A real send carries a plain wamid. id, which every later status update repeats.
Step 3: the same call in Node
Node 18 or later has fetch built in:
import { randomUUID } from "node:crypto";
export async function sendText(to, body, idempotencyKey = randomUUID()) {
const res = await fetch(`${process.env.AVOX_API_URL}/api/messages/send`, {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.AVOX_TEST_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": idempotencyKey,
},
body: JSON.stringify({ to, type: "text", text: { body } }),
});
const data = await res.json();
if (data.ok === true) return data;
const retryAfter = res.headers.get("Retry-After");
const err = new Error(`${res.status} ${data.error.code}: ${data.error.message}`);
err.code = data.error.code;
err.retryAfter = retryAfter ? Number(retryAfter) : null;
err.requestId = data.error.request_id;
throw err;
}Branch on error.code, never on the message text. Codes don't change once published, and each links to an explanation on the docs' errors page. Log the request_id: you can paste it into API logs in the dashboard to find the exact request, and Support will ask for it.
Step 4: break it on purpose
Before you trust your error handling, trigger some errors. With a test key, a handful of numbers return specific failures:
This should return a 422 outside_messaging_window with "test": true, and nothing is sent:
curl -i -X POST "$AVOX_API_URL/api/messages/send" \
-H "Authorization: Bearer $AVOX_TEST_KEY" \
-H "Content-Type: application/json" \
-d '{"to":"+15550000002","type":"text","text":{"body":"test"}}'The body of a failed call looks like this:
{
"ok": false,
"error": {
"code": "outside_messaging_window",
"message": "It's been more than 24 hours since this person last messaged you. Send an approved template instead.",
"request_id": "req_9b2e5d7a1c4f80e36d2a7b15",
"meta_code": 131047
}
}+15550000001 gives invalid_recipient, +15550000005 gives meta_rate_limited with a Retry-After header, and +15550000006 gives template_not_found. The full list is on the testing page. Test sends never show up in your inbox and produce no delivery statuses, but they do appear in API logs with a Test badge.
Step 5: go live, and meet the 24-hour rule
Create a Live key, keep it in its own variable (AVOX_API_KEY), and send to a personal number you control, not the connected number itself.
Here's the rule that trips up most first live sends. Per Meta's documentation, a customer service window opens for 24 hours when a person messages you, and while it's open you can send free-form messages. When it closes, only approved template messages are allowed (as of October 2026; check the page). So for your first text, message the connected number from your phone first. For anyone else, send a template:
{
"to": "15551234567",
"type": "template",
"template": {
"name": "order_update",
"language": { "code": "en_US" },
"components": [
{ "type": "body", "parameters": [{ "type": "text", "text": "A-1042" }] }
]
}
}The template name and language must match an approved template exactly, or you'll get template_not_found. Our post on getting templates approved covers how.
A 200 also doesn't mean delivered. It means the message was handed to WhatsApp. Delivery statuses (sent, delivered, read, failed) arrive later with the same message_id, and you'll see them on the Logs page. To receive customer replies on your own server, read WhatsApp webhooks explained.
Habits worth having from day one
- Always send an
Idempotency-Key. If a request times out, retrying with the same key and the same body returns the first result instead of sending twice. Use an id from your own job, likeorder-1042-shipped. More in test keys and idempotency. - Respect
Retry-After. A429tells you how many seconds to wait. Don't retry validation errors in a loop; they count towards your limits too. See handling rate limits and errors. - One key per system. When one leaks, you revoke one key. Rotating a key lets the old one keep working for a grace period you choose.
- Keep the test key in CI. It exercises your real error paths without messaging anyone.
Questions people ask
Do I need Meta's access token or a phone number id?
No. Your server only holds an Avox key, and the Meta credentials stay inside Avox. The key already knows which number it sends from.
Can a key do more than send messages?
Yes, if you give it more permissions. With Read or Write for tables, rows, Flows, templates or automations it can use the builder API. No key can read your contacts, conversations or billing.
Why did my live send return 200 but nothing arrived?
WhatsApp can refuse a message after accepting it, for example when the window has closed. Check the Logs page for a failed status on that message_id.
Is there an official SDK?
The docs show curl, Node.js and Python examples using plain HTTP, so you don't need one. Don't assume packages that aren't in the docs.
Your next step: create the test key, run the first curl, then change the number to +15550000002 and watch it fail the way you'd want your code to handle.
- #whatsapp api for developers
- #send whatsapp message api
- #api keys
- #test keys
- #node js
- #curl
- #idempotency
Thanks for reading
How did this land?
Was this helpful?
Try it yourself
A code-first WhatsApp API for developers tutorial: create a test key, send a message with one POST, read the response and errors, then switch to a live key.
Follow Avox on Google
Pick Avox as a preferred source and Google shows our stories more often in Top Stories and its search results.