Chatrixa Developers

Template Messages

Send an approved WhatsApp template (for example an invoice with a PDF) with POST /api/send/template.

Send a template

curl -X POST https://chatrixa.com/api/send/template \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "phone": "+14155552671",
    "template": {
      "name": "invoice_ready",
      "language": { "code": "en" },
      "components": [
        { "type": "header", "parameters": [
          { "type": "document", "document": { "link": "https://files.example.com/INV-1001.pdf", "filename": "INV-1001.pdf" } }
        ] }
      ]
    },
    "reference": "INV-1001",
    "recipient_reference": "+14155552671",
    "idempotency_key": "invoice-1001"
  }'

The template object is sent to the WhatsApp Cloud API as you give it. phone, template.name and template.language are required. The last three fields are optional — see below.

Response:

{
  "statusCode": 200,
  "data": { "success": true, "data": { "messages": [{ "id": "wamid.HBgM..." }] } },
  "request_id": "3f0c2a6e-1d1b-4d55-9a37-6f3f5f8a2b10"
}

data.success is false when WhatsApp refused the message. The HTTP status is still 200 in that case.

Buttons with a dynamic link

When the template has a URL button whose link ends with {{1}} (see Managing Templates), each send gives that ending in a button component. WhatsApp adds it to the end of the button's fixed URL.

Template button: https://pay.example.com/link/{{1}}. Send:

"template": {
  "name": "payment_link",
  "language": { "code": "en" },
  "components": [
    { "type": "body", "parameters": [ { "type": "text", "text": "TCK-1001" }, { "type": "text", "text": "12.500" } ] },
    { "type": "button", "sub_type": "url", "index": "1",
      "parameters": [ { "type": "text", "text": "AbC123" } ] }
  ]
}

The customer's button opens https://pay.example.com/link/AbC123.

Request id

Every call that reaches this endpoint, also a refused one, gets a request_id. It is in the response body and in the X-Request-Id header. Keep it in your logs and quote it when you contact support: it points to the audit record of that call.

Do not put personal data (names, phone numbers, e-mail addresses) in reference: it is stored as you send it. Use an invoice or order number.

The audit record keeps only keyed fingerprints and small values: the template name and language, a fingerprint of the phone, the file host, a fingerprint of the file link, the file extension, and your reference. It never keeps your API token, the message text, the phone number, the filename or the file link (signed links stay private). Records are deleted after 180 days.

Calls refused before they reach the endpoint (wrong token 401, suspended account 403 ORGANIZATION_SUSPENDED, rate limits) get no request_id.

Owner guard: recipient_reference

The guard is opt-in. Send the phone number or the Chatrixa contact uuid that you believe owns the document. When it does not match the recipient of phone, nothing is sent:

{
  "statusCode": 422,
  "code": "TEMPLATE_RECIPIENT_MISMATCH",
  "message": "The recipient does not match recipient_reference. Nothing was sent.",
  "request_id": "3f0c2a6e-1d1b-4d55-9a37-6f3f5f8a2b10"
}

If recipient_reference is present it must be a non-empty string (or number) of at most 255 characters, or the call is refused with 400. It is never ignored.

Safe retries: idempotency_key

Give each send a unique key, for example invoice-1001: 1 to 255 characters, letters, digits, ., _, : or -. Anything else is a 400. Keys belong to your organization: all your API keys share them.

Call Result
Same key, same request 200 with the first result, "idempotent_replay": true and original_request_id. Nothing is sent again.
Same key, other request (other phone, template, language, document, or — for non-authentication templates — other parameters such as the invoice number or amount) 409 TEMPLATE_IDEMPOTENCY_KEY_REUSED. Nothing is sent.
Same key while the first call is still running 409 TEMPLATE_IDEMPOTENCY_IN_PROGRESS with original_request_id. Retry a little later.
Same key after the first call ended without a known result: a timeout or lost connection while calling WhatsApp, a WhatsApp server error (5xx), an unexpected answer, or a call still not finished after 10 minutes 409 TEMPLATE_IDEMPOTENCY_OUTCOME_UNKNOWN with original_request_id. Do not retry with the same key: check whether the customer got the first message (support can look up original_request_id), then send again with a new key if needed.

Only when WhatsApp refuses the first send outright (data.success: false with a 4xx error that is not temporary, for example 131026 or a template error), or Chatrixa refuses it before calling WhatsApp, is the key freed: you can fix the problem and retry with the same key. After a timeout, a 5xx, an HTTP 408, or an error WhatsApp marks as temporary (is_transient, or codes 1, 2, 131000, 131016, 133004) the message may already have been delivered, so the key stays taken (TEMPLATE_IDEMPOTENCY_OUTCOME_UNKNOWN).

For authentication (OTP) templates the parameters are not part of the request comparison, because a short code must never be stored even as a fingerprint: the same key with another code returns the first result. Use a new key for every new code. To be safe, Chatrixa compares parameters only for a template it knows is Marketing or Utility in exactly the language you send (synced in Chatrixa). Any other template is treated like an authentication one. Media links (document, image, video, carousel cards) are always compared.

If the send record cannot be updated at the wrong moment (for example a database outage right after a call), a key can stay blocked as in progress or unknown. Use a new key then.

The replayed data is partial: it carries success, the WhatsApp message id and only the chat's id, wam_id, status and created_at — never the message content.

A key whose first call is older than the 180-day retention window is forgotten: using it again sends again.

If the call carries recipient_reference or idempotency_key and Chatrixa cannot record it, nothing is sent and the answer is 503 TEMPLATE_SEND_AUDIT_UNAVAILABLE (retry later). Calls without these fields are sent as before.

To create, edit, delete or sync templates from your own system, and to be notified when WhatsApp approves, rejects or re-categorises one, see Managing templates and Webhooks.

Errors

Status code Meaning
400 — Invalid input; see errors.
401 — Missing or wrong API token.
403 — / ORGANIZATION_SUSPENDED No active subscription, WhatsApp not connected, or account suspended.
403 API_KEY_SCOPE_MISSING The token lacks messages:send (see required_scope).
409 TEMPLATE_IDEMPOTENCY_KEY_REUSED, TEMPLATE_IDEMPOTENCY_IN_PROGRESS, TEMPLATE_IDEMPOTENCY_OUTCOME_UNKNOWN See Safe retries.
422 TEMPLATE_RECIPIENT_MISMATCH See Owner guard.
503 TEMPLATE_SEND_AUDIT_UNAVAILABLE A guarded call could not be recorded; nothing was sent.