Try the app2email WhatsApp API with an instant sandbox key and no account, then connect your own number, send your first template, follow its status and read the reply.
This guide takes you from nothing to a WhatsApp message and its answer, in two parts.
Part 1, the instant sandbox (about 2 minutes, no account): you get a key for a demo number, send a template to a pretend customer, watch it go from sent to read, and read the customer's answer. Nothing reaches WhatsApp, but every request and answer has the shape of the real API, so the same code works later.
Part 2, your own number: you sign up, connect your WhatsApp number, make an API key, and send the same kind of message to a real phone.
What the customer sees (Part 2): a WhatsApp message from your business name, for example "Hi Ava, your order #1234 has shipped." When they answer, you can reply with a normal text for the next 24 hours.
What you see: the send answer with a message_id, the status of that message (sent, delivered, read), the customer's answer as a message.received event, and every message in the app2email Activity Log and Inbox.
curl, or Node.js 18+, or Python 3.9+ with requests. Nothing else.| Scope | What it is for in this guide |
|---|---|
messages:send | Send the template and the reply (POST /messages) |
messages:read | List your templates (GET /templates), read a message's status (GET /messages/{message_id}) and fetch events (GET /events) |
webhooks:manage | Only if you want events pushed to your server (POST /webhooks) |
GET /me works with any valid key, whatever its scopes.
The instant sandbox is a demo WhatsApp number, 12025550100, with five pretend customers who react the way real ones do. You need no account and no key to start.
What it gives you:
POST https://api.app2email.com/v1/account/sandbox, with no key and no body, answers an instant sandbox key (a2es_...). It is shown once and is valid for 7 days. It works only on the demo number.sandbox_recipient.hello_world (en_US, UTILITY), order_update (en, UTILITY) and weekend_offer (en, MARKETING). They are checked by the same code as real templates.GET /me, GET /templates, POST /messages, GET /messages, GET /conversations, GET /conversations/{contact}, PUT /conversations/{contact}/owner, GET /events and POST /sandbox/inbound (makes a pretend customer write to you). Any other call answers 403 not_in_instant_sandbox.GET /events instead of a webhook.curl -X POST https://api.app2email.com/v1/account/sandboxconst res = await fetch("https://api.app2email.com/v1/account/sandbox", { method: "POST" });
const { instant_sandbox } = await res.json();
console.log(instant_sandbox.api_key, instant_sandbox.expires);import requests
res = requests.post("https://api.app2email.com/v1/account/sandbox", timeout=10)
sandbox = res.json()["instant_sandbox"]
print(sandbox["api_key"], sandbox["expires"])What you get back (shortened: the answer also lists the calls it has and the first calls to make, in calls and try_first):
{
"success": true,
"request_id": "s4ndb",
"instant_sandbox": {
"api_key": "a2es_000qlA9iTHS1NETB9JExample...",
"expires": "2026-11-22T03:00:00.000Z",
"number": "12025550100",
"base_url": "https://api.app2email.com/v1/12025550100",
"mcp_url": "https://api.app2email.com/mcp",
"authorization": "Authorization: Bearer <api_key>",
"test_contacts": [
{ "number": "12025550101", "name": "Ava", "behaviour": "answers every message a few seconds later" },
{ "number": "12025550102", "name": "Ben", "behaviour": "reads, never answers: a free-form message to him is 422 outside_24h_window" },
{ "number": "12025550103", "name": "Cara", "behaviour": "delivery fails: message.status failed and message.failed" },
{ "number": "12025550104", "name": "Dan", "behaviour": "answers STOP: contact.opted_out, then a marketing template to him is 403 recipient_opted_out" },
{ "number": "12025550105", "name": "Eve", "behaviour": "asks for a person: set the conversation's owner to human" }
],
"templates": ["hello_world (en_US, UTILITY)", "order_update (en, UTILITY)", "weekend_offer (en, MARKETING)"],
"not_here": "Webhooks (use GET /events), media uploads, contacts, broadcasts in the background, scheduled sends and every other call need a connected number: they answer 403 not_in_instant_sandbox here."
},
"next": "For a real WhatsApp number call create_account with the person's e-mail address: they confirm, connect their number and choose a plan.",
"documentation_url": "https://www.app2email.com/docs/api/sandbox"
}Keep api_key: it is not shown again. If you lose it, get a new one. Below, SANDBOX_KEY stands for it. A quick check that it works: GET https://api.app2email.com/v1/12025550100/me with Authorization: Bearer SANDBOX_KEY.
GET /templates lists every template with what values it needs and a complete example_request you can send after changing the values.
curl https://api.app2email.com/v1/12025550100/templates \
-H "Authorization: Bearer SANDBOX_KEY"const KEY = process.env.SANDBOX_KEY;
const API = "https://api.app2email.com/v1/12025550100";
const res = await fetch(`${API}/templates`, { headers: { Authorization: `Bearer ${KEY}` } });
const { templates } = await res.json();
for (const t of templates) console.log(t.name, t.language, t.status, t.needs);import os, requests
KEY = os.environ["SANDBOX_KEY"]
API = "https://api.app2email.com/v1/12025550100"
res = requests.get(f"{API}/templates", headers={"Authorization": f"Bearer {KEY}"}, timeout=10)
for t in res.json()["templates"]:
print(t["name"], t["language"], t["status"], t.get("needs"))Each entry has name, language, category, status, can_send, needs and, for approved templates, example_request. order_update needs two text values in its body: the customer's name and an order number.
Ava (12025550101) answers every message a few seconds later. A template is the message you can send any time, also to someone who has not written to you yet.
curl -X POST https://api.app2email.com/v1/12025550100/messages \
-H "Authorization: Bearer SANDBOX_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "12025550101",
"type": "template",
"template": {
"name": "order_update",
"language": { "code": "en" },
"components": [
{ "type": "body", "parameters": [
{ "type": "text", "text": "Ava" },
{ "type": "text", "text": "#1234" }
] }
]
}
}'const res = await fetch(`${API}/messages`, {
method: "POST",
headers: { Authorization: `Bearer ${KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({
to: "12025550101",
type: "template",
template: {
name: "order_update",
language: { code: "en" },
components: [
{ type: "body", parameters: [{ type: "text", text: "Ava" }, { type: "text", text: "#1234" }] },
],
},
}),
});
const sent = await res.json();
console.log(res.status, sent.message_id, sent.status);res = requests.post(
f"{API}/messages",
headers={"Authorization": f"Bearer {KEY}"},
json={
"to": "12025550101",
"type": "template",
"template": {
"name": "order_update",
"language": {"code": "en"},
"components": [
{"type": "body", "parameters": [{"type": "text", "text": "Ava"}, {"type": "text", "text": "#1234"}]}
],
},
},
timeout=10,
)
sent = res.json()
print(res.status_code, sent.get("message_id"), sent.get("status"))What you get back (HTTP 200, shortened): the message was accepted. text is the message as the customer sees it.
{
"success": true,
"request_id": "kxrkf",
"message_id": "wamid.HBgLNjE0MTIzNDU2NzgVAgARGBJTQU1QTEVfVEVTVF9FVkVOVAA=",
"status": "accepted",
"from": "12025550100",
"to": "12025550101",
"template": { "name": "order_update", "language": "en", "category": "UTILITY" },
"text": "Hi Ava, your order #1234 has shipped."
}A wrong value comes back as an error with a stable error.code, a how_to_fix and, for template mistakes, a complete correct example_request. Try it: leave out one parameter and you get 422 template_parameters_invalid.
GET /events?wait=25 waits up to 25 seconds for the next event, so you need no public address. You get message.status with sent, delivered and read, then message.received with Ava's answer.
curl "https://api.app2email.com/v1/12025550100/events?wait=25" \
-H "Authorization: Bearer SANDBOX_KEY"let after = "";
for (let i = 0; i < 5; i++) {
const q = after ? `&after=${encodeURIComponent(after)}` : "";
const res = await fetch(`${API}/events?wait=25${q}`, { headers: { Authorization: `Bearer ${KEY}` } });
const page = await res.json();
for (const e of page.events ?? []) console.log(e.type, e.data.status ?? e.data.text);
after = page.cursor ?? after;
}after = ""
for _ in range(5):
params = {"wait": 25, **({"after": after} if after else {})}
page = requests.get(f"{API}/events", params=params,
headers={"Authorization": f"Bearer {KEY}"}, timeout=40).json()
for e in page.get("events", []):
print(e["type"], e["data"].get("status") or e["data"].get("text"))
after = page.get("cursor", after)What you get back (shortened; Ava's words vary):
{
"success": true,
"request_id": "e7fd2",
"events": [
{
"id": "evt_Xq3k9m2Lw8Rt5Yp1Zs01",
"type": "message.status",
"created": "2026-11-15T03:10:02.000Z",
"number": "12025550100",
"data": {
"message_id": "wamid.HBgLNjE0MTIzNDU2NzgVAgARGBJTQU1QTEVfVEVTVF9FVkVOVAA=",
"to": "12025550101",
"status": "delivered",
"timestamp": "2026-11-15T03:10:01.000Z",
"sent_by": "api"
}
},
{
"id": "evt_Ab7c2d9Ef4Gh6Jk8Lm03",
"type": "message.received",
"created": "2026-11-15T03:10:09.000Z",
"number": "12025550100",
"data": {
"message_id": "wamid.HBgLNjE0MTIzNDU2NzgVAgASGBQzQUZCMTY0MDc2MUYwNzBDNTY5MAA=",
"from": "12025550101",
"name": "Ava",
"type": "text",
"text": "Thanks! When will it arrive?",
"timestamp": "2026-11-15T03:10:08.000Z"
}
}
],
"count": 2,
"cursor": "ec_184467",
"has_more": false
}Pass cursor as after on the next call to get only newer events. Each event is the same JSON a webhook gets later, with the same id. types=message.received gives only incoming messages. GET /messages lists the messages too, each sent one with its status and times.
Ava has just written, so her 24 hour window is open and you can send free text:
curl -X POST https://api.app2email.com/v1/12025550100/messages \
-H "Authorization: Bearer SANDBOX_KEY" \
-H "Content-Type: application/json" \
-d '{"to": "12025550101", "type": "text", "text": {"body": "It arrives on Friday."}}'The same text to Ben (12025550102), who never wrote, answers 422 outside_24h_window: outside the window only a template can be sent.
| Customer | Send them | What you learn |
|---|---|---|
Ben, 12025550102 | a text | He reads but never answers: 422 outside_24h_window for free text |
Cara, 12025550103 | hello_world | Delivery fails: message.status with failed, and message.failed |
Dan, 12025550104 | order_update, then weekend_offer | He answers STOP: contact.opted_out, then the marketing template is 403 recipient_opted_out |
Eve, 12025550105 | any template | She asks for a person: hand the chat over with PUT /conversations/{contact}/owner and "owner": "human" |
From an AI assistant instead of a terminal: the Management MCP server https://api.app2email.com/mcp/manage has the tool create_sandbox, and the instant key also works on the MCP server https://api.app2email.com/mcp (check_key, list_templates, send_template, list_events, wait_for_message ...). See Let an AI agent run your WhatsApp with MCP and Sandbox.
Meta's side decides whether messages actually go out: add a payment method to your WhatsApp Business Account, verify your business and get your display name approved. Getting started walks you through it.
On the API key page, create a key with messages:send and messages:read (add webhooks:manage if you want a webhook). The key (a2en_...) is shown once: keep it on your server, never in a web page or a log.
Tick Sandbox key when you create it to test on your own number first: every check runs against your account, nothing goes to WhatsApp, answers have "sandbox": true, message ids start with wamid.SANDBOX., and message.status events still arrive. Make a second key without the flag when you are ready to send for real.
In every request, YOUR_NUMBER is the WhatsApp number you send from: country code first, digits only.
curl https://api.app2email.com/v1/YOUR_NUMBER/me \
-H "Authorization: Bearer YOUR_API_KEY"const res = await fetch("https://api.app2email.com/v1/YOUR_NUMBER/me", {
headers: { Authorization: `Bearer ${process.env.API_KEY}` },
});
console.log(await res.json());import os, requests
res = requests.get("https://api.app2email.com/v1/YOUR_NUMBER/me",
headers={"Authorization": f"Bearer {os.environ['API_KEY']}"}, timeout=10)
print(res.json())What you get back:
{
"success": true,
"request_id": "a7k3p",
"key_valid": true,
"api_version": "v1",
"number": "4976659348270",
"plan": "standard_5000",
"service_status": "LIVE",
"key": { "name": "First message", "scopes": ["messages:read", "messages:send"], "ip_allow": "" },
"limits": { "max_numbers_per_request": 1000, "requests_per_second": 20, "burst": 50, "rate_limit_mode": "enforce", "webhooks_max": 5 }
}service_status must be LIVE, and key.scopes must list the scopes you need (or * for full access). A sandbox key also shows "sandbox": true.
GET /v1/YOUR_NUMBER/templates lists your templates. Pick one with "status": "APPROVED" and "can_send": true, and copy its example_request. No approved template yet? Create one on the Templates page of the dashboard, or see Send order and appointment notifications to create one through the API and get it approved.
Send the template to your own mobile number (not the business number itself: that answers 422 recipient_is_sender). Add an Idempotency-Key: if you retry after a timeout, the message is not sent twice.
curl -X POST https://api.app2email.com/v1/YOUR_NUMBER/messages \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: first-message-1" \
-d '{
"to": "61412345678",
"type": "template",
"template": {
"name": "order_update",
"language": { "code": "en" },
"components": [
{ "type": "body", "parameters": [
{ "type": "text", "text": "John" },
{ "type": "text", "text": "#1234" }
] }
]
}
}'const res = await fetch("https://api.app2email.com/v1/YOUR_NUMBER/messages", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.API_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": "first-message-1",
},
body: JSON.stringify({
to: "61412345678",
type: "template",
template: {
name: "order_update",
language: { code: "en" },
components: [
{ type: "body", parameters: [{ type: "text", text: "John" }, { type: "text", text: "#1234" }] },
],
},
}),
});
const sent = await res.json();
console.log(res.status, sent.message_id ?? sent.error);res = requests.post(
"https://api.app2email.com/v1/YOUR_NUMBER/messages",
headers={"Authorization": f"Bearer {os.environ['API_KEY']}", "Idempotency-Key": "first-message-1"},
json={
"to": "61412345678",
"type": "template",
"template": {
"name": "order_update",
"language": {"code": "en"},
"components": [
{"type": "body", "parameters": [{"type": "text", "text": "John"}, {"type": "text", "text": "#1234"}]}
],
},
},
timeout=10,
)
sent = res.json()
print(res.status_code, sent.get("message_id") or sent.get("error"))Use your own template's name, language and values (its example_request has them). What you get back (HTTP 200):
{
"success": true,
"request_id": "kxrkf",
"message_id": "wamid.HBgLNjE0MTIzNDU2NzgVAgARGBJTQU1QTEVfVEVTVF9FVkVOVAA=",
"status": "accepted",
"from": "4976659348270",
"to": "61412345678",
"template": { "name": "order_update", "language": "en", "category": "UTILITY" },
"text": "Hi John, your order #1234 has shipped.",
"conversation_url": "https://www.app2email.com/conversation/61412345678_4976659348270_...",
"note": "accepted by WhatsApp. delivery and read status appear in your app2email Activity Log (WhatsApp sent).",
"contacts": [{ "input": "61412345678", "wa_id": "61412345678" }]
}Add "dry_run": true to the body to check everything (template values, number, Do Not Call list, monthly limit) without sending. The answer shows the exact WhatsApp message. Nothing is sent, logged or counted.
GET /messages/{message_id} (scope messages:read) shows where the message is. URL-encode the id.
curl "https://api.app2email.com/v1/YOUR_NUMBER/messages/wamid.HBgLNjE0MTIzNDU2NzgVAgARGBJTQU1QTEVfVEVTVF9FVkVOVAA%3D" \
-H "Authorization: Bearer YOUR_API_KEY"What you get back: status is one of accepted, sent, delivered, read, failed, deleted, queued or unknown. Steps not reached yet are left out of times, and reply appears once the customer answers this message.
{
"success": true,
"request_id": "p4n8w",
"message_id": "wamid.HBgLNjE0MTIzNDU2NzgVAgARGBJTQU1QTEVfVEVTVF9FVkVOVAA=",
"to": "61412345678",
"status": "read",
"sent_by": "api",
"text": "Hi John, your order #1234 has shipped.",
"times": {
"submitted": "2026-11-06T01:00:00Z",
"accepted": "2026-11-06T01:00:01Z",
"sent": "2026-11-06T01:00:02Z",
"delivered": "2026-11-06T01:00:04Z",
"read": "2026-11-06T01:12:40Z"
},
"conversation_url": "https://www.app2email.com/conversation/61412345678_4976659348270_..."
}Answer the message on your phone. Two ways to get the answer in your code:
GET /v1/YOUR_NUMBER/events?wait=25&types=message.received, as in Part 1. On your own number the first call switches the event feed on, and events are kept from then on, for 72 hours. So call it once with after=now before you send, and keep the cursor.POST /v1/YOUR_NUMBER/webhooks and {"url": "https://your-server.example/webhook"} (scope webhooks:manage), or add it on the API key page under Webhooks. app2email then sends every event as a signed POST to your URL. Build a WhatsApp chatbot has a complete receiver with the signature check.The answer arrives as message.received:
{
"id": "evt_Xq3k9m2Lw8Rt5Yp1Zs01",
"type": "message.received",
"created": "2026-11-06T01:00:00.000Z",
"number": "4976659348270",
"data": {
"message_id": "wamid.HBgLNjE0MTIzNDU2NzgVAgARGBJTQU1QTEVfVEVTVF9FVkVOVAA=",
"from": "61412345678",
"name": "John",
"type": "text",
"text": "Thanks! When will it arrive?",
"conversation_url": "https://www.app2email.com/conversation/61412345678_4976659348270_SAMPLEk3XbQ9rTzP2mW",
"timestamp": "2026-11-06T01:00:00.000Z"
}
}You can now reply with "type": "text", exactly as in Part 1, until 24 hours after the customer's last message.
message.status events: sent, then delivered, then read when you open it. A failed message comes as message.status with status: "failed" and an error object, and also as message.failed.message.received, and the 24 hour window opens for free-form replies.Send each message once. Give every POST /messages an Idempotency-Key that is unique to that message, such as your order number and the event. The same request with the same key within 24 hours gets the first answer again, with the header Idempotent-Replayed: true. Same key with another body: 422 idempotency_key_reused.
Dedupe events by their id. An event can come again, from GET /events after a lost answer and from a webhook after a retry. Keep the ids you have handled for at least two days.
Check the webhook signature. Every webhook event has X-App2email-Signature: t=<unix seconds>,v1=<hex>: the HMAC-SHA256 of t, a dot and the raw body, with the webhook's secret (whsec_...) as the key. Refuse events that do not match or have an old t.
Respect the rate limit. Every answer has X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset. Over the limit you get 429 rate_limited with Retry-After: wait that long, then retry. To send one template to many numbers, put them in one call instead of one call each.
Templates outside the 24 hour window. Free text works only within 24 hours of the customer's last message (app2email stops 15 minutes early). Everything else needs an approved template.
Only message people who agreed. Marketing templates are not sent to numbers on your Do Not Call list, and a customer who writes STOP is added to it (contact.opted_out). Send a marketing broadcast that respects opt-ins covers consent.
Keep the key secret and small. A key on a server, never in a web page. Give it only the scopes it needs, and use a sandbox key for tests.
| What you see | Why | Fix |
|---|---|---|
429 from POST /v1/account/sandbox | More than 10 instant sandbox keys an hour from your address | Wait Retry-After seconds, or keep using the key you have (valid 7 days) |
401 missing_api_key, invalid_api_key, api_key_expired, api_key_revoked | No key, a wrong key, an expired one (an instant sandbox key lasts 7 days) or a revoked one | Send Authorization: Bearer YOUR_API_KEY with a current key; get a new instant key, or a key from the API key page |
403 api_key_number_mismatch | The key is for another number than the one in the URL | Put the key's own number in the URL. An instant sandbox key works only on 12025550100 |
400 invalid_number_in_url | The number in the URL is not digits with country code | Use the full number, digits only, no + |
403 not_in_instant_sandbox | The demo number does not have this call (webhooks, for one) | Use GET /events there, or a sandbox key on your own number |
422 sandbox_recipient | The instant sandbox writes only to its pretend customers | Send to 12025550101 to 12025550105 |
403 plan_not_allowed, service_not_live | No paid plan, or the service is paused | Choose a plan; a paused service goes live with "Go Live" on the Settings page |
403 insufficient_scope | The key lacks a permission (details.required_scope) | Make a key with messages:send and messages:read |
403 sandbox_key | A sandbox key cannot do this (templates, settings, approvals) | Use a key without the sandbox flag for that call |
404 template_not_found, template_language_not_found | The template's name or language is wrong | Copy both from GET /templates |
422 template_not_approved | Meta has not approved the template (yet) | Wait for approval, or pick one with can_send: true |
422 template_parameters_invalid, template_parameter_count_mismatch | Wrong number or kind of values | Fix them from details and the example_request in the error |
422 outside_24h_window | Free text to someone who has not written in the last 24 hours | Send an approved template |
422 recipient_is_sender | You sent to the business number itself | Send to another phone |
403 recipient_opted_out | The customer is on your Do Not Call list | Do not send them marketing |
403 whatsapp_payment_issue | No valid payment method on your WhatsApp Business Account (Meta error 131042) | Add one in WhatsApp Manager under Billing and payments |
429 rate_limited | Too many calls for this key | Wait Retry-After seconds, then retry |
GET /events stays empty on your own number | The feed starts at its first call | Call it once before you send (after=now), then send again |
Every answer has a request_id. GET /requests/{id} shows what was logged for it on your own number, and support@app2email.com can find it too. All codes: Errors.
Answer customers from your own code on a signed webhook, and hand over to a person.
Create a utility template, get it approved, and follow every delivery.
Connect Claude or another agent to your number with scoped keys and approvals.
The same calls from a no-code workflow, without writing a server.