# Webhooks

Receive a signed POST for every campaign event instead of polling. Live endpoints use HTTPS.

## Register an endpoint

```bash
curl -s -H "Authorization: Bearer $KEY" -H 'content-type: application/json' $API/v1/webhooks \
  -d '{"url":"https://partner.example/xcel/webhooks","event_types":["campaign.status_changed","approval.decided"]}'
```

Response (201). The `secret` is shown here once; store it now:

```json
{
  "id": "f68d03c7-2219-4ea2-afd2-52ac708a1f09",
  "mode": "test",
  "url": "https://partner.example/xcel/webhooks",
  "event_types": ["campaign.status_changed", "approval.decided"],
  "active": true,
  "created_at": "2026-11-02T15:00:00.000Z",
  "secret": "whsec_AX_nNsI4BlRvh8n6i_EOz1JpTmRbUg5s",
  "signature": {
    "header": "X-Xcel-Signature",
    "format": "t=<unix seconds>,v1=<hex HMAC-SHA256 of `${t}.${raw body}` keyed with secret>",
    "note": "Store the secret now; it is not shown again. Reject deliveries whose t is more than 5 minutes old."
  }
}
```

- Omit `event_types`, or send `[]`, to receive every event type. A type this API does not have is refused with 400 `invalid_request`; for a Lob event name such as `postcard.delivered`, the fix names the campaign event to use ([Event types](#event-types)).
- An endpoint belongs to the key's mode. A test key's endpoints receive sandbox events only; a live key's, live events only.
- An endpoint receives events that happen after it is registered. Earlier events are not sent to it, but [`GET /v1/events`](#reconcile-a-window-you-missed) lists them. A delivery it did receive, or failed to, can be [replayed](#test-your-endpoint).
- A partner may have at most 5 active endpoints per mode by default; one more is refused with 409 `webhook_limit_reached`. One endpoint can receive every event type, so reuse it. A deactivated endpoint does not count: to make room, deactivate one with `DELETE /v1/webhooks/{id}` or in the [partner console](console.md#developers).
- To change an endpoint's URL or event types, register a new one, then deactivate the old one.

## Manage your endpoints

All three routes act only on your endpoints in the key's mode: a sandbox key never sees or changes a live endpoint, and another partner's endpoint answers 404 `webhook_not_found`. Your team's admins can also list, deactivate and reactivate endpoints in the [partner console](console.md#developers) (**Developers**), and read each endpoint's delivery log there.

**List:** `GET /v1/webhooks` returns your endpoints, active and deactivated, oldest first, each with its latest delivery, and the active-endpoint limit. The secret is never in the list.

```json
{
  "webhooks": [
    {
      "id": "9b0f6c1e-1f7e-4a9a-8f5e-2d3c4b5a6978",
      "mode": "test",
      "url": "https://example.com/xcel/webhooks",
      "event_types": [],
      "active": true,
      "created_at": "2026-11-02T15:04:05.000Z",
      "deactivated_at": null,
      "secret_rotated_at": null,
      "last_delivery": {
        "event_id": "4f8a2c1d-0b3e-4c5f-9a6b-7c8d9e0f1a2b",
        "status": "delivered",
        "attempts": 1,
        "http_status": 200,
        "error": null,
        "created_at": "2026-11-02T15:10:00.000Z",
        "delivered_at": "2026-11-02T15:10:00.412Z",
        "next_attempt_at": null
      }
    }
  ],
  "limit": { "active_max": 5, "active": 1 }
}
```

`last_delivery.status` is `pending` (with `next_attempt_at` for the next retry), `delivered`, `failed` (after the last retry) or `cancelled`. `last_delivery` is null before the first event.

**Deactivate:** `DELETE /v1/webhooks/{id}` deactivates the endpoint and cancels its pending deliveries (status `cancelled`, error `webhook_deactivated`), so nothing more is sent to it. It answers 200 with the endpoint (`active: false`, `deactivated_at`) and `pending_deliveries_cancelled`. It is idempotent: calling it again answers 200 with `pending_deliveries_cancelled: 0`. The endpoint stays in the list for its history.

**Rotate the secret:** `POST /v1/webhooks/{id}/rotate-secret` (no body) gives an active endpoint a new `whsec_` secret and returns it once, in the same shape as registration (`secret` and `signature`). It applies at once: every delivery sent from now on, retries included, is signed with it. Deploy the new secret to your receiver first, or have it accept either secret for a few minutes, then rotate. A deactivated endpoint answers 409 `webhook_inactive`.

**Reactivate:** an admin reactivates a deactivated endpoint in the [partner console](console.md#developers) with **Reactivate**. The API has no reactivate route. The endpoint keeps its id, URL, event types and secret, and receives events from then on; the deliveries its deactivation cancelled are not sent again. The endpoint limit and the [URL rules](#url-rules) apply again, as for a new endpoint, so an endpoint whose host now fails them stays inactive: register a new one.

### URL rules

| Rule | Error message |
| --- | --- |
| Must be a valid URL | The webhook URL is not a valid URL. |
| Live: `https://` only. Sandbox: `https://` or `http://` | Live webhook URLs must use https (sandbox URLs may use http). |
| No user name or password in the URL | Webhook URLs must not embed credentials. |
| Not `localhost`, `*.localhost`, `*.local`, `*.internal`, `*.home.arpa` or `metadata` | Webhook URLs must point at a public host. |
| The host must resolve | The webhook host does not resolve. |
| Every address the host resolves to must be public | The webhook host resolves to a private, loopback, link-local, CGNAT or metadata address. |

A refused URL returns 400 `invalid_webhook_url` with one of these messages. The host is checked again before every delivery.

## The delivery

Each delivery is a `POST` with a JSON body:

```http
POST /xcel/webhooks HTTP/1.1
Content-Type: application/json
User-Agent: XcelMailAPI-Webhooks/1
X-Xcel-Signature: t=1793631600,v1=c94e95d12eee4cf4a8c4861c2e1ed33db01a2070131e763cea14756695ba8d7b
X-Xcel-Event-Id: 1dc9a039-8d37-4566-9d9d-ed024a100a21
X-Xcel-Event-Type: campaign.status_changed
X-Xcel-Mode: test
X-Xcel-Webhook-Id: 3c6f1b2a-9d4e-4f7a-8b1c-2e5d6f7a8b9c

{"id":"1dc9a039-8d37-4566-9d9d-ed024a100a21","type":"campaign.status_changed","created_at":"2026-11-02T15:00:00.000Z","sequence":1793631600000000,"mode":"test","data":{"campaign_id":"20b6b4d9-f321-41ef-aa5e-c1db05b559fd","mode":"test","dealer_id":"8f2b0e4c-5d6a-4b7c-9e8f-0a1b2c3d4e5f","dealer_external_id":"dlr-1042","template_code":"card_8_5x11_birthday","template_version":2,"envelope":"closed_face","external_ref":"cmp_778","metadata":{"program":"birthday"},"from":"in_production","to":"at_usps","label":"Accepted at USPS (processing scan)","description":"USPS acceptance scan recorded. Processing scan only; not proof of delivery.","evidence":"usps_processing_scan","evidence_note":"USPS processing scans show mail moving through postal facilities. They are not proof of delivery to a mailbox.","actor":"sandbox","reason":"simulated"}}
```

| Body field | Meaning |
| --- | --- |
| `id` | The event id. Also in `X-Xcel-Event-Id`. Use it to drop duplicates. |
| `type` | The event type. Also in `X-Xcel-Event-Type`. |
| `created_at` | When the event happened (UTC). |
| `sequence` | A number that never decreases across your campaigns and dealers, but two events can share one, and it is not contiguous. Compare two to find the newer, and break a tie by `created_at`, then `id`. To drop a duplicate, use the event id, never this. Not in events sent before this field existed. |
| `mode` | `test` or `live`: which of your modes this delivery is for. Also in `X-Xcel-Mode`. |
| `data` | On every campaign event: `campaign_id`, `mode`, `dealer_id` (Xcel's dealer id), `dealer_external_id` (your id for the dealer; `null` when none), `template_code` and `template_version` (what the current creative prints; `null` before the first creative and for your own HTML or print-ready art), `envelope` (a letter's `closed_face` or `double_window`, a fold card's `closed_face`; `null` for a postcard), `external_ref` (`null` when none) and `metadata` (`{}` when none), then the event's own fields. A `dealer.updated` event has `dealer_id` and `external_id` instead. Ids, statuses, counts and your own reference only; never customer data. |

Each delivery also has `X-Xcel-Mode` (`test` or `live`) and `X-Xcel-Webhook-Id` (the endpoint). A `dealer.updated` for a dealer shared by both modes goes to both modes' endpoints with the same event id, each signed with its own secret. If you register one URL for both modes, read `X-Xcel-Mode` to pick the secret to verify with, and de-duplicate per event id. Or register a URL per mode.

## Test your endpoint

`POST /v1/webhooks/{id}/test` sends one signed `webhook.test` event now, whatever `event_types` the endpoint takes, and answers what your server replied. Nothing is stored and nothing retries. At most 20 per endpoint per hour.

```json
{ "webhook_id": "...", "event_id": "...", "event_type": "webhook.test", "delivered": true, "http_status": 200, "error": null, "next_step": "..." }
```

`GET /v1/webhooks/event-types` lists every event type you can subscribe to, with what it says; `test_event` names `webhook.test`, which only the test call sends. `GET /v1/webhooks/{id}/deliveries?limit=25&offset=0` lists an endpoint's deliveries, newest first: event type, status, attempts and the last error, never the body.

`POST /v1/webhooks/{id}/deliveries/{delivery_id}/replay` queues a past delivery to send again, with its stored body, its original event id and sequence, and a fresh signature. A receiver that de-duplicates by `X-Xcel-Event-Id` drops a copy it already handled. A delivery still queued answers 409 `webhook_delivery_pending`. At most 100 replays per endpoint per hour.

## Event types

| Type | When | `data` fields besides `campaign_id`, `mode`, `dealer_id`, `dealer_external_id`, `template_code`, `template_version`, `envelope`, `external_ref` and `metadata` |
| --- | --- | --- |
| `campaign.status_changed` | Any status change | `from`, `to`, `label`, `description`, `evidence`, `evidence_note` (USPS scan states only), `actor`, `reason`; on the change to `submitted` also `submission_id`, `quantity`, `total_cents`, `placeholder_pricing` and `timing` ([Mail dates](quotes-and-approvals.md#mail-dates)) |
| `audience.completed` | An uploaded audience was processed | `audience_id`, `audience_version`, `status`, `submitted_count`, `mailable_count`, `rejected_count` |
| `audience.address_processed` | Live: Xcel ops finished CASS and NCOA | `audience_id`, `audience_version`, `cass_failed`, `ncoa_moved` |
| `audience.purged` | An audience's files were deleted, by the retention job or a [delete call](audiences.md#remove-a-list-early) | `audience_id`, `audience_version`, `reason` (`retention` or `request`) |
| `creative.generated` | A creative version was stored | `creative_version`, `preflight_ok`, `errors`, `warnings` (counts; info issues are not counted) |
| `quote.created` | A quote was made | `quote_id`, `quantity`, `mail_class`, `total_cents`, `expires_at` |
| `approval.requested` | Approval was requested | `approval_id`, `quote_id`, `total_cents`, `max_spend_cents`, `expires_at`, `delivery` (`email` or `sandbox_review_url`) |
| `approval.decided` | The approver approved or rejected on the review page, or a sandbox script decided | `approval_id`, `decision` (`approved` or `rejected`), `decided_at`, `decided_via` (`sandbox_test_route` when the sandbox route decided, `chat_proof_view` when the approver decided in the chat's proof view, else absent), `has_note` (rejections only), `prescreen_attestation` (null unless the piece is a prescreened credit offer; see [Prescreened offers](quotes-and-approvals.md#prescreened-offers)) |
| `campaign.results_updated` | The campaign's result totals changed | The `results` aggregates of `get_campaign_results`: `source`, `simulated`, `job`, `drops`, `delivery_percent`, `responses`, `matched`, `leads_with_results`, `updated_at` |
| `campaign.lead_results_updated` | One or more leads' responses or matches changed | `changed_leads`, `leads_with_results`, `part`, `parts`, `leads` (up to 500 `external_id` and `row_key` pairs), `next_step` |
| `campaign.results_linked` | Xcel linked a live order to its tracking, when it goes into production. Results follow from the next poll. | `linked_at`. |
| `campaign.usps_tracking_updated` | Pieces reached a new USPS stage: their first scan (`in_transit`), or a sort for their carrier (`processed_for_delivery`) | `changed_pieces`, `part`, `parts`, `pieces` (up to 500, each with `external_id`, `row_key`, `stage` and `stage_at`), `next_step` |
| `dealer.updated` | A dealer got a new profile version (created, changed or a logo uploaded), by you, Xcel or the UpDash seed; an approver you named changed status; or Xcel changed its disclosures, license number or spend cap (`changed_fields` such as `xcel_managed.disclosures`, `actor_type` `xcel_admin`; `version` stays the same, and the values never appear) | None of the campaign fields: `dealer_id`, `external_id`, `version`, `changed_fields` (names such as `phones.main`, never values; `approvers` for an approver change), `actor_type` (`api_key`, `oauth_client`, `console_user`, `xcel_admin` or `updash_seed`; for an approver change also `approver`, `xcel_ops` or `system`), and for an approver change `approver_invitation` (`id`, `status`) |
| `standing_order.run_created` | A [standing order](standing-orders.md) run built its order and asked the dealer's approver, or found nobody left to mail | None of the campaign fields: `standing_order_id`, `standing_order_external_id`, `mode`, `dealer_id`, `dealer_external_id`, `run_id`, `campaign_id` (null for `nothing_to_mail`), `status` (`awaiting_approval` or `nothing_to_mail`), `trigger` (`request`, `schedule` or `email`), `counts` (`rows`, `mailable`, `skipped_already_mailed`) |
| `standing_order.run_failed` | A standing order run failed, its own submit after approval included, or an emailed list started no run (a paused standing order, a sender not allowed: `run_id` null) | The same as `standing_order.run_created`, with `status` `failed`, `error_code` and `error_message` (the failed step's error) |
| `inbound_email.unmatched` | An email reached a dealer's [inbound address](standing-orders.md#emailed-lists), and no standing order's `inbound_subject` is in its subject. Nothing else of the email is kept | None of the campaign fields: `mode`, `dealer_id`, `dealer_external_id`, `subject` (at most 200 characters), `received_at` |

`external_ref` and `metadata` are what you sent when you created the campaign ([Your reference on a campaign](concepts.md#your-reference-on-a-campaign)), so a receiver can join an event to its own order without keeping Xcel's campaign id. `dealer_external_id` and `template_code` let a receiver find the order by its dealer and by the piece it prints. An event recorded before one of these fields existed does not have it.

`actor` on a status change is `partner`, `reviewer` (the approver on the review page), `ops` (Xcel staff), `sandbox` (the sandbox advance endpoint) or `system`. `reason` is a short phrase such as `proof rendered`, `approved on review page`, `submitted`, `advanced in ops dashboard`, `creative version 3 generated` or, from the UpDash poller (`actor: system`), `UpDash: 41.2% of pieces have USPS processing scans`.

The two results events are sent only when something changed: the Xcel side compares each poll or sandbox step with the stored results and stays quiet when they match. They carry ids and counts only. `campaign.lead_results_updated` names the leads that changed, never their responses or matches; fetch those with `get_campaign_results` (`GET /v1/campaigns/{id}/results`). More than 500 changed leads come as several events, numbered by `part` of `parts`. Live orders send them after a poll of UpDash (every 6 hours, once Xcel links the order); sandbox orders from the test advance, from `in_postal_network` on (`campaign.lead_results_updated` from `delivery_estimated`, when the first simulated responders appear). See [Results and attribution](concepts.md#results-and-attribution).

`campaign.usps_tracking_updated` names the pieces whose USPS stage moved since the last poll, never each scan: a piece's first scan moves it to `in_transit`, and the first scan that sorts it for its carrier to `processed_for_delivery`, which usually means it arrives within a day or two. Neither is proof of delivery. `stage_at` is when the piece reached the stage. A piece whose first scans include that sort goes straight to `processed_for_delivery`. Read each piece's scan count, first and last scan and last facility on `GET /v1/campaigns/{id}/leads` (`usps`, [Who was mailed](concepts.md#who-was-mailed)). More than 500 pieces come as several events, numbered by `part` of `parts`. Live orders send it after a poll of UpDash; sandbox orders from the test advance: some pieces `in_transit` at `in_postal_network`, more of them `processed_for_delivery` at `delivery_estimated`, and every scanned piece at `completed`.

### dealer.updated

Test and live keys share dealers, so a `dealer.updated` event goes to your active endpoints in both modes that subscribe to it. A [test dealer](dealers.md#test-dealers)'s events go to your test endpoints only. Only stored changes send it: a live key, the [partner console](console.md) in live mode, Xcel, or a test key's change to its own test dealer. A test key's write to a shared dealer only validates and sends nothing. It names the fields that changed, never their values: read them with `GET /v1/dealers/{id}/profile` (or `?version=N`). A write that changes nothing sends nothing. See [Dealers](dealers.md).

```json
{
  "id": "3c4d5e6f-7a8b-4c9d-8e0f-1a2b3c4d5e6f",
  "type": "dealer.updated",
  "created_at": "2026-11-02T15:00:00.000Z",
  "sequence": 1793631600000000,
  "mode": "live",
  "data": {
    "dealer_id": "8f2b0e4c-5d6a-4b7c-9e8f-0a1b2c3d4e5f",
    "external_id": "dlr-1042",
    "version": 4,
    "changed_fields": ["phones.service", "hours.service"],
    "actor_type": "api_key"
  }
}
```

When an approver you named changes status ([Approvers](dealers.md#approvers)), the event names `approvers` and the invitation, never the address. `version` is the dealer's current profile version, unchanged. `actor_type` is `approver` when they confirmed, `xcel_ops` when Xcel registered or declined them, `system` when the link expired, or your key or console user when you named them.

```json
{
  "id": "5e6f7a8b-9c0d-4e1f-8a2b-3c4d5e6f7a8b",
  "type": "dealer.updated",
  "created_at": "2026-11-03T09:12:00.000Z",
  "sequence": 1793697120000000,
  "mode": "live",
  "data": {
    "dealer_id": "8f2b0e4c-5d6a-4b7c-9e8f-0a1b2c3d4e5f",
    "external_id": "dlr-1042",
    "version": 4,
    "changed_fields": ["approvers"],
    "actor_type": "approver",
    "approver_invitation": { "id": "1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d", "status": "registered" }
  }
}
```

### Example payloads

`campaign.status_changed` when the approver approves:

```json
{
  "id": "6a1d2c8e-58f0-4f7e-9d43-2b8f1f0c7a11",
  "type": "campaign.status_changed",
  "created_at": "2026-11-02T15:00:00.000Z",
  "sequence": 1793631600000000,
  "mode": "live",
  "data": {
    "campaign_id": "20b6b4d9-f321-41ef-aa5e-c1db05b559fd",
    "mode": "live",
    "dealer_id": "8f2b0e4c-5d6a-4b7c-9e8f-0a1b2c3d4e5f",
    "dealer_external_id": "dlr-1042",
    "template_code": "card_8_5x11_birthday",
    "template_version": 2,
    "envelope": "closed_face",
    "external_ref": "cmp_778",
    "metadata": { "program": "birthday" },
    "from": "awaiting_approval",
    "to": "approved",
    "label": "Approved",
    "description": "Approved by a human; ready to submit.",
    "evidence": null,
    "actor": "reviewer",
    "reason": "approved on review page"
  }
}
```

`audience.completed`:

```json
{
  "id": "0b3e7a5c-9f61-4d2a-8c7e-5d4f3a2b1c0d",
  "type": "audience.completed",
  "created_at": "2026-11-02T15:00:00.000Z",
  "sequence": 1793631600000000,
  "mode": "live",
  "data": {
    "campaign_id": "20b6b4d9-f321-41ef-aa5e-c1db05b559fd",
    "mode": "live",
    "dealer_id": "8f2b0e4c-5d6a-4b7c-9e8f-0a1b2c3d4e5f",
    "dealer_external_id": "dlr-1042",
    "template_code": null,
    "template_version": null,
    "envelope": "closed_face",
    "external_ref": "cmp_778",
    "metadata": { "program": "birthday" },
    "audience_id": "09ef23ca-cee4-4669-b282-828ce568bb64",
    "audience_version": 1,
    "status": "pending_address_processing",
    "submitted_count": 7,
    "mailable_count": 4,
    "rejected_count": 3
  }
}
```

`audience.address_processed`:

```json
{
  "id": "5f0c1e2d-3b4a-4c5d-8e9f-0a1b2c3d4e5f",
  "type": "audience.address_processed",
  "created_at": "2026-11-04T16:20:00.000Z",
  "sequence": 1793809200000000,
  "mode": "live",
  "data": { "campaign_id": "20b6b4d9-f321-41ef-aa5e-c1db05b559fd", "mode": "live", "dealer_id": "8f2b0e4c-5d6a-4b7c-9e8f-0a1b2c3d4e5f", "dealer_external_id": "dlr-1042", "template_code": "card_8_5x11_birthday", "template_version": 2, "envelope": "closed_face", "external_ref": "cmp_778", "metadata": { "program": "birthday" }, "audience_id": "09ef23ca-cee4-4669-b282-828ce568bb64", "audience_version": 1, "cass_failed": 12, "ncoa_moved": 31 }
}
```

`audience.purged`:

```json
{
  "id": "7c2b9d4e-1f3a-4b6c-9d8e-2f1a0b9c8d7e",
  "type": "audience.purged",
  "created_at": "2027-01-31T03:17:00.000Z",
  "sequence": 1801365420000000,
  "mode": "live",
  "data": { "campaign_id": "20b6b4d9-f321-41ef-aa5e-c1db05b559fd", "mode": "live", "dealer_id": "8f2b0e4c-5d6a-4b7c-9e8f-0a1b2c3d4e5f", "dealer_external_id": "dlr-1042", "template_code": "card_8_5x11_birthday", "template_version": 2, "envelope": "closed_face", "external_ref": "cmp_778", "metadata": { "program": "birthday" }, "audience_id": "09ef23ca-cee4-4669-b282-828ce568bb64", "audience_version": 1, "reason": "retention" }
}
```

`creative.generated`:

```json
{
  "id": "2d9e8f7a-6b5c-4d3e-9f2a-1b0c9d8e7f6a",
  "type": "creative.generated",
  "created_at": "2026-11-02T15:00:00.000Z",
  "sequence": 1793631600000000,
  "mode": "live",
  "data": { "campaign_id": "20b6b4d9-f321-41ef-aa5e-c1db05b559fd", "mode": "live", "dealer_id": "8f2b0e4c-5d6a-4b7c-9e8f-0a1b2c3d4e5f", "dealer_external_id": "dlr-1042", "template_code": "card_8_5x11_birthday", "template_version": 2, "envelope": "closed_face", "external_ref": "cmp_778", "metadata": { "program": "birthday" }, "creative_version": 2, "preflight_ok": true, "errors": 0, "warnings": 0 }
}
```

`quote.created`:

```json
{
  "id": "8e7d6c5b-4a39-4281-9f0e-1d2c3b4a5968",
  "type": "quote.created",
  "created_at": "2026-11-02T15:00:00.000Z",
  "sequence": 1793631600000000,
  "mode": "live",
  "data": { "campaign_id": "20b6b4d9-f321-41ef-aa5e-c1db05b559fd", "mode": "live", "dealer_id": "8f2b0e4c-5d6a-4b7c-9e8f-0a1b2c3d4e5f", "dealer_external_id": "dlr-1042", "template_code": "card_8_5x11_birthday", "template_version": 2, "envelope": "closed_face", "external_ref": "cmp_778", "metadata": { "program": "birthday" }, "quote_id": "0e0f8f4d-902c-40d1-ac8e-c47e14cb0758", "quantity": 4, "mail_class": "first_class", "total_cents": 616, "expires_at": "2026-11-09T15:00:00.000Z" }
}
```

`approval.requested`:

```json
{
  "id": "3c4d5e6f-7a8b-4c9d-8e0f-1a2b3c4d5e6f",
  "type": "approval.requested",
  "created_at": "2026-11-02T15:00:00.000Z",
  "sequence": 1793631600000000,
  "mode": "live",
  "data": { "campaign_id": "20b6b4d9-f321-41ef-aa5e-c1db05b559fd", "mode": "live", "dealer_id": "8f2b0e4c-5d6a-4b7c-9e8f-0a1b2c3d4e5f", "dealer_external_id": "dlr-1042", "template_code": "card_8_5x11_birthday", "template_version": 2, "envelope": "closed_face", "external_ref": "cmp_778", "metadata": { "program": "birthday" }, "approval_id": "96706396-e7df-4043-a724-a640c6e14f3a", "quote_id": "0e0f8f4d-902c-40d1-ac8e-c47e14cb0758", "total_cents": 616, "max_spend_cents": 2000, "expires_at": "2026-11-09T15:00:00.000Z", "delivery": "email" }
}
```

`approval.decided` (a rejection):

```json
{
  "id": "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d",
  "type": "approval.decided",
  "created_at": "2026-11-03T10:05:00.000Z",
  "sequence": 1793700300000000,
  "mode": "live",
  "data": { "campaign_id": "20b6b4d9-f321-41ef-aa5e-c1db05b559fd", "mode": "live", "dealer_id": "8f2b0e4c-5d6a-4b7c-9e8f-0a1b2c3d4e5f", "dealer_external_id": "dlr-1042", "template_code": "card_8_5x11_birthday", "template_version": 2, "envelope": "closed_face", "external_ref": "cmp_778", "metadata": { "program": "birthday" }, "approval_id": "96706396-e7df-4043-a724-a640c6e14f3a", "decision": "rejected", "decided_at": "2026-11-03T10:05:00.000Z", "has_note": true, "prescreen_attestation": null }
}
```

The amounts are pilot placeholders. The rejection note itself is never sent; only `has_note`. On an approved prescreened credit offer, `prescreen_attestation` is `{"required": true, "consumer_reporting_agency": "<as the piece names it>", "list_date": "2026-10-15", "confirmed_at": "2026-11-03T10:05:00.000Z"}`; on a rejected one, `list_date` and `confirmed_at` are null.

`campaign.results_updated` (a sandbox order; a live one has `"source": "updash"` and `"simulated": false`):

```json
{
  "id": "4b5c6d7e-8f90-4a1b-9c2d-3e4f5a6b7c8d",
  "type": "campaign.results_updated",
  "created_at": "2026-11-02T15:00:00.000Z",
  "sequence": 1793631600000000,
  "mode": "test",
  "data": {
    "campaign_id": "20b6b4d9-f321-41ef-aa5e-c1db05b559fd",
    "mode": "test",
    "dealer_id": "8f2b0e4c-5d6a-4b7c-9e8f-0a1b2c3d4e5f",
    "dealer_external_id": "dlr-1042",
    "template_code": "card_8_5x11_birthday",
    "template_version": 2,
    "envelope": "closed_face",
    "external_ref": "cmp_778",
    "metadata": { "program": "birthday" },
    "source": "sandbox",
    "simulated": true,
    "job": "SBX-20B6B4D9",
    "drops": [{ "drop_number": 1, "home_date": "2026-11-02", "project_status": "Completed", "quantity": 4 }],
    "delivery_percent": 98.1,
    "responses": { "leads": 2, "sms": 0, "web": 1, "calls": 0, "appointments": 2, "showroom_visits": 0, "facebook": 0, "qr_codes": 1, "total": 4, "unique_responders": 2 },
    "matched": { "sales": 1, "repair_orders": 0 },
    "leads_with_results": 2,
    "updated_at": "2026-11-02T15:00:00.000Z"
  }
}
```

`campaign.lead_results_updated`:

```json
{
  "id": "6d7e8f90-a1b2-4c3d-8e4f-5a6b7c8d9e0f",
  "type": "campaign.lead_results_updated",
  "created_at": "2026-11-02T15:00:00.000Z",
  "sequence": 1793631600000000,
  "mode": "test",
  "data": {
    "campaign_id": "20b6b4d9-f321-41ef-aa5e-c1db05b559fd",
    "mode": "test",
    "dealer_id": "8f2b0e4c-5d6a-4b7c-9e8f-0a1b2c3d4e5f",
    "dealer_external_id": "dlr-1042",
    "template_code": "card_8_5x11_birthday",
    "template_version": 2,
    "envelope": "closed_face",
    "external_ref": "cmp_778",
    "metadata": { "program": "birthday" },
    "changed_leads": 2,
    "leads_with_results": 2,
    "part": 1,
    "parts": 1,
    "leads": [
      { "external_id": "crm-1001", "row_key": "xmdr6kslk45b2rkegz" },
      { "external_id": "crm-1002", "row_key": "xmpksflhfx7fhctpdw" }
    ],
    "next_step": "Call get_campaign_results (leads) for their responses and matches."
  }
}
```

`campaign.usps_tracking_updated`:

```json
{
  "id": "0b1c2d3e-4f5a-4b6c-8d7e-9f0a1b2c3d4e",
  "type": "campaign.usps_tracking_updated",
  "created_at": "2026-11-28T06:40:12.000Z",
  "sequence": 1795848012000000,
  "mode": "live",
  "data": {
    "campaign_id": "20b6b4d9-f321-41ef-aa5e-c1db05b559fd",
    "mode": "live",
    "dealer_id": "8f2b0e4c-5d6a-4b7c-9e8f-0a1b2c3d4e5f",
    "dealer_external_id": "dlr-1042",
    "template_code": "postcard_6x9_we_missed_you",
    "template_version": 3,
    "envelope": null,
    "external_ref": "cmp_778",
    "metadata": {},
    "changed_pieces": 2,
    "part": 1,
    "parts": 1,
    "pieces": [
      { "external_id": "crm-1001", "row_key": "xmdr6kslk45b2rkegz", "stage": "in_transit", "stage_at": "2026-11-26T15:02:40.000Z" },
      { "external_id": "crm-1002", "row_key": "xmpksflhfx7fhctpdw", "stage": "processed_for_delivery", "stage_at": "2026-11-27T23:21:46.000Z" }
    ],
    "next_step": "Call GET /v1/campaigns/{id}/leads for each piece's usps tracking: scans, times and the last facility."
  }
}
```

`external_id` is `null` for a row your file gave none.

## Verify the signature

`X-Xcel-Signature` is `t=<unix seconds>,v1=<hex>`, where `v1` is the HMAC-SHA256 of the string `<t>.<raw request body>`, keyed with the endpoint's full secret (including the `whsec_` prefix). To verify:

1. Read the raw body bytes before any JSON parsing. Re-serialized JSON will not match.
2. Split the header on `,` and each part on the first `=`.
3. Reject when `t` is more than 300 seconds from your clock.
4. Compute the HMAC and compare it with `v1` in constant time.

Test vector: the delivery shown in [The delivery](#the-delivery) is signed with the secret `whsec_AX_nNsI4BlRvh8n6i_EOz1JpTmRbUg5s`. With the timestamp check turned off, your verifier must accept that body and header, and reject the body with one character changed.

### Node.js

```js
import crypto from "node:crypto";
import express from "express";

// Returns true when the X-Xcel-Signature header matches the raw request body.
export function verifyXcelSignature(secret, header, rawBody, toleranceSeconds = 300) {
  if (!header) return false;
  const parts = {};
  for (const pair of header.split(",")) {
    const i = pair.indexOf("=");
    if (i > 0) parts[pair.slice(0, i).trim()] = pair.slice(i + 1).trim();
  }
  const t = Number(parts.t);
  if (!Number.isInteger(t) || !parts.v1) return false;
  if (Math.abs(Math.floor(Date.now() / 1000) - t) > toleranceSeconds) return false;
  const expected = crypto.createHmac("sha256", secret).update(`${t}.${rawBody}`).digest("hex");
  const a = Buffer.from(expected);
  const b = Buffer.from(parts.v1);
  return a.length === b.length && crypto.timingSafeEqual(a, b);
}

const app = express();
app.post("/xcel/webhooks", express.raw({ type: "application/json" }), (req, res) => {
  const raw = req.body.toString("utf8");
  if (!verifyXcelSignature(process.env.XCEL_WEBHOOK_SECRET, req.get("X-Xcel-Signature"), raw)) {
    return res.status(400).send("bad signature");
  }
  const event = JSON.parse(raw);
  // Queue the work, de-duplicated on event.id, then answer quickly.
  res.status(204).end();
});
```

### Python

```python
import hashlib
import hmac
import time


def verify_xcel_signature(secret: str, header: str, raw_body: bytes, tolerance: int = 300) -> bool:
    """Return True when the X-Xcel-Signature header matches the raw request body."""
    parts = dict(p.strip().split("=", 1) for p in (header or "").split(",") if "=" in p)
    try:
        t = int(parts["t"])
    except (KeyError, ValueError):
        return False
    v1 = parts.get("v1")
    if not v1 or abs(int(time.time()) - t) > tolerance:
        return False
    expected = hmac.new(secret.encode(), f"{t}.".encode() + raw_body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, v1)


# Flask example
# @app.post("/xcel/webhooks")
# def xcel_webhook():
#     if not verify_xcel_signature(os.environ["XCEL_WEBHOOK_SECRET"], request.headers.get("X-Xcel-Signature", ""), request.get_data()):
#         abort(400)
#     event = request.get_json()
#     return "", 204
```

### PHP

```php
<?php
// Returns true when the X-Xcel-Signature header matches the raw request body.
function verify_xcel_signature(string $secret, string $header, string $rawBody, int $tolerance = 300): bool
{
    $parts = [];
    foreach (explode(',', $header) as $pair) {
        $kv = explode('=', trim($pair), 2);
        if (count($kv) === 2) {
            $parts[$kv[0]] = $kv[1];
        }
    }
    if (!isset($parts['t'], $parts['v1']) || !ctype_digit($parts['t'])) {
        return false;
    }
    $t = (int) $parts['t'];
    if (abs(time() - $t) > $tolerance) {
        return false;
    }
    $expected = hash_hmac('sha256', $t . '.' . $rawBody, $secret);
    return hash_equals($expected, $parts['v1']);
}

$raw = file_get_contents('php://input');
$header = $_SERVER['HTTP_X_XCEL_SIGNATURE'] ?? '';
if (!verify_xcel_signature(getenv('XCEL_WEBHOOK_SECRET'), $header, $raw)) {
    http_response_code(400);
    exit;
}
$event = json_decode($raw, true);
http_response_code(204);
```

All three functions were checked against signatures made by the server's signing code.

## Delivery and retries

- Answer with any 2xx status within 5 seconds. Anything else, a timeout, a connection error or a redirect counts as a failure. Redirects are not followed.
- Delivery is attempted right after the HTTP request that caused the event (REST approval requests, audience completion, proofs, submits, sandbox advances, dealer and profile writes, logo uploads, imports, review-page decisions, ops actions on the ops dashboard, and every MCP tool that writes), and by a scheduled job every 5 minutes that picks up everything else: events from creative and quote requests over REST, changes Xcel makes from its admin tool, and the results and status events from the UpDash poller.
- A failed delivery is retried after 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours and 24 hours: seven attempts over about 33 hours. These are the earliest times; a retry goes out on the next delivery run after it falls due, so it can wait up to 5 minutes more. After the seventh failure the delivery is marked failed and not retried.
- Before every attempt the host is resolved and checked again. If it now points at a non-public address, the attempt fails and is retried on the same schedule.
- Each attempt is claimed before it is sent: the delivery run takes a lease on the delivery and counts the attempt in one database step, so two runs (the scheduled job and the after-request attempt, or two job runs) never send the same delivery at once. If a run stops mid-send, the delivery becomes due again when its lease runs out: 3 minutes for an after-request run, about 11 minutes for a scheduled run.
- Delivery is still at least once: a timeout after your server processed the event, or a run that stopped after your server answered, leads to another attempt. De-duplicate on `X-Xcel-Event-Id` (the same value as the body's `id`), and store the ids you have processed.
- Each run takes live deliveries first, then takes turns across partners (each partner's oldest first), so one partner's backlog of slow sandbox endpoints cannot hold back other partners' live deliveries. A run works on up to 4 endpoints at a time, live ones first.
- Each endpoint gets its deliveries one at a time, oldest event first. After one fails, its later deliveries wait for the next run, with no attempt counted, so a dead endpoint costs one try a run. Only a retry can arrive after a newer event, so do not rely on arrival order: compare `sequence`, then `created_at` and `id` when two tie, or fetch `GET /v1/campaigns/{id}` for the current state.
- `campaign.results_updated` is a full snapshot of the totals. Keep the newest, by `sequence`, then `created_at` and `id`; never add them up, since a count can fall when a match is withdrawn. `changed_leads` on `campaign.lead_results_updated` counts the leads changed in that update, and a later update can name the same lead again.
- Xcel stores only the last status code or error class per delivery, never your response body.
- Deactivating an endpoint (`DELETE /v1/webhooks/{id}`) cancels its pending deliveries. A delivery that falls due for an endpoint that is no longer active is marked failed without being sent.

## Reconcile a window you missed

`GET /v1/events` lists your events for a time window, whether or not an endpoint was registered then. It needs no webhook.

```bash
curl -s "$API/v1/events?since=2026-11-01&until=2026-11-02&dealer_id=dlr-1042&limit=100" \
  -H "Authorization: Bearer $KEY"
```

```json
{ "events": [ { "id": "...", "type": "campaign.status_changed", "created_at": "2026-11-01T15:00:00.000Z", "sequence": 1793545200000000, "mode": "live", "data": { "campaign_id": "...", "dealer_id": "...", "to": "at_usps" } } ], "has_more": true, "next_cursor": "..." }
```

| Query | Meaning |
| --- | --- |
| `since` | Events at or after this time: a date-time with a time zone, or a date (midnight UTC). |
| `until` | Events before this time, in the same form. Windows that share an edge neither repeat nor miss an event. |
| `dealer_id` | Only this dealer's events: Xcel's id or your `external_id`. Another partner's dealer answers 404. |
| `type` | Only this [event type](#event-types). |
| `limit` | Most events per page, 1 to 100, default 50. |
| `starting_after` | `next_cursor` from the previous page, with the same filters. |

- Each item is the [body a webhook delivers](#the-delivery), oldest first. It is your events only, in your key's mode: a sandbox key reads test campaigns, a live key live campaigns. `dealer.updated` reads in both modes with your key's `mode`, except a test dealer's, which only a sandbox key reads.
- Every type in [Event types](#event-types) is here. `webhook.test` pings are not stored, and the campaign timeline's own ops and retention entries are not part of this list.
- Go by `next_cursor`, not by the page's length: a page of large events stops before `limit`. `has_more` is false on the last page.
- An event can commit a moment after its `created_at`. Read up to a minute or two before now, or overlap your windows, and drop duplicates by `id`.
- `sequence` here is read from `created_at`, so two events in one millisecond share one, and it can sit milliseconds below what a webhook delivered for the same event. Compare values from one source only, and match a webhook to this list by event `id`. List order is the order.
- Retention deletes an order's row keys and per-lead results, not its events: an old `campaign.lead_results_updated` still names the ids it named. MCP has no tool for this list.

## Polling instead

Without a webhook, poll `GET /v1/campaigns/{id}` and read `campaign.status`, `latest_approval.status` and `next_step`, or `GET /v1/campaigns/{id}/results` for the timeline and the results. Live results change at most every 6 hours, so polling more often gains nothing.
