DEVELOPER DOCUMENTATION
Afojet WhatsApp API
Connect your website, app, CRM or billing software to WhatsApp. Send order updates, OTPs, reminders and payment links, keep your contacts in sync, and get every customer reply and delivery receipt on your own server — using the official WhatsApp Business (Cloud) API through your Afojet account.
- Simple REST + JSON API with one API key — no Meta app or token handling on your side.
- Messages are charged to your prepaid Afojet wallet at the same prices as the inbox.
- Everything you send through the API also appears in your team’s Live Chat, marked “API”.
- Signed webhooks for incoming messages, delivery / read receipts, payments and leads.
Getting started
- Create an Afojet account (free) and open WhatsApp API → Get WhatsApp API.
- Connect your WhatsApp number with Facebook (Embedded Signup — about 5 minutes).
- Top up your wallet and create at least one approved message template (needed to start conversations).
- Go to Inbox → Developers → API keys and create a key. Copy it — it is shown only once.
- Call the API from your server. Keep the key secret: never put it in a web page or mobile app.
bashcurl https://www.afojet.com/api/v1/whatsapp/account \
-H "Authorization: Bearer afo_wa_YOUR_KEY"Authentication
| Item | Details |
|---|---|
| Base URL | https://www.afojet.com/api/v1/whatsapp |
| Auth header | Authorization: Bearer afo_wa_… (or X-API-Key: afo_wa_…) |
| Format | JSON requests and responses (UTF-8). Send Content-Type: application/json with a body. |
| Phone numbers | Country code + number, digits only: 919876543210. 10-digit Indian mobiles also work. |
| Rate limit | 120 requests per minute per key (429 when exceeded). |
| Keys | Up to 10 per account; only the account owner can create or delete them. Each request is listed in Inbox → Developers → Request log for 30 days. |
Account
GET/account — your connected WhatsApp number and wallet balance.
json{
"number": { "phone": "+91 98765 43210", "name": "Your Business", "phone_number_id": "1234567890", "status": "registered" },
"wallet": { "balance": 482.5, "currency": "INR" }
}Templates
GET/templates?status=approved — your message templates and exactly what each one needs when you send it.
json{
"templates": [{
"name": "order_update", "language": "en", "status": "approved", "category": "utility",
"body": "Hi {{1}}, your order {{2}} has been shipped.",
"header": null, "footer": "Thank you", "buttons": [{ "index": 0, "type": "url", "text": "Track", "url": "https://shop.example/track/{{1}}" }],
"needs": { "params": ["1", "2"], "header": [], "media": null, "buttons": [{ "index": 0, "type": "url" }], "code": false }
}]
}Create templates in Inbox → Templates. Meta reviews them (usually minutes).
Send messages
POST/messages
Template message
bashcurl -X POST https://www.afojet.com/api/v1/whatsapp/messages \
-H "Authorization: Bearer afo_wa_YOUR_KEY" -H "Content-Type: application/json" \
-d '{
"to": "919876543210",
"template": "order_update",
"language": "en",
"params": ["Ravi", "#1024"],
"buttons": { "0": "1024" },
"name": "Ravi Patel"
}'| Field | Description |
|---|---|
to | Required. Customer number with country code. |
template | Template name. language is optional when the name is unique. |
params | Body variables: a list for {{1}}, {{2}} or an object for named variables, e.g. {"first_name":"Ravi"}. |
header_params | Variables in a text header. |
media | Public https link to the image / video / PDF for a media header. |
buttons | Dynamic link endings or coupon codes by button index: {"0":"order/1024"}. |
code | The one-time code, for authentication (OTP) templates. |
name | Optional — saved on the contact. |
json201 Created
{ "id": "wamid.HBgMOTE5ODc2NTQzMjEwFQIAERgS…", "to": "919876543210", "type": "template",
"category": "utility", "status": "accepted", "cost": 0.2, "currency": "INR" }Text reply (within 24 hours)
bashcurl -X POST https://www.afojet.com/api/v1/whatsapp/messages \
-H "Authorization: Bearer afo_wa_YOUR_KEY" -H "Content-Type: application/json" \
-d '{"to":"919876543210","text":"Your order has shipped 🚚"}'Marketing templates are not sent to contacts who replied STOP (error contact_opted_out). Failed messages are refunded to your wallet automatically.
Read messages & delivery status
GET/messages/{id} — one message and its status: accepted → sent → delivered → read (or failed with an error).
GET/messages?contact=919876543210&direction=in&limit=50&before_id=… — recent messages, newest first. Page with next_before_id.
json{ "messages": [{ "id": "wamid.…", "direction": "in", "contact": "919876543210", "type": "text",
"text": "Is my order shipped?", "status": "received", "cost": 0, "sent_by_api": false, "created_at": "2026-11-20T09:15:00.000Z" }],
"next_before_id": 18422 }For real-time updates use webhooks instead of polling.
Contacts
| Endpoint | Description |
|---|---|
GET/contacts?search=&tag=&opted_in=&page=&per_page= | List contacts (max 200 per page). |
POST/contacts | Create or update one contact, or up to 500 with {"contacts":[…]}. Tags are added, attributes merged. |
GET/contacts/{phone} | One contact. |
PATCH/contacts/{phone} | name, tags (replace), add_tags, remove_tags, attributes ("" removes a key), opted_in. |
DELETE/contacts/{phone} | Delete a contact. |
bashcurl -X POST https://www.afojet.com/api/v1/whatsapp/contacts \
-H "Authorization: Bearer afo_wa_YOUR_KEY" -H "Content-Type: application/json" \
-d '{"phone":"919876543210","name":"Ravi Patel","tags":["customer","surat"],"attributes":{"city":"Surat","plan":"gold"}}'Payments
Send a payment request in the chat. Set up how you collect money in Inbox → Payments → Settings:
- WhatsApp Pay — customer pays inside WhatsApp via your Razorpay / PayU / BillDesk / Zaakpay (Indian +91 business numbers, INR).
- Razorpay Payment Link — works on any number; UPI, cards, net banking; confirmed automatically. Other currencies (USD, EUR, GBP, AED, SAR, QAR, SGD, AUD, CAD, NZD, MYR, HKD) need International Payments on your Razorpay account.
- UPI ID link — a pay page with your UPI ID and QR code; you confirm payments yourself.
POST/payments
bashcurl -X POST https://www.afojet.com/api/v1/whatsapp/payments \
-H "Authorization: Bearer afo_wa_YOUR_KEY" -H "Content-Type: application/json" \
-d '{
"to": "919876543210",
"items": [{ "name": "IELTS coaching – 2 months", "quantity": 1, "price": 15000 }],
"tax": 2700,
"message": "Your course booking",
"via": "link",
"currency": "INR"
}'json201 Created
{ "payment": { "reference_id": "AFMWO3K1A2B3C4", "to": "919876543210", "status": "pending", "order_status": "pending",
"sent_as": "link", "pay_url": "https://rzp.io/rzp/AbCdE", "total": 17700, "currency": "INR",
"items": [{ "name": "IELTS coaching – 2 months", "quantity": 1, "price": 15000 }], "tax": 2700, "shipping": 0, "discount": 0,
"transaction_id": null, "method": null, "paid_at": null, "created_at": "2026-11-20T09:20:00.000Z" } }via: whatsapp (WhatsApp Pay) or link; leave it out to use your default. Prices are in the currency’s main unit (rupees, dollars).
GET/payments/{reference_id} — status pending, paid or failed. GET/payments?status=paid&limit=50 — recent requests.
Webhooks
Add your https URL in Inbox → Developers → Webhooks, pick events and copy the signing secret. We POST JSON to your URL; answer with any 2xx within 8 seconds. Failed deliveries are retried after 1 min, 5 min, 30 min, 2 h and 6 h, and you can see and resend every delivery in the inbox.
| Event | When |
|---|---|
message.received | A customer sent you a message (text, button reply, photo, document, location…). |
message.status | A message you sent was sent, delivered, read or failed. |
contact.opt_change | A contact replied STOP or START. |
payment.status | A payment request was paid or failed. |
order.status | You marked an order processing, shipped, completed or canceled. |
lead.created | A chat started from a Click-to-WhatsApp ad or one of your tracked links. |
httpPOST https://your-server.com/whatsapp-webhook
Content-Type: application/json
X-Afojet-Event: message.received
X-Afojet-Delivery: 1234
X-Afojet-Timestamp: 1763630100
X-Afojet-Signature: sha256=5f2b8c…
{ "event": "message.received", "created_at": "2026-11-20T09:15:00.000Z",
"data": { "id": "wamid.…", "from": "919876543210", "name": "Ravi", "type": "text", "text": "Is my order shipped?",
"button_payload": null, "media_id": null, "reply_to": null, "timestamp": "2026-11-20T09:14:59.000Z", "phone_number_id": "1234567890" } }Verify the signature
The signature is HMAC-SHA256 of timestamp + "." + raw body with your webhook secret. Always check it, and reject old timestamps.
node.jsconst crypto = require('crypto');
// raw = the request body exactly as received (string / Buffer)
function verify(raw, headers, secret) {
const ts = headers['x-afojet-timestamp'];
const expected = 'sha256=' + crypto.createHmac('sha256', secret).update(ts + '.' + raw).digest('hex');
const sig = String(headers['x-afojet-signature'] || '');
return sig.length === expected.length
&& crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(expected))
&& Math.abs(Date.now() / 1000 - Number(ts)) < 300;
}php<?php
$raw = file_get_contents('php://input');
$ts = $_SERVER['HTTP_X_AFOJET_TIMESTAMP'] ?? '';
$sig = $_SERVER['HTTP_X_AFOJET_SIGNATURE'] ?? '';
$ok = hash_equals('sha256=' . hash_hmac('sha256', $ts . '.' . $raw, getenv('AFOJET_WEBHOOK_SECRET')), $sig)
&& abs(time() - (int) $ts) < 300;
if (!$ok) { http_response_code(401); exit; }
$event = json_decode($raw, true);
http_response_code(200);pythonimport hmac, hashlib, time
def verify(raw: bytes, headers, secret: str) -> bool:
ts = headers.get('X-Afojet-Timestamp', '')
expected = 'sha256=' + hmac.new(secret.encode(), ts.encode() + b'.' + raw, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, headers.get('X-Afojet-Signature', '')) and abs(time.time() - int(ts or 0)) < 300Errors & limits
Errors return an HTTP status and {"error":{"code":"…","message":"…"}}. The message is written for people — you can show it in your app.
| HTTP | code | Meaning |
|---|---|---|
| 400 | bad_request / invalid_json | Missing or wrong fields, or the body is not JSON. |
| 400 | invalid_number | "to" / phone is not a valid number with country code. |
| 400 | outside_24h_window | More than 24 hours since the customer wrote — send a template. |
| 400 | template_not_found / template_not_approved / template_params | Check the name, Meta’s review status, and the values it needs (GET /templates → needs). |
| 400 | no_number / payments_off | Connect a WhatsApp number / set up payments first. |
| 401 | unauthorized | Missing, wrong or deleted API key. |
| 402 | insufficient_balance | Top up your wallet. |
| 403 | contact_opted_out | Marketing template to someone who replied STOP. |
| 404 | not_found | Message, contact or payment not found in your account. |
| 429 | rate_limited | More than 120 requests a minute with one key. |
| 502 | meta_error / razorpay_error | WhatsApp or Razorpay refused the request — the message says why. |
Code samples
node.js// Node.js 18+ (built-in fetch)
const res = await fetch('https://www.afojet.com/api/v1/whatsapp/messages', {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.AFOJET_API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ to: '919876543210', template: 'order_update', language: 'en', params: ['Ravi', '#1024'] }),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error.message);
console.log('Sent', data.id);php<?php
$ch = curl_init('https://www.afojet.com/api/v1/whatsapp/messages');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('AFOJET_API_KEY'), 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode(['to' => '919876543210', 'template' => 'order_update', 'language' => 'en', 'params' => ['Ravi', '#1024']]),
]);
$data = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo $status < 300 ? 'Sent ' . $data['id'] : 'Error: ' . $data['error']['message'];pythonimport os, requests
r = requests.post('https://www.afojet.com/api/v1/whatsapp/messages',
headers={'Authorization': f"Bearer {os.environ['AFOJET_API_KEY']}"},
json={'to': '919876543210', 'template': 'order_update', 'language': 'en', 'params': ['Ravi', '#1024']},
timeout=30)
data = r.json()
print('Sent', data['id']) if r.ok else print('Error:', data['error']['message'])Zapier, Pabbly, Make, n8n
No code needed: use their Webhooks / HTTP request action to call POST https://www.afojet.com/api/v1/whatsapp/messages (or /contacts, /payments) with the header Authorization: Bearer afo_wa_… and a JSON body. Use their Catch webhook trigger as your Afojet webhook URL to react to incoming messages, payments and leads — e.g. add every new WhatsApp lead to Google Sheets, or send an order confirmation when a WooCommerce / Shopify order is created.
FAQ
How much does a message cost? The same as in the inbox — see pricing. Replies inside the 24-hour window may be free; failed messages are refunded.
Can I use the API and the inbox together? Yes. API messages appear in Live Chat marked “API”, and your team can reply there. Replies from customers arrive in Live Chat and on your webhook.
Do I need my own Meta app or token? No. Afojet manages the connection to WhatsApp; you only need your Afojet API key.
Can I delete a message from the customer’s phone? No — WhatsApp’s Business API has no “delete for everyone”.
Need help? Contact us or open a support ticket from your account.