> Documentation index: https://docs.bannerandbooth.com/llms.txt · MCP: https://mcp.bannerandbooth.com/mcp · Search: https://docs.bannerandbooth.com/search?q=

# Webhooks

Source: https://docs.bannerandbooth.com/guides/webhooks

Set `notify_url` when you create an order and Banner & Booth POSTs a JSON event to it whenever something happens on that order: payment, artwork, proofs, production, shipping, cancellation. Webhooks are optional. Polling `GET /v1/orders/{id}` works without them.

> **Note:** Webhooks are best effort with **one attempt** each. There are no retries. Treat a webhook as a hint to check the order, always confirm with `GET /v1/orders/{id}`, and keep a slow poll running as a backstop.

## Turn them on

Pass `notify_url` (an `https` URL you control) on `POST /v1/orders` or `create_order`. The create response then includes a `webhook_secret` alongside the `order_key`. Both appear only in this response.

```bash curl
curl -s https://api.bannerandbooth.com/v1/orders \
  -H "Content-Type: application/json" \
  -d '{
    "items": [{ "sku": "BB-KIT-1010A", "quantity": 1 }],
    "notify_url": "https://example.com/hooks/bannerandbooth",
    "test": true
  }' | jq '{id, order_key, webhook_secret}'
```

```json Response
{
  "id": "bbo_test_8k2m4q7xvd",
  "order_key": "bbk_test_5f1c9a7e3b2d8f604c1e9a7b3d5f2c8e",
  "webhook_secret": "whsec_9a3e5c7b1d2f4a6c8e0b2d4f6a8c0e1d"
}
```

`webhook_secret` (`whsec_<32 hex>`) signs every webhook for this order. It's separate from the `order_key`: give your webhook receiver the secret, and it never needs the key. Store it by order id.

## Event payload

```json
{
  "id": "evt_5k2m8q4xvd7n",
  "type": "proof.ready",
  "order_id": "bbo_test_veceqxd96t",
  "mode": "test",
  "created_at": "2026-12-01T03:54:25.120Z",
  "data": {
    "proof_id": "prf_t6cycxx4jk",
    "kind": "human",
    "sku": "BB-KIT-1010A",
    "url": "https://api.bannerandbooth.com/p/40429c7e4bd1d509908681d28fe24e1f"
  }
}
```

| Field | Meaning |
|---|---|
| `id` | Unique event id, `evt_` + 12 characters. Use it to ignore duplicates. |
| `type` | One of the event types below. |
| `order_id` | The order the event is about. |
| `mode` | `test` or `live`. |
| `created_at` | When it was sent (UTC, ISO 8601 with milliseconds). |
| `data` | Details for the event type. Useful for logging; fetch the order before acting. |

Requests are `POST` with `Content-Type: application/json` and `User-Agent: BannerAndBooth-Webhooks/1.0`. The payload doesn't include the order's status: read it with `GET /v1/orders/{id}`.

## Event types

| `type` | Sent when | `data` | Typical next step |
|---|---|---|---|
| `order.paid` | The buyer paid. | `order_number` | Confirm, then tell the buyer it's paid and what's next. |
| `order.updated` | An unpaid order was changed with `PATCH` or `update_order`. | `fields` (the names of the changed fields) | Re-read totals and the payment link. |
| `artwork.received` | A file, logo or design brief was added for a SKU. | `artwork_id`, `sku`, `role` (`artwork`, `logo` or `brief`), `preflight` (verdict or `null`) | Nothing; a proof follows. |
| `proof.ready` | An automatic preview or a prepress proof is ready. | `proof_id`, `kind` (`auto_preview` or `human`), `sku`, `url` | Show it to the buyer. |
| `proof.approved` | A proof was approved (by anyone with the key). | `proof_id`, `sku` | Confirm it was the buyer's decision. |
| `proof.changes_requested` | Changes were requested on a proof. | `proof_id`, `sku` | Wait for the next version. |
| `order.in_production` | Printing started. | | Tell the buyer the production window. |
| `order.shipped` | The order shipped. Sent as soon as Shopify records the shipment. | `tracking` | Send the tracking link. |
| `order.delivered` | The carrier reported delivery. | `tracking` | Done. |
| `order.cancelled` | An unpaid order was cancelled. | | Stop. |

On test orders, events caused by `simulate` have `"data": { "simulated": true }`.

## Signature

Every webhook has a `BB-Signature` header:

```text
BB-Signature: t=1796097265,v1=3160518fa61f70e6408c850be4ef8fe555a1a16226b9c99a232eac09bd6695c5
```

- `t` is the Unix time (seconds) when it was signed.
- `v1` is the hex HMAC-SHA256 of the string `"<t>.<raw body>"`, keyed with the order's `webhook_secret` (the full string, including `whsec_`).

To verify:

1. Read the **raw** request body bytes. Don't parse and re-serialize the JSON first; any whitespace change breaks the signature.
2. Split the header on `,` and each part on the first `=`. Take `t` and every `v1`.
3. Reject if `t` is more than 5 minutes from your clock. This blocks replayed requests.
4. Parse the body to read `order_id`, and look up that order's `webhook_secret`. The `order_id` isn't trusted yet; it only picks the secret.
5. Compute `HMAC-SHA256(secret, t + "." + raw_body)` as hex.
6. Compare it to each `v1` with a constant-time comparison. Accept if any match.
7. Ignore events whose `id` you've already processed.
8. Respond `2xx` quickly, then do the work. Confirm the state with `GET /v1/orders/{id}`.

## Verify in Python

Standard library only. Save as `webhook_receiver.py`, put your secrets in `webhook_secrets.json` as `{"<order_id>": "<webhook_secret>"}` (or set `BB_WEBHOOK_SECRET` for a single order), then run `python3 webhook_receiver.py`. It listens on port 8000.

```python Python
import hashlib, hmac, json, os, time
from http.server import BaseHTTPRequestHandler, HTTPServer

TOLERANCE_SECONDS = 300
SECRETS = json.load(open("webhook_secrets.json")) if os.path.exists("webhook_secrets.json") else {}
seen_event_ids = set()


def secret_for(order_id):
    return SECRETS.get(order_id) or os.environ.get("BB_WEBHOOK_SECRET")


def verify(raw_body: bytes, header: str, secret: str, now: float = None) -> bool:
    pairs = [p.strip().split("=", 1) for p in header.split(",") if "=" in p]
    timestamp = next((v for k, v in pairs if k == "t"), "")
    signatures = [v for k, v in pairs if k == "v1"]
    if not timestamp.isdigit() or not signatures:
        return False
    if abs((time.time() if now is None else now) - int(timestamp)) > TOLERANCE_SECONDS:
        return False
    expected = hmac.new(secret.encode(), timestamp.encode() + b"." + raw_body, hashlib.sha256).hexdigest()
    return any(hmac.compare_digest(expected, s) for s in signatures)


class Handler(BaseHTTPRequestHandler):
    def do_POST(self):
        raw = self.rfile.read(int(self.headers.get("Content-Length", 0)))
        try:
            event = json.loads(raw)
        except ValueError:
            return self.reply(400)
        secret = secret_for(event.get("order_id", ""))
        if not secret or not verify(raw, self.headers.get("BB-Signature", ""), secret):
            return self.reply(400)
        if event["id"] not in seen_event_ids:
            seen_event_ids.add(event["id"])
            print("verified", event["type"], event["order_id"], event["mode"])
            # Next: GET /v1/orders/{order_id} with the order key, then act on next_actions.
        self.reply(200)

    def reply(self, code):
        self.send_response(code)
        self.end_headers()


if __name__ == "__main__":
    HTTPServer(("", 8000), Handler).serve_forever()
```

## Verify in Node

Node 18+, no dependencies. Save as `webhook_receiver.mjs`, set up `webhook_secrets.json` or `BB_WEBHOOK_SECRET` the same way, then run `node webhook_receiver.mjs`.

```javascript Node
import { createServer } from "node:http";
import { createHmac, timingSafeEqual } from "node:crypto";
import { existsSync, readFileSync } from "node:fs";

const TOLERANCE_SECONDS = 300;
const SECRETS = existsSync("webhook_secrets.json") ? JSON.parse(readFileSync("webhook_secrets.json", "utf8")) : {};
const seenEventIds = new Set();

const secretFor = (orderId) => SECRETS[orderId] ?? process.env.BB_WEBHOOK_SECRET;

export function verify(rawBody, header, secret, now = Date.now() / 1000) {
  const pairs = header.split(",").filter((p) => p.includes("=")).map((p) => {
    const i = p.indexOf("=");
    return [p.slice(0, i).trim(), p.slice(i + 1).trim()];
  });
  const timestamp = pairs.find(([k]) => k === "t")?.[1] ?? "";
  const signatures = pairs.filter(([k]) => k === "v1").map(([, v]) => v);
  if (!/^\d+$/.test(timestamp) || signatures.length === 0) return false;
  if (Math.abs(now - Number(timestamp)) > TOLERANCE_SECONDS) return false;
  const expected = createHmac("sha256", secret).update(`${timestamp}.`).update(rawBody).digest();
  return signatures.some((s) => {
    const given = Buffer.from(s, "hex");
    return given.length === expected.length && timingSafeEqual(given, expected);
  });
}

const server = createServer((req, res) => {
  const chunks = [];
  req.on("data", (c) => chunks.push(c));
  req.on("end", () => {
    const raw = Buffer.concat(chunks);
    let event;
    try {
      event = JSON.parse(raw.toString("utf8"));
    } catch {
      res.writeHead(400).end();
      return;
    }
    const secret = secretFor(event.order_id ?? "");
    if (!secret || !verify(raw, req.headers["bb-signature"] ?? "", secret)) {
      res.writeHead(400).end();
      return;
    }
    if (!seenEventIds.has(event.id)) {
      seenEventIds.add(event.id);
      console.log("verified", event.type, event.order_id, event.mode);
      // Next: GET /v1/orders/{order_id} with the order key, then act on next_actions.
    }
    res.writeHead(200).end();
  });
});

if (import.meta.url === `file://${process.argv[1]}`) server.listen(8000);
```

## Test your verifier

This is a real signature. Your `verify` function should return `true` for it when you pass `now` equal to `t` (so the 5-minute window doesn't reject an old example), and `false` if you change a single byte of the body.

```text
webhook_secret  whsec_9a3e5c7b1d2f4a6c8e0b2d4f6a8c0e1d
t               1796097265
body (280 bytes, no trailing newline):
{"id":"evt_5k2m8q4xvd7n","type":"proof.ready","order_id":"bbo_test_veceqxd96t","mode":"test","created_at":"2026-12-01T03:54:25.120Z","data":{"proof_id":"prf_t6cycxx4jk","kind":"human","sku":"BB-KIT-1010A","url":"https://api.bannerandbooth.com/p/40429c7e4bd1d509908681d28fe24e1f"}}
BB-Signature    t=1796097265,v1=3160518fa61f70e6408c850be4ef8fe555a1a16226b9c99a232eac09bd6695c5
```

```python Python
from webhook_receiver import verify

