API — Suhail WhatsApp

Send WhatsApp messages and verification codes from your own system, from your own number. All requests are JSON over https, and so are the responses.

Authentication

Create a key under Developers in your workspace and send it in the Authorization header. The key is shown once; revoke it at once if it leaks.

curl https://suhailds.com/api/v1/templates \
  -H "Authorization: Bearer sk_live_…"

Send a message

Free-form text — allowed within 24 hours of the customer's last message to you, otherwise 409 window_closed:

curl -X POST https://suhailds.com/api/v1/messages \
  -H "Authorization: Bearer sk_live_…" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: order-1042-shipped" \
  -d '{"to": "+447700900123", "type": "text", "text": "Your order has shipped."}'

An approved template — at any time, to recipients with a recorded opt-in. Variables follow the order of {{1}}, {{2}}:

curl -X POST https://suhailds.com/api/v1/messages \
  -H "Authorization: Bearer sk_live_…" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 7f3c9e1a-order-1042" \
  -d '{
    "to": "+249912345678",
    "type": "template",
    "template": { "name": "order_update", "language": "ar", "variables": ["1042", "Friday"] },
    "consent": { "source": "checkout form on example.com" }
  }'

Messenger and Instagram: add channel (messenger or instagram); the recipient is their ID in that channel (PSID or IGSID) as it arrived in their inbound message. Text only, and within 24 hours of their last message; later messages cannot be sent through the API.

curl -X POST https://suhailds.com/api/v1/messages \
  -H "Authorization: Bearer sk_live_…" \
  -H "Content-Type: application/json" \
  -d '{"channel": "messenger", "to": "24001002003004", "type": "text", "text": "Your order has shipped."}'

consent.source records the recipient's opt-in and where it came from before sending (once is enough). Someone who sent STOP is never messaged until they send START, and consent does not override that.

Idempotency-Key (optional, up to 255 characters): repeat the same request with the same key after a network failure and you get the first response; the message is not sent twice. The same key with a different body ⇒ 422.

HTTP/1.1 201 Created
{ "id": "5b0f…", "wamid": "wamid.HBgM…", "to": "447700900123", "status": "queued" }

Message status

Statuses: queued, then sent, delivered and read — or failed, with Meta's error and code.

curl https://suhailds.com/api/v1/messages/5b0f… \
  -H "Authorization: Bearer sk_live_…"

{ "id": "5b0f…", "wamid": "wamid.HBgM…", "status": "delivered", "error": null,
  "pricing_category": "utility", "created_at": "…", "updated_at": "…" }

Verification codes (OTP)

Needs an APPROVED authentication template in your workspace; Meta approves it only for a verified business portfolio. We generate a 6-digit code valid for 10 minutes and store only its hash.

curl -X POST https://suhailds.com/api/v1/otp/send \
  -H "Authorization: Bearer sk_live_…" \
  -H "Content-Type: application/json" \
  -d '{"to": "+447700900123", "client_ip": "203.0.113.24"}'

{ "id": "c1e2…", "to": "447700900123", "status": "pending", "expires_at": "…" }
curl -X POST https://suhailds.com/api/v1/otp/verify \
  -H "Authorization: Bearer sk_live_…" \
  -H "Content-Type: application/json" \
  -d '{"to": "+447700900123", "code": "482913"}'

{ "status": "approved", "attempts_remaining": 4 }

The result is one of: approved (correct, and never accepted twice), incorrect, expired, too_many (after five wrong attempts; request a new code).

Against OTP pumping: one code per minute and five per hour for each number, plus an hourly limit per workspace. Pass client_ip (the address of the user who asked for the code, not your server's) to add a per-address limit. Exceeding a limit ⇒ 429 with Retry-After.

Templates

Your workspace templates and their status. Create and sync them in the dashboard; Meta reviews each template before approving it.

curl https://suhailds.com/api/v1/templates \
  -H "Authorization: Bearer sk_live_…"

{ "data": [ { "name": "order_update", "language": "ar", "category": "UTILITY",
              "status": "APPROVED", "variables": 2, "body": "…" } ] }

Webhooks

Set your URL under Developers. Events: message.received, message.status and template.status (and ping for tests).

POST https://your-app.example/hooks/whatsapp
X-Suhail-Event: message.received
X-Suhail-Delivery: 1842
X-Suhail-Signature: t=1764160000,v1=5d41402abc4b2a76b9719d911017c592…

{ "id": "evt_…", "type": "message.received", "created_at": "…",
  "data": { "id": "…", "wamid": "wamid.…", "from": "447700900123",
            "type": "text", "text": "Hello", "timestamp": "…" } }

Verify every request: v1 is the HMAC-SHA256 of "t.raw body" with your workspace secret. Reject anything that does not match or is older than 5 minutes.

// Node.js
import { createHmac, timingSafeEqual } from 'node:crypto'

function verify(rawBody, header, secret) {
  const { t, v1 } = Object.fromEntries(header.split(',').map((p) => p.split('=')))
  if (Math.abs(Date.now() / 1000 - Number(t)) > 300) return false // older than 5 minutes
  const expected = createHmac('sha256', secret).update(`${t}.${rawBody}`).digest('hex')
  return expected.length === v1.length && timingSafeEqual(Buffer.from(expected), Buffer.from(v1))
}

Answer with 2xx within 10 seconds. Anything else is retried with exponential backoff (30 s, 1 min, 2 min… up to 6 h) for 24 hours; the log is in the dashboard.

Errors

Every error has the same shape: a stable code to program against and a message to read. Meta's errors arrive in error.meta with its code and fbtrace_id.

HTTP/1.1 409 Conflict
{ "error": { "code": "window_closed",
             "message": "Free-form text is allowed only within 24 hours of the recipient’s last message. Send an approved template instead." } }
401missing_key · invalid_key
403workspace_suspended
404not_found · template_not_found
409window_closed · opted_out · no_opt_in · template_not_approved · not_connected · no_auth_template · idempotency_in_progress
422invalid_request · invalid_recipient · invalid_phone · idempotency_key_reused
429rate_limited · rate_limited_phone · rate_limited_workspace · rate_limited_ip
502meta_error · send_failed

Rate limits

120 requests per minute per key. Exceeding it ⇒ 429 with a Retry-After header in seconds; RateLimit-Remaining is in every response.

Meta's own limit for your number (how many customers you can start conversations with per 24 hours) also applies; it is shown on the WhatsApp page.