# Webhooks

> Receive events, retries and replays, and verify signatures.

An event is recorded for everything that happens to a connection, a sign-in or an async run, whether or not you have a webhook. [List them](https://sidelatch.com/docs/api#ref-get-v1-events) for 30 days. Set `webhook_url` in [settings](https://sidelatch.com/docs/api#ref-patch-v1-settings) and each one is also POSTed to you. Events carry ids and statuses only, never portal data or credentials.

The event types and their `data` are listed on [Events](https://sidelatch.com/docs/events#events).

**Event body**

```json
{
  "id": "evt_1f0c...",
  "type": "connection.reconnect_needed",
  "created": 1795700000,
  "data": {
    "connection_id": "conn_8f2c41d07a9b4e6f",
    "user_id": "agency-42",
    "portal": "demo_carrier",
    "status": "reconnect_needed",
    "reason": "wrong_password"
  }
}
```

### Delivery

Answer with any 2xx within 10 seconds. A delivery that fails is tried again after 5 seconds, 30 seconds and 2 minutes, then after 10 minutes, 1 hour, 6 hours and 16 hours: about a day in all. Pending deliveries are kept in our database, so a restart on our side does not lose one. A 4xx other than 408 or 429 is not retried. Delivery is at least once: use the event `id` (also in the `Sidelatch-Event-Id` header) to ignore a repeat. [List deliveries](https://sidelatch.com/docs/api#ref-get-v1-webhook-deliveries) or [send an event again](https://sidelatch.com/docs/api#ref-post-v1-events-event-id-resend), here or in the console.

### Verify the signature

Every request has a `Sidelatch-Signature: t=<unix time>,v1=<hex>` header: an HMAC-SHA256 of `"<t>.<raw body>"` keyed with your webhook secret. Reject anything older than five minutes.

**Python**

```python
import hashlib, hmac, time

def verify(secret: str, header: str, body: bytes) -> bool:
    """header is the Sidelatch-Signature value; body is the raw request body."""
    parts = dict(p.split("=", 1) for p in header.split(","))
    if abs(time.time() - int(parts["t"])) > 300:
        return False
    expected = hmac.new(secret.encode(), f"{parts['t']}.".encode() + body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, parts["v1"])
```

**Node.js**

```js
import crypto from "node:crypto";

export function verify(secret, header, rawBody) {
  const parts = Object.fromEntries(header.split(",").map((p) => p.split("=")));
  if (Math.abs(Date.now() / 1000 - Number(parts.t)) > 300) return false;
  const expected = crypto.createHmac("sha256", secret).update(`${parts.t}.${rawBody}`).digest("hex");
  return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1));
}
```

---

Sidelatch docs: [Docs](https://sidelatch.com/docs.md) · [Quick start](https://sidelatch.com/docs/quickstart.md) · [Concepts](https://sidelatch.com/docs/concepts.md) · [The connect window](https://sidelatch.com/docs/guides/connect-window.md) · [Webhooks](https://sidelatch.com/docs/guides/webhooks.md) · [MCP for AI agents](https://sidelatch.com/docs/guides/mcp.md) · [Writes](https://sidelatch.com/docs/guides/writes.md) · [Build a portal](https://sidelatch.com/docs/guides/build-a-portal.md) · [Events](https://sidelatch.com/docs/events.md) · [Errors](https://sidelatch.com/docs/errors.md) · [API reference](https://sidelatch.com/docs/api.md)