secret = "whsec_9a3e5c7b1d2f4a6c8e0b2d4f6a8c0e1d"
body = b'{"id":"evt_5k2m8q4xvd7n","type":"proof.ready","order_id":"bbo_test_veceqxd96t","mode":"test","created_at":"2026-12-01T03:54:25.120Z","data":{"proof_id":"prf_t6cycxx4jk","kind":"human","sku":"BB-KIT-1010A","url":"https://api.bannerandbooth.com/p/40429c7e4bd1d509908681d28fe24e1f"}}'
header = "t=1796097265,v1=3160518fa61f70e6408c850be4ef8fe555a1a16226b9c99a232eac09bd6695c5"

assert verify(body, header, secret, now=1796097265)
assert not verify(body.replace(b"proof.ready", b"proof.READY"), header, secret, now=1796097265)
assert not verify(body, header, secret, now=1796097265 + 301)
print("ok")
```

```javascript Node
import { verify } from "./webhook_receiver.mjs";

const secret = "whsec_9a3e5c7b1d2f4a6c8e0b2d4f6a8c0e1d";
const body = Buffer.from('{"id":"evt_5k2m8q4xvd7n","type":"proof.ready","order_id":"bbo_test_veceqxd96t","mode":"test","created_at":"2026-12-01T03:54:25.120Z","data":{"proof_id":"prf_t6cycxx4jk","kind":"human","sku":"BB-KIT-1010A","url":"https://api.bannerandbooth.com/p/40429c7e4bd1d509908681d28fe24e1f"}}');
const header = "t=1796097265,v1=3160518fa61f70e6408c850be4ef8fe555a1a16226b9c99a232eac09bd6695c5";

console.assert(verify(body, header, secret, 1796097265) === true, "valid signature");
console.assert(verify(Buffer.from(body.toString().replace("proof.ready", "proof.READY")), header, secret, 1796097265) === false, "tampered body");
console.assert(verify(body, header, secret, 1796097265 + 301) === false, "too old");
console.log("ok");
```

Save the Python test next to `webhook_receiver.py` and the Node test next to `webhook_receiver.mjs`, as `test_verify.py` and `test_verify.mjs`.

## Send a test webhook

Create a test order with `notify_url`, then simulate events. Each one sends a real, signed webhook to your URL:

```bash curl
curl -s -X POST "https://api.bannerandbooth.com/v1/orders/$BB_ORDER_ID/simulate" \
  -H "Authorization: Bearer $BB_ORDER_KEY" -H "Content-Type: application/json" \
  -d '{"event":"proof_ready"}'
```

To receive webhooks on your laptop, expose the local port with any HTTPS tunnel and use the tunnel's URL as `notify_url`.

## Good practice

- **Respond fast.** Return `200` before doing slow work. There's only one attempt.
- **Don't trust the payload's state.** Fetch the order and use its `status` and `next_actions`.
- **Dedupe by `id`.** Store processed event ids.
- **Poll as a backstop.** If your receiver was down, you missed the event. A poll every few hours catches up.
- **Keep secrets per order.** A leaked `webhook_secret` only lets someone forge webhooks for that one order, and your receiver confirms everything with `GET` anyway.

## Related

- [Ordering: the loop](https://docs.bannerandbooth.com/guides/ordering#drive-the-loop)
- [Test mode](https://docs.bannerandbooth.com/guides/test-mode)
- [API reference: create an order](https://docs.bannerandbooth.com/reference/api#create-an-order)
