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

# Webhooks

> Lurk tells your server when something happens. Signed, retried, and safe to repeat.

Add an endpoint and pick the events you want. Lurk sends each one as a `POST` with a JSON body.

| Event | When |
| - | - |
| `activity.created` | A rule gave or took units. The body holds the same receipt `POST /v1/events` returned. |
| `rule.live` | A person took a rule live. |
| `unit.used` | Someone used some of a unit with `units.use`: a coupon at the till, a ticket at the door. |

## Add an endpoint

The URL must be HTTPS and on the public internet. The response holds the signing secret **once**; keep it on your server.

```bash theme={null}
curl https://api.getlurk.com/v1/webhook-endpoints \
  -H "Authorization: Bearer $LURK_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://example.com/lurk", "events": ["activity.created"] }'
```

## What you receive

```json theme={null}
{
  "id": "whd_01j9…",
  "type": "activity.created",
  "created_at": "2026-10-11T08:12:00.000Z",
  "data": {
    "activity": "act_01j9…",
    "event": "checkin.scanned",
    "user": "maya@example.com",
    "receipts": [{ "by": "rule:morning-regular", "via": "api", "unit": "beans", "change": 10, "balance": 1250 }]
  }
}
```

`user` is your own identifier for the person, as you sent it. `id` is the same on every retry, so you can ignore one you have already handled.

A `unit.used` delivery looks like this:

```json theme={null}
{
  "id": "whd_01j9…",
  "type": "unit.used",
  "created_at": "2026-10-15T18:02:00.000Z",
  "data": {
    "activity": "act_01j9…",
    "user": "maya@example.com",
    "unit": "coupon",
    "amount": 1,
    "balance": 2,
    "reference": "scan-8841",
    "reason": "Table 4"
  }
}
```

Lurk adds event types over time. End your handler with a branch that ignores a `type` you do not know, and ignore fields you do not read.

## Check the signature

Every delivery carries `webhook-id`, `webhook-timestamp` and `webhook-signature`, following the [Standard Webhooks](https://www.standardwebhooks.com) scheme. Check the signature on the **raw** body before you trust it.

```typescript theme={null}
import { constructEvent } from "@getlurk/sdk";

// Pass the raw request body (text, not parsed JSON), the request headers and the endpoint's secret.
export async function handle(body: string, headers: Headers): Promise<number> {
  const event = await constructEvent(body, headers, process.env.LURK_WEBHOOK_SECRET ?? "");
  if (event.type === "activity.created") {
    for (const receipt of event.data.receipts) {
      console.log(`${event.data.user}: ${receipt.change} ${receipt.unit}, now ${receipt.balance}`);
    }
  }
  return 200; // any 2xx tells Lurk it arrived
}
```

In Python:

```python theme={null}
import os

from flask import Flask, abort, request  # any framework: you only need the raw body and the headers

from getlurk import WebhookVerificationError, construct_event

app = Flask(__name__)


@app.post("/webhooks/lurk")
def lurk_webhook():
    try:
        event = construct_event(request.get_data(), request.headers, os.environ["LURK_WEBHOOK_SECRET"])
    except WebhookVerificationError:
        abort(400)
    if event["type"] == "activity.created":
        print(event["data"]["receipts"])
    return "", 204
```

Without an SDK: the signed text is `<webhook-id>.<webhook-timestamp>.<body>`, the key is the part of the secret after `whsec_` decoded from base64, and the signature is `v1,` plus the base64 of the HMAC-SHA-256. Reject a timestamp more than five minutes from now.

## Retries

Answer with any `2xx` within 10 seconds. Anything else, or no answer, counts as a failure and Lurk tries again after 10 seconds, 1 minute, 5 minutes, 30 minutes, 2 hours, 8 hours, 24 hours and 36 hours (about three days), then stops. Redirects are not followed.

An endpoint that fails 15 attempts in a row is switched off, and its status shows `disabled` with the reason `failing`.

## Manage endpoints

* `GET /v1/webhook-endpoints` lists the project's endpoints, newest first, with each one's `status` (`active` or `disabled`) and, when it is disabled, `disabled_reason`.
* `POST /v1/webhook-endpoints/{id}/delete` stops sending to an endpoint and removes its delivery history. It cannot be undone.
* A project can have 25 active endpoints. Disabled ones do not count. Past 25, adding one is refused with `validation_failed`.
* A disabled endpoint gets nothing. The reason is `failing` (15 failed attempts in a row) or `manual`: the person who added it was removed from the team or made a viewer, so what they set up stopped with their access. Add a new endpoint if you still want one; a new endpoint has a new secret.


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