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

# Webhooks

> Every change, pushed to your endpoint, signed, with retries that back off.

Register an HTTPS endpoint in Vensight under **Settings → Developers**, and every change
in the workspace is POSTed to it as it happens. When you add the endpoint, Vensight shows
its **signing secret** once. Store it with your other secrets.

## The payload

```json theme={null}
{
  "id": "evt_41207",
  "type": "invoices.status_changed",
  "created_at": "2026-09-09T02:14:07.221Z",
  "data": {
    "resource": "invoices",
    "resource_id": "9c2a7d10-4e8b-4f3a-b6d2-1a7e5c9f0b84",
    "vendor_id": "6f1c2a4e-8b1d-4c3a-9e57-2d4b8a1f0c93",
    "action": "updated",
    "field": "status",
    "from": "approved",
    "to": "paid"
  },
  "links": {
    "self": "/api/v1/invoices/9c2a7d10-4e8b-4f3a-b6d2-1a7e5c9f0b84",
    "changes": "/api/v1/changes"
  }
}
```

`type` is the event; the [Event catalog](https://docs.vensight.ai/event-catalog.md) lists all of them. `field`, `from`
and `to` appear only on a `status_changed` event. The three payload pages under **Webhooks**
in the API reference tab describe every field.

The payload carries ids rather than the whole record. To get the record as it is now,
call `https://app.vensight.ai` followed by `links.self`, with your API key. A record copied
into the payload would already be out of date by the time a retry delivered it.

## Verifying the signature

Every request carries `Vensight-Signature: t=<unix seconds>,v1=<hex>`. The `v1` value is an
HMAC-SHA256 of `"<t>.<raw body>"`, using your endpoint's signing secret.

> [!WARNING]
>
> Verify against the **raw request body**, before any JSON parsing. Parsing and
> re-serialising changes whitespace and key order, and the signature will never match.

```typescript Node.js theme={null}
import { createHmac, timingSafeEqual } from "node:crypto";

export function verify(rawBody: Buffer, header: string, secret: string, toleranceSeconds = 300): boolean {
  const parts = Object.fromEntries(
    header.split(",").map((p) => {
      const i = p.indexOf("=");
      return [p.slice(0, i), p.slice(i + 1)];
    }),
  );
  const t = Number(parts.t);
  if (!Number.isFinite(t) || !parts.v1) return false;
  if (Math.abs(Date.now() / 1000 - t) > toleranceSeconds) return false; // too old: a replay

  const expected = createHmac("sha256", secret)
    .update(`${t}.`)
    .update(rawBody)
    .digest();
  const given = Buffer.from(parts.v1, "hex");
  return given.length === expected.length && timingSafeEqual(given, expected);
}

// Express: keep the raw body for this route.
// app.post("/vensight", express.raw({ type: "application/json" }), (req, res) => {
//   if (!verify(req.body, req.get("Vensight-Signature") ?? "", process.env.VENSIGHT_WEBHOOK_SECRET!)) {
//     return res.sendStatus(400);
//   }
//   res.sendStatus(200);           // answer first
//   queue.push(JSON.parse(req.body.toString("utf8")));
// });
```

```python Python theme={null}
import hmac, hashlib, time

def verify(raw_body: bytes, header: str, secret: str, tolerance=300) -> bool:
    parts = dict(p.split("=", 1) for p in header.split(","))
    t, given = int(parts["t"]), parts["v1"]
    if abs(time.time() - t) > tolerance:
        return False                      # too old: someone is replaying it
    expected = hmac.new(secret.encode(),
                        f"{t}.".encode() + raw_body,
                        hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, given)
```

Two details worth keeping: the **timestamp is inside the signed string**, which is what
makes a captured delivery useless later; and the comparison is constant-time
(`timingSafeEqual`, `compare_digest`), not `==`, so it does not leak the answer through its
timing.

Other headers: `Vensight-Event` (the type), `Vensight-Event-Id` (stable across retries; key
your idempotency on this) and `Vensight-Delivery` (this delivery to this endpoint; it stays
the same on every retry of it, so it is useful for matching your logs to ours).

## What counts as delivered

Any **2xx** within **10 seconds**. If your endpoint has not answered by then, the attempt
counts as failed and is retried. So answer first and do the work afterwards: queue the event
and return 200. A handler that finishes its processing before answering will eventually
time out, and you will process the same event twice.

A **3xx is treated as a failure, not a success.** A redirect on a webhook endpoint is almost
always a misconfiguration, and following it would send your data, and its signature, to a
URL nobody registered.

## Retries

A failed delivery is retried on a backing-off schedule: **30 seconds, then 1 minute, 2, 4,
8, 16, 32, 64, 128 and 256 minutes, then every 6 hours, up to 14 attempts**, a little over a
day in total (about 26½ hours). Each wait has a small random offset, so deliveries that
failed together do not all come back at once.

The one exception is **410 Gone**: if your endpoint answers with it, that delivery is not
retried. Every other failure, including a `4xx`, is retried as above, because an endpoint
part-way through its own deploy often answers that way for a minute.

An endpoint is **paused automatically when 20 deliveries in a row have each failed every
retry** (or been answered `410`), on the assumption that it has been taken down rather than
having a bad moment. In practice that means it has been unreachable for more than a day. Any
successful delivery resets the count. You will see it paused, with the reason, in Vensight.

**A paused endpoint loses nothing.** Events that happen while it is paused are held, and when
you resume it they are sent, oldest first, within a few minutes. The same is true if you
pause an endpoint yourself.

## Duplicates and order

Each event is delivered **at least once**. Normally that means exactly once, but a delivery
whose answer was lost on the way back (a timeout, a dropped connection) is sent again. Key
your processing on `Vensight-Event-Id` and skip one you have already handled.

Events are **not guaranteed to arrive in order**. A retried event can land after a newer
one. The number in `Vensight-Event-Id` only ever goes up, so if order matters to you, compare
it before applying a change, or fetch the current record from `links.self`, which is always
up to date.

## Catching up after missed deliveries

After 14 attempts a single delivery stops for good. That event is not lost either: every
event is also an entry on the [change feed](https://docs.vensight.ai/api-reference/changes/list.md), and you can read
it back from there.

The webhook and the feed name the same things differently:

| Webhook | Change feed |
| - | - |
| `id`: `evt_41207` | `id`: `41207` (the same number, without `evt_`) |
| `type` | `event_name` |
| `created_at` | `occurred_at` |
| `data.resource`, `data.resource_id`, `data.vendor_id`, `data.action` | `resource`, `resource_id`, `vendor_id`, `action` |
| `data.field`, `data.from`, `data.to` | `payload.field`, `payload.from`, `payload.to` |

To catch up:

1. Take the `created_at` of the last event you processed successfully.
2. Read `/v1/changes?updated_since=<that created_at>`, page by page, until `has_more` is
   `false`. Add `event_name=` to read only the events you subscribe to.
3. Skip any entry whose id you have already processed. `updated_since` includes the
   boundary, so the last event you handled comes back once.
4. Process the rest exactly as you would a webhook.

```bash curl theme={null}
curl "$BASE/changes?updated_since=2026-09-09T02:14:07.221Z&limit=200" \
  -H "Authorization: Bearer $VENSIGHT_KEY"
```

```typescript TypeScript theme={null}
for await (const change of walk("changes", { updated_since: lastCreatedAt })) {
  if (await alreadyProcessed(`evt_${change.id}`)) continue;
  await handle(change); // same handling as a webhook, using the table above
}
```

```python Python theme={null}
for change in walk("changes", updated_since=last_created_at):
    if already_processed(f"evt_{change['id']}"):
        continue
    handle(change)  # same handling as a webhook, using the table above
```

`walk` is the paging function from the [Quickstart](https://docs.vensight.ai/quickstart.md).

## Rotating the signing secret

There is no button to replace an endpoint's secret. Rotate it by running two endpoints for
a short while:

1. In **Settings → Developers**, add a second endpoint with the **same URL** and the same
   events. It gets its own new secret.
2. Change your handler to accept a signature made with either secret.
3. Deliveries now arrive twice, once per endpoint, with the same `Vensight-Event-Id`. If
   you already key your idempotency on it, as above, the second copy is skipped.
4. Delete the old endpoint, then remove the old secret from your handler.

Do the same straight away if a secret may have been exposed.

## Choosing events

Leave the event list empty to receive everything. Otherwise name the types you want,
such as `vendors.status_changed` or `documents.created`. The
[Event catalog](https://docs.vensight.ai/event-catalog.md) lists every one.

Exactly **one** event is sent per change, with the most specific name that applies, so a
status change does not also arrive as an `updated`.

## Testing an endpoint

Add the endpoint, then change something in Vensight. The delivery, its attempts and any
error appear under **Settings → Developers → Recent deliveries** within a minute.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.