---
title: "Webhooks & events"
description: "Subscribe to EdgeCart events, verify signatures, and handle retries."
---

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

# Webhooks & events

Webhooks deliver commerce events to systems you control. EdgeCart writes events
to the outbox in the same transaction as the change, and the outbox Worker
delivers them asynchronously.

## Create an endpoint

Use the Admin API:

```http
POST /api/webhook-endpoints
Content-Type: application/json

{
  "url": "https://example.com/hooks/edgecart",
  "events": ["order.created", "payment.captured"]
}
```

Use exact event names, or `["*"]` for all events. Patterns such as `order.*` are
not supported.

Rotate the signing secret with:

```http
POST /api/webhook-endpoints/:id/rotate-secret
```

Inspect delivery attempts with `GET /api/webhook-deliveries`.

## Verify the signature

Each delivery carries:

```text
x-edgecart-signature: t=<timestamp>,v1=<hmac>
```

The HMAC is SHA-256 over `<timestamp>.<raw body>`. Use the raw request body, not
a parsed and re-serialized object.

```ts
import { createHmac, timingSafeEqual } from "node:crypto";

function verify(rawBody: string, header: string, secret: string) {
  const parts = Object.fromEntries(
    header.split(",").map((part) => part.split("=") as [string, string]),
  );
  const expected = createHmac("sha256", secret)
    .update(`${parts.t}.${rawBody}`)
    .digest("hex");
  return timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1));
}
```

In a Worker, use `crypto.subtle.importKey` and `crypto.subtle.sign` instead.

## Retries and deactivation

- Delivery is **at least once**. Deduplicate by event ID in the payload.
- Failed deliveries retry with backoff. The queue retries five times before the
  dead-letter queue.
- A `410 Gone` response deactivates the endpoint.
- Return a 2xx quickly; do slow work asynchronously.

> **Only subscribe endpoints you control**
>
> Webhook URL validation is lexical. A hostname that resolves to a private or
> loopback address, including DNS rebinding, cannot be detected inside the
> Workers runtime.

## Events

EdgeCart emits events for orders, payments, fulfillments, order changes, and
promotion/campaign changes. Plugin async hooks (`order:created`, `order:paid`,
`order:fulfilled`, `order:cancelled`, `refund:created`) use the same outbox.

See the [event catalog](https://edgecart.dev/reference/events) for the full list, and the
[Observability module](https://edgecart.dev/modules/observability) for the delivery model.

## Related

- [API conventions](https://edgecart.dev/reference/api-conventions)
- [Understand the Observability module](https://edgecart.dev/modules/observability)
- [Deployment](https://edgecart.dev/developers/deployment)

Source: https://edgecart.dev/developers/webhooks/index.mdx
