# Webhook routes

The routes that manage where Maxy sends signed `order.updated` events: register an endpoint, list them, send a test, read and replay past events, and stop sending. How to verify an event and what it carries is on [Webhooks](https://maxy.co/docs/webhooks). Every route here takes your secret key; a test key's endpoints get the sandbox's events. The samples use `BASE` and `MAXY_API_KEY` from [Get a price](https://maxy.co/docs/buy-btc#get-a-price), and `WEBHOOK_URL`, your HTTPS endpoint. The answers are real sandbox answers, trimmed.

## POST /webhooks

Registers an HTTPS endpoint on a public host. The answer carries the signing secret, `whsec_…`, once: store it. A key has at most five endpoints.

| Field | Required | Meaning |
| --- | --- | --- |
| `url` | yes | A full `https://` URL. Not `localhost`, and not a private or link-local address |

```sh
curl -s -X POST "$BASE/webhooks" -H "x-maxy-key: $MAXY_API_KEY" -H "content-type: application/json" \
  -d '{ "url": "'"$WEBHOOK_URL"'" }' > hook.json
WEBHOOK_ID=$(jq -r .id hook.json)
```

```json
{
  "id": "0dc33337-7b15-45fa-8174-d3be5e664e34",
  "url": "https://postman-echo.com/post",
  "events": ["order.updated"],
  "secret": "whsec_…",
  "createdAt": "2026-11-20T01:17:51.37511+00:00",
  "sandbox": true
}
```

Answers `201`. A sixth endpoint answers `409 conflict`; a URL that is not HTTPS on a public host answers `400 invalid_input`. To test on a laptop without a public URL: `npx -p maxy-labs maxy webhooks listen --forward-to http://localhost:3000/maxy/webhooks` ([Command line](https://maxy.co/docs/command-line)).

## GET /webhooks

Your endpoints, without their secrets.

```sh
curl -s -H "x-maxy-key: $MAXY_API_KEY" "$BASE/webhooks"
```

```json
{ "webhooks": [{ "id": "0dc33337-7b15-45fa-8174-d3be5e664e34", "url": "https://postman-echo.com/post", "events": ["order.updated"], "createdAt": "2026-11-20T01:17:51.37511+00:00" }], "sandbox": true }
```

## POST /webhooks/{id}/test

Sends a signed `webhook.test` event to the endpoint now, and says what it answered. Use it to check your verifier before any order exists.

```sh
curl -s -X POST -H "x-maxy-key: $MAXY_API_KEY" "$BASE/webhooks/$WEBHOOK_ID/test"
```

```json
{ "eventId": "evt_0819a79b54d27d044e98cff8", "delivered": true, "status": 200, "error": null, "sandbox": true }
```

## GET /webhooks/{id}/events

The endpoint's last 25 order events, with each delivery's attempts and the answer your endpoint gave. With `?signed=1`, each event also carries `delivery`: its raw body and a signature made now, so you can replay it into a local server that checks `Maxy-Signature`.

```sh
curl -s -H "x-maxy-key: $MAXY_API_KEY" "$BASE/webhooks/$WEBHOOK_ID/events"
```

```json
{
  "events": [
    {
      "id": "evt_a6d16d204ed9110c8e079d6d",
      "type": "order.updated",
      "createdAt": "2026-11-20T01:18:31.009+00:00",
      "attempts": 0,
      "deliveredAt": null,
      "failedAt": null,
      "lastStatus": null,
      "lastError": null,
      "data": { "orderId": "0x53414e44424f588359cb23e9…", "state": "in_progress", "previousState": "pending", "btcTxId": null, "…": "…" }
    },
    "…"
  ],
  "sandbox": true
}
```

## POST /webhooks/{id}/events/{eventId}/replay

Sends a past event again now, with the same event id and a new signature. Use it after your endpoint was down, or to test your duplicate check.

```sh
EVENT_ID=$(curl -s -H "x-maxy-key: $MAXY_API_KEY" "$BASE/webhooks/$WEBHOOK_ID/events" | jq -r '.events[0].id')
curl -s -X POST -H "x-maxy-key: $MAXY_API_KEY" "$BASE/webhooks/$WEBHOOK_ID/events/$EVENT_ID/replay"
```

```json
{ "eventId": "evt_a6d16d204ed9110c8e079d6d", "replayed": true, "delivered": true, "status": 200, "error": null, "sandbox": true }
```

## DELETE /webhooks/{id}

Stops sending to an endpoint. Do this first if its secret leaks, then register a new one.

```sh
curl -s -X DELETE -H "x-maxy-key: $MAXY_API_KEY" "$BASE/webhooks/$WEBHOOK_ID"
```

```json
{ "deleted": true, "id": "0dc33337-7b15-45fa-8174-d3be5e664e34", "sandbox": true }
```

## Deliveries

| | |
| --- | --- |
| Events | `order.updated`: each change of `state` or `btcTxId`, and a completed buy's first Bitcoin confirmation (`btcConfirmations` 1). `order.payment_replaced`: a completed order's Bitcoin payment replaced before it confirmed (`previousBtcTxId` names the old one). `webhook.test`: only from `POST /webhooks/{id}/test`. All for orders placed with your key or followed with `POST /orders/watch` |
| Request | `POST` with a JSON body `{ id, type, createdAt, data }`, and the headers `Maxy-Signature`, `Maxy-Event-Id`, `Maxy-Event-Type` and `User-Agent: Maxy-Webhooks/1` |
| Signature | `Maxy-Signature: t=<unix seconds>,v1=<hex>`, where `v1` is HMAC-SHA256 of `<t>.<raw body>` with the endpoint's secret |
| Your answer | Any `2xx` within 10 seconds |
| Retries | 8 more tries after a failure, at 30 seconds, 2, 10 and 30 minutes, then 1, 3, 6 and 12 hours |
| Order | At least once, and not always in order: dedupe on `id`, order by `createdAt` |

The OpenAPI document describes the event under `webhooks`: [OpenAPI document](https://maxy.co/docs/openapi-document).

## Errors

| HTTP | `code` | When |
| --- | --- | --- |
| 400 | `invalid_input` | A URL that is not HTTPS on a public host |
| 401 | `auth_required`, `invalid_api_key` | No key, or a key Maxy did not issue |
| 403 | `scope_denied` | A publishable key: webhooks take the secret key |
| 404 | `not_found` | No endpoint or event with that id for this key |
| 409 | `conflict` | A sixth endpoint |

## A delivered event

One whole request as your endpoint receives it (the published test vector's, so the signature checks):

```json
{
  "secret": "whsec_maxy_test_vector_not_a_real_secret_000000",
  "timestamp": 1793644197,
  "body": "{\"id\":\"evt_92c8c63c194b601ce42da1a3\",\"type\":\"order.updated\",\"createdAt\":\"2026-11-02T18:29:57.000Z\",\"data\":{\"orderId\":\"0xed3985cf8b6dcc9a30448c9faaefbaf3a2f2ef9c06f50ce1f46dd955212ce2ea\",\"route\":\"evm-btc-gasless\",\"chainId\":8453,\"state\":\"completed\",\"previousState\":\"in_progress\",\"rawStatus\":\"SETTLED\",\"isComplete\":true,\"btcTxId\":\"6afc6d649cef90d92d8413ccc12aeb14945c92e5b63db9724cf12b6ef985ea3f\",\"txs\":[{\"label\":\"escrow\",\"hash\":\"0xf103819940fef19e88f9c0eafb24a52bad8de86c277e18e8e2e60a8594c7f8d1\"},{\"label\":\"btc_payout\",\"hash\":\"6afc6d649cef90d92d8413ccc12aeb14945c92e5b63db9724cf12b6ef985ea3f\"},{\"label\":\"settlement\",\"hash\":\"0xef66f624a34cff33a5d5660e1666e15669bc02dfc8b0a27fa827e8b268e702f2\"}]}}",
  "headers": {
    "content-type": "application/json",
    "user-agent": "Maxy-Webhooks/1",
    "maxy-event-id": "evt_92c8c63c194b601ce42da1a3",
    "maxy-event-type": "order.updated",
    "maxy-signature": "t=1793644197,v1=3dcfb13254225870c0d80924d3a267d926286c09d26fb054358bb793361aaf68"
  }
}
```

Check it with ten lines of Node, before you parse the body:

```js
import { createHmac, timingSafeEqual } from 'node:crypto';

// rawBody: the request body as bytes, before any JSON parsing; secret: the endpoint's whsec_… secret
export function verify(rawBody, header, secret, now = Math.floor(Date.now() / 1000)) {
  const { t, v1 } = Object.fromEntries(header.split(',').map((kv) => kv.split('=')));
  if (!t || !v1 || Math.abs(now - Number(t)) > 300) return false;
  const want = createHmac('sha256', secret).update(`${t}.${rawBody}`).digest();
  const got = Buffer.from(v1, 'hex');
  return got.length === want.length && timingSafeEqual(got, want);
}
```

Every field of `data`: [Webhooks](https://maxy.co/docs/webhooks#event-fields).

---
Source: https://maxy.co/docs/webhook-routes (Maxy Docs › API reference › Routes)
