By use case

Transactional notifications with the WhatsApp API

A transactional notification is a message born from an event in your system: payment captured, password changed, status updated. To send it through the WhatsApp API once, fast and without blocking your app, the send has to leave the request, go through a queue and be confirmed by webhook.

By D-API engineering team5 min read

Transactional is not a campaign

The difference is not the copy, it is the trigger. A campaign is decided by a person and goes to a list. A transactional notification is decided by the system, goes to one person and only exists because something happened to them. Typical examples:

  • Order received, payment approved or declined, invoice issued.
  • Password reset, new sign-in to the account, email change.
  • Status change on a ticket, proposal, case or delivery.
  • Plan renewal due, card expiring, usage limit reached.

Because customers expect these alerts, read rates on WhatsApp tend to be high and the risk of reports is low. On the other hand, tolerance for mistakes is low too: a payment alert that arrives twice creates a support ticket, and one that never arrives creates distrust. The technical design exists to prevent both.

An architecture that handles volume

The most common mistake is calling the WhatsApp API inside the request that processes the payment. If the call is slow, checkout is slow. If it fails, the payment ends up in a strange state. The recommended flow splits responsibilities:

  1. The domain publishes an event, for example payment.approved, and moves on. No WhatsApp here.
  2. A consumer reads the event from the queue, builds the message from a template and computes the idempotency key.
  3. The worker sends to D-API with async: true. The API answers right away with a commandId and runs the send in the background.
  4. The result arrives on the webhook command.result. The worker stores the commandId with the notification and the webhook updates the record.
  5. Delivery and read come later, through the message.delivered and message.read events, if you want to show them in your dashboard.

The worker call looks like this:

curl -X POST https://api.d-api.cloud/api/v1/messages/send/text \
  -H "Authorization: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "sessionId": "store-notifications",
    "to": "14155550123",
    "text": "Payment approved. Your order 48213 is being packed.",
    "async": true
  }'

If your system would rather poll than wait for the event, the result is also available at GET /api/v1/commands/{commandId} for about an hour. For guaranteed delivery, the docs recommend the webhook. If you already run RabbitMQ, you can receive events straight into a queue, configured per session.

Idempotency: the notification that must not arrive twice

Queues deliver at least once, not exactly once. A worker that crashes after sending and before acknowledging will reprocess the same message. The protection lives on your side, and it is simple:

  • Key derived from the event, not the clock. Something like order:48213:paid. The same event always produces the same key.
  • Unique constraint in the database. Store the key in a notifications table with a unique index before calling the API. If the insert fails as a duplicate, the send already happened or is in progress.
  • Explicit state. pending, sent with the commandId, confirmed or failed. Retry only what is failed, with growing intervals and a maximum number of attempts.
  • The webhook is idempotent too. D-API retries a webhook up to 7 times with exponential backoff if your server does not respond, and deduplicates events within a short window. Your handler must accept the same event twice with no side effects.

Event format and retry details are in WhatsApp webhooks.

Official or unofficial API for notifications

Both paths work for transactional messages, under different rules. On D-API they share the same integration, so you can revisit the choice without rewriting the worker.

Unofficial (QR code)Official (Cloud API)
First message to the customerFree-form textApproved template, usually utility category
Send routemessages/send/text and othersmessages/send/template outside the conversation window
CostPer connection on D-APIPer-connection fee plus Meta’s per-template charge, which varies by category and country
Changing the copyImmediateNew template, subject to Meta approval

In an official template, the variable parts go in bodyVariables, and the template name and language are required. To go deeper on the choice, see official vs unofficial WhatsApp API and the official WhatsApp API (Meta Cloud API) page.

Content best practices

  • Name the company in the first line. The customer needs to know who is talking before reading the rest.
  • One notification, one subject. Do not use a payment alert to pitch a product.
  • Include the identifier the customer recognizes: order number, ticket ID, last digits of the card.
  • Group nearby events. Three status changes in two minutes become a single message.
  • Respect the clock. An alert that is not urgent can wait until the next morning.

Two specific cases have their own guides: verification codes (OTP) and order tracking. If notifications come from internal systems such as an ERP or monitoring, also see WhatsApp API for internal operations. The 3-day free trial, no credit card, is enough to build the full flow, from the event to the confirmation webhook.

Frequently asked questions

What is a transactional notification on WhatsApp?
It is a message triggered by an event in the customer’s journey, not by a campaign: order confirmed, payment approved, password reset, delivery on the way. It is expected, one-to-one and immediately useful.
Can I send transactional notifications with the unofficial WhatsApp API?
Yes, and it is one of the most common uses. The rule is to send only to people who have a relationship with your company and expect that alert. High volume to people who do not know the number is what leads to bans, not the type of API.
Do I need a template for notifications on the official WhatsApp API?
Yes, when the business starts the conversation. Order, payment and account alerts usually fall under Meta’s utility category, and the template must be approved before the first send. Approval is Meta’s decision.
How do I stop a customer from getting the same notification twice?
Build a unique key for each notification from the event, such as order 123 paid, and store it before sending. If the event arrives again, the key already exists and the send is skipped.
How do I know the notification was delivered?
When you send with async true you get a commandId back, and the send result arrives on the command.result webhook. After that, the message.delivered and message.read events report delivery and read status.

Try D-API's WhatsApp API

3-day trial with full access. No credit card, no lock-in.