Developers

Webhooks

Let your own systems know the moment something changes in a Hand-Off store: an order is placed or paid, a customer signs up, a product or its stock changes.

What a webhook is

A webhook endpoint is an address on your server. When an event it subscribes to happens in the store, Hand-Off sends it an HTTPS POST with a JSON body describing the change, signed so you can check it came from Hand-Off. Your server answers 2xx to say it got it.

Use them to update a warehouse, an accounting tool, a CRM or a chat channel without polling the API.

Add an endpoint

  1. In the Hand-Off dashboard or the Hand-Off Vendor app, open Settings → Webhooks for the store.
  2. Choose Add endpoint, enter your address, pick the events and, if you like, a description.
  3. Copy the signing secret (it starts with whsec_) and keep it on your server. It is shown once; if you lose it, rotate it.
  4. Choose Send test event to check your server receives and verifies a delivery.
  • Who can: members with the store permission to manage webhooks (store:webhook:manage) add, change, pause, delete and test endpoints and rotate secrets. Members who can only read webhooks (store:webhook:read) see the endpoints and their delivery log.
  • The address must be https:// on port 443, with a public host name: not an IP address, not a private or internal name, no user name or password in it. Hand-Off checks it when you save it and again before every delivery.
  • Up to 10 endpoints per store.
  • A connected AI can do the same through the MCP tools, with the member’s permissions; an owner approves every new endpoint, and every change to an endpoint’s address or events. The routes are in the REST reference.

Webhooks are rolling out. If Settings doesn’t show Webhooks for your store yet, they aren’t switched on for it.

Event types

The list of event types isn’t available right now. It is read from the running Hand-Off API and will appear here when the API can be reached. The guides on the other pages don’t depend on it.

  • webhook.test is what Send test event sends. Nobody subscribes to it, it holds no store data, and it goes to a paused endpoint too.
  • New event types are added over time, and an event can be listed before the store starts sending it. Answer 2xx to a type you don’t handle.

The payload

Every delivery is one JSON object, the envelope:

Body (a test event)
{
  "id": "evt_3kQx7cV0bN2mRt9yLp4wZa1s",
  "type": "webhook.test",
  "api_version": "v1",
  "created": 1796292000,
  "store_id": "6740f1c2a9e4b3d2c1a0f9e8",
  "data": {
    "object": {
      "object": "test",
      "message": "This is a test delivery from Hand-Off."
    }
  }
}
FieldWhat it is
idThe event’s id (evt_…). The same as the webhook-id header, and the same on every try.
typeThe event type, such as order.paid.
api_versionThe payload version, "v1".
createdWhen the event happened, in Unix seconds.
store_idThe store it happened in.
data.objectThe order, customer, product or stock record. Its object field says which.
  • data.object is the record as it is when the delivery is sent, not when the event happened. A retry, or a resend from the delivery log, carries the latest state. Use the record’s own updatedAt to tell which of two deliveries is newer.
  • A deleted record arrives as { object, id, deleted: true }.
  • Money is an integer in the currency’s smallest unit (cents for USD), with currency on every record that holds money.
  • Fields are added over time and never renamed or removed within v1. Ignore fields you don’t know.

Verify the signature

Deliveries are signed the Standard Webhooks way, so any Standard Webhooks library can verify them. Every delivery carries three headers:

Request (headers)
POST /hooks/hand-off HTTP/1.1
Content-Type: application/json
User-Agent: Hand-Off-Webhooks/1.0
webhook-id: evt_3kQx7cV0bN2mRt9yLp4wZa1s
webhook-timestamp: 1796292004
webhook-signature: v1,<base64 HMAC-SHA256>
  • webhook-id: the event id.
  • webhook-timestamp: when this try was sent, in Unix seconds.
  • webhook-signature: v1, and the base64 HMAC-SHA256 of {webhook-id}.{webhook-timestamp}.{body}. While a secret is being rotated it holds two signatures separated by a space; accept the delivery when either matches.

To check one:

  1. Take the HMAC key from your secret: the part after whsec_, base64-decoded.
  2. Sign id.timestamp.body with HMAC-SHA256, using the raw body exactly as received. Parsing the JSON and serialising it again changes the bytes.
  3. Compare your result with each v1, signature in constant time (timingSafeEqual, hmac.compare_digest), never with ==.
  4. Refuse a timestamp more than 5 minutes from your clock, so an old delivery can’t be replayed.
Node.js (Express)
import { createHmac, timingSafeEqual } from "node:crypto"
import express from "express"

const SECRET = process.env.HAND_OFF_WEBHOOK_SECRET // whsec_…
const TOLERANCE_SECONDS = 5 * 60

/** True when one of the signatures matches. rawBody: the request body exactly as received. */
export function verifyHandOffWebhook(rawBody, headers, secret = SECRET) {
  const id = headers["webhook-id"]
  const timestamp = headers["webhook-timestamp"]
  const signatures = headers["webhook-signature"]
  if (!id || !timestamp || !signatures || !/^\d+$/.test(timestamp)) return false
  if (Math.abs(Date.now() / 1000 - Number(timestamp)) > TOLERANCE_SECONDS) return false

  const key = Buffer.from(secret.replace(/^whsec_/, ""), "base64")
  const expected = createHmac("sha256", key)
    .update(Buffer.concat([Buffer.from(`${id}.${timestamp}.`), rawBody]))
    .digest()

  return signatures.split(" ").some((entry) => {
    const [version, value] = entry.split(",")
    if (version !== "v1" || !value) return false
    const given = Buffer.from(value, "base64")
    return given.length === expected.length && timingSafeEqual(given, expected)
  })
}

const app = express()

// Keep the raw bytes: parsing and re-serialising the JSON changes them and breaks the signature.
app.post("/hooks/hand-off", express.raw({ type: "application/json" }), async (req, res) => {
  if (!verifyHandOffWebhook(req.body, req.headers)) return res.sendStatus(400)

  const event = JSON.parse(req.body.toString("utf8"))
  if (await alreadyHandled(req.headers["webhook-id"])) return res.sendStatus(200)

  await queueForProcessing(event) // do the slow work after answering
  res.sendStatus(200)
})
Python
import base64
import hashlib
import hmac
import time

TOLERANCE_SECONDS = 5 * 60


def verify_hand_off_webhook(raw_body: bytes, headers, secret: str) -> bool:
    """True when one of the signatures matches. raw_body: the request body exactly as received."""
    msg_id = headers.get("webhook-id")
    timestamp = headers.get("webhook-timestamp")
    signatures = headers.get("webhook-signature")
    if not msg_id or not timestamp or not signatures or not timestamp.isdigit():
        return False
    if abs(time.time() - int(timestamp)) > TOLERANCE_SECONDS:
        return False

    key = base64.b64decode(secret.removeprefix("whsec_"))
    signed = f"{msg_id}.{timestamp}.".encode() + raw_body
    expected = base64.b64encode(hmac.new(key, signed, hashlib.sha256).digest()).decode()

    for entry in signatures.split(" "):
        version, _, value = entry.partition(",")
        if version == "v1" and hmac.compare_digest(value, expected):
            return True
    return False


# Flask: verify_hand_off_webhook(request.get_data(), request.headers, SECRET)

Answer quickly

  • A delivery succeeds when your server answers any 2xx status within 10 seconds. Anything else is a failed try: another status, a timeout, a refused connection or a TLS error.
  • Redirects are not followed: a 3xx is a failure. Give the final address.
  • Hand-Off reads at most the first 1 KiB of your answer and doesn’t keep it. Answer first, then do the slow work.
  • Hand-Off sends at most 2 deliveries at a time to one endpoint, so a slow answer holds the deliveries behind it.

Retries

A failed delivery is tried again, 8 tries in all over about a day. Each wait gets up to 10% added at random.

TryWhen
1Right after the event
21 minute after try 1
35 minutes after try 2
430 minutes after try 3
52 hours after try 4
65 hours after try 5
78 hours after try 6
88 hours after try 7 (the last)
  • If you answer with a Retry-After header asking for a longer wait, Hand-Off waits that long, up to 1 hour.
  • After the eighth failed try the delivery is marked failed. You can send it again from the endpoint’s delivery log (Resend), which starts the tries over with the record as it is now.
  • The delivery log keeps every delivery for 30 days: its status, the number of tries and your last status code.
  • While an endpoint is paused, its events are skipped, not saved for later. Resume it to receive new events.

Duplicates and order

The same event can reach you more than once: a try that timed out after your server handled it, a resend, or a delivery Hand-Off queued again after a fault. Store each webhook-id you have handled and skip one you have already seen. Events can also arrive out of order, so don’t rely on the order they come in.

Disabled endpoints

An endpoint whose deliveries have all failed for 3 days is disabled: Hand-Off stops sending to it and Settings shows it as disabled. Fix your server, then turn the endpoint back on; it starts again with a clean count. Any successful delivery (other than a test) resets the count.

Rotate the secret

Rotate when the secret may have leaked, when someone who knew it leaves, or on a schedule. In Settings → Webhooks, open the endpoint and choose Rotate secret. The new secret is shown once.

  • For 24 hours after a rotation, the previous secret keeps signing beside the new one: every delivery carries both signatures. Put the new secret on your server within that time; a verifier that accepts any matching signature keeps working throughout.
  • After 24 hours only the new secret signs.
  • Never put the secret in client-side code, a repository or a log.

Help

Something not arriving? Check the endpoint’s delivery log first: it shows each try’s status code or a short reason. Still stuck? Write to support@hand-off.net.