> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dmly.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Webhooks

> Subscribe to 83 events and DMLY posts to your endpoint as they happen.

Rather than polling the API, register an endpoint and DMLY will `POST` to it whenever
something happens: a message arrives, an invoice is paid, an appointment is booked.

## Setting one up

**1. Add a webhook integration**

Go to **Configurations → Integrations → Webhooks** and add your endpoint URL. It must be
publicly reachable over HTTPS.

**2. Choose events**

Subscribe to the topics you care about, then select **Connect**. Subscribe narrowly:
every event you accept and discard is a request your server paid for.

**3. Copy the signing secret**

DMLY generates a signing secret for you; you don't supply one. Once connected, the
**Signing secret** panel appears: select **Reveal**, then **Copy**. Every delivery to
your own endpoint is signed, so verify it. See [Verifying](#verifying-a-delivery).

**4. Send a test**

Use the test ping to confirm your endpoint is reachable and your signature check works
before relying on it.

## The payload

Every delivery has the same envelope. Only `data` varies by topic:

```json theme={"dark"}
{
  "id": "9f1c4b6e-3a2d-4f8b-9c1e-2a7d5e8b0c31",
  "event": "contact.created",
  "occurred_at": "2026-07-14T09:30:00+00:00",
  "workspace_id": 42,
  "data": {
    "contact": { "id": "…", "name": "Ada Lovelace", "phone": "+15551230001" }
  }
}
```

Test pings carry an extra `"test": true` so you can ignore them in production logic.

### Messages that came from an ad

When a chat starts from a Click-to-WhatsApp, Click-to-Messenger or Click-to-Instagram ad, the
`message.received` delivery carries the ad as `data.message.referral`. On an ordinary message it
is `null`. The object has the same keys on all three apps, and a key Meta didn't send is `null`
rather than missing:

```json theme={"dark"}
"referral": {
  "source": "ad",
  "ad_id": "120214731400140001",
  "ad_title": "2021 Toyota Corolla LE",
  "body": null,
  "photo_url": "https://scontent.xx.fbcdn.net/v/t45.1600-4/corolla.jpg",
  "video_url": null,
  "thumbnail_url": null,
  "source_url": null,
  "post_id": "110022003300440_987654321098765",
  "product_id": "6543210987654321",
  "ref": "spring_inventory",
  "ctwa_clid": null
}
```

| Field | Means |
| - | - |
| `source` | `ad`, `post` (a WhatsApp chat opened from an organic post) or `link` (an m.me or ig.me ref link, where only `ref` is set) |
| `ad_id` | The ad's ID in Meta, the same one the ads report and the ad triggers use |
| `ad_title` | The ad's headline |
| `product_id` | On a catalog ad, the catalog item the person tapped. Messenger only in practice: WhatsApp doesn't send it and Instagram doesn't document it |
| `post_id` | The post behind the ad |
| `photo_url`, `video_url` | The ad's media. On Messenger and Instagram, `video_url` is the video's thumbnail image |
| `ref` | The `ref` value set on the ad or link, if any |
| `ctwa_clid` | WhatsApp only: the click ID Meta's Conversions API uses |

Media links point at Meta's CDN and expire, so copy anything you want to keep. The same object
appears on each message from `GET /conversations/{contact}/messages`, and `GET /conversations`
carries the most recent one per conversation.

> [!NOTE]
>
> On Messenger, somebody who already has a chat with your Page can tap an ad without typing
> anything. Meta sends no message for that, so DMLY records an inbound message reading
> **Opened the chat from an ad** that carries the referral, and you receive it as a normal
> `message.received`.

## Headers

| Header | Value |
| - | - |
| `X-Dmly-Event` | The topic, e.g. `contact.created` |
| `X-Dmly-Delivery` | Id for this delivery. **Stable across retries**: for your own endpoints it is the envelope `id` |
| `X-Dmly-Signature` | `sha256=<hmac>`, sent on every delivery to your own endpoints |
| `User-Agent` | `Salesbot-Webhooks/1.0` |

> [!WARNING]
>
> These headers used to be called `X-Salesbot-Event`, `X-Salesbot-Delivery` and
> `X-Salesbot-Signature`. Every delivery still carries the old names as well, with exactly
> the same values, so an endpoint that verifies `X-Salesbot-Signature` keeps working. The old
> names are deprecated and will be removed in a future release: read the `X-Dmly-` headers in
> new code, and switch existing verifiers over.

## Verifying a delivery

The signature is an HMAC-SHA256 of the **raw request body**, keyed by your secret. Compute
it over the bytes exactly as received; parsing and re-serialising the JSON first will
change the bytes and the signature will never match.

```python theme={"dark"}
import hmac, hashlib

def verify(raw_body: bytes, header: str, secret: str) -> bool:
    expected = "sha256=" + hmac.new(
        secret.encode(), raw_body, hashlib.sha256
    ).hexdigest()
    return hmac.compare_digest(expected, header)
```

> [!WARNING]
>
> Always compare with a constant-time function (`hmac.compare_digest`, `crypto.timingSafeEqual`).
> A plain `==` leaks timing information that can be used to forge a signature.

> [!NOTE]
>
> Zapier hook URLs are not signed. Their URLs are unguessable capability URLs, so they carry
> no `X-Dmly-Signature` header. Signing applies to your own webhook endpoints.

## Responding

Return any `2xx` to acknowledge. DMLY allows **8 seconds** before it treats the delivery as
failed, so acknowledge immediately and do the real work asynchronously; do not process the
event inline and then respond.

Failed deliveries are retried twice more, after roughly **10s** then **60s** (three
attempts in total). After that the delivery is logged as failed and dropped.

> [!TIP]
>
> Deliveries are at-least-once, not exactly-once: a timeout on your side can produce a
> retry for an event you already handled. Deduplicate on the envelope's `id` (or the
> identical `X-Dmly-Delivery` header), which is stable across retries of the same
> event.

## Events

There are 85 topics across contacts, Facebook lead forms, conversations, calls, message lifecycle,
appointments, classes, invoices, orders, payments, subscriptions, credits, the store,
automations and broadcasts.

Most are documented with their full payload in the sidebar under this section. The sidebar
does not yet cover eight store topics: `store.order_in_transit`, `store.order_out_for_delivery`,
`store.order_delivered`, `store.order_ready_for_pickup`, `store.order_delivery_failed`,
`store.customer_created`, `store.customer_opted_in` and `store.customer_opted_out`. For the
complete, current list, call `GET /api/v1/webhooks/events`, which always returns every topic.

### order.status\_changed

`order.status_changed` is new and not in the sidebar yet. It fires when a team member moves a
confirmed order through its [progress steps](https://docs.dmly.io/finance/orders.md#order-progress). Its `data` carries
the order:

```json theme={"dark"}
{
  "event": "order_status_changed",
  "order": {
    "id": "ord_demo",
    "number": "ORD-0042",
    "total": "89.00",
    "currency": "USD",
    "status": "ready for pickup",
    "status_key": "ready",
    "previous_status": "preparing",
    "fulfilment_type": "pickup",
    "correction": false
  }
}
```

* `status_key` is the step: `received`, `preparing`, `ready`, `out_for_delivery`, `delivered`
  or `collected`. `status` is the same step in the words the customer reads.
* `fulfilment_type` is `pickup` (pickup and dine-in), `delivery`, or empty when the order says
  neither.
* `correction` is `true` when the order was moved back one step to fix a mistake. That move
  reaches your webhook so an outside system keeps the true state, but it starts no automation
  and sends the customer nothing.

The REST API's order object carries the same progress: `fulfilment_status` (null for a draft,
cancelled or refunded order), `fulfilment_type`, and the time of each step as `preparing_at`,
`ready_at`, `out_for_delivery_at`, `delivered_at` and `collected_at`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.