# Webhooks

> The events a crawl, a batch or a monitor sends to your receiver, and how to check them.

A crawl, a batch scrape or a monitor can send its events to a receiver you run, so you do not have to poll for them. Add `webhook` to the request that starts the job or creates the monitor.

## The field

`webhook` is an address as a string, or an object:

| Field      | What it does                                                                                                                                    |
| ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| `url`      | Where deliveries go. Required.                                                                                                                  |
| `headers`  | Headers to add to each delivery. At most 20, with names that are valid HTTP header names and values of at most 1024 printable ASCII characters. |
| `metadata` | A JSON object of at most 16 KiB. It comes back in every payload.                                                                                |
| `events`   | The events you want. Every event when left out.                                                                                                 |

Your `headers` are added to each request, but they never replace `Content-Type`, a signature header, or a header that frames the request (`Content-Length`, `Host`, `Transfer-Encoding`, `Connection`, `User-Agent`). Those are dropped.

## The receiver

The address must be `https`. It may not be an onion address, hold a user name or a fragment, be longer than 2048 characters, or point to a private, loopback or local address. A webhook that breaks a rule is refused with `400 BAD_REQUEST`, and nothing is stored.

The address and the headers are stored sealed, and are never shown again. A monitor shows only a hint of its address, and `***` for each header value. Where the server cannot seal them, the call is `503 SECRETS_UNAVAILABLE` and the job does not start.

Deliveries never go over Tor, and a redirect is never followed.

## Events

| Sent by        | Events                                                                                       |
| -------------- | -------------------------------------------------------------------------------------------- |
| A crawl        | `crawl.started`, `crawl.page`, `crawl.completed`, `crawl.failed`                             |
| A batch scrape | `batch_scrape.started`, `batch_scrape.page`, `batch_scrape.completed`, `batch_scrape.failed` |
| A monitor      | `monitor.page`, `monitor.check.completed`                                                    |

`events` picks from these. On a crawl or a batch you may write the short names (`started`, `page`, `completed`, `failed`) as well. A monitor sends `monitor.page` once for each page of a check whose status is not `same`, as soon as that page has been read, and `monitor.check.completed` once for each check.

A cancelled job sends no `completed` or `failed`. A page sends its event once its result is written, so a page that was given up on without a try sends none.

## The payload

Every delivery is a JSON body:

| Field       | What it holds                                         |
| ----------- | ----------------------------------------------------- |
| `success`   | `true`, or `false` when something failed.             |
| `type`      | The event, such as `crawl.page`.                      |
| `id`        | The job’s id, or for a monitor the check’s id.        |
| `webhookId` | The id of this delivery. It is the same on every try. |
| `data`      | A list. Empty, except as below.                       |
| `metadata`  | What you sent in `metadata`.                          |
| `error`     | A short sentence, only when `success` is `false`.     |

On a `page` event, `data` holds the page’s document, with the formats the job asked for. It is made from the stored capture when the delivery is sent.

```json
{
  "success": true,
  "type": "crawl.page",
  "id": "01K0EXAMPLEJOB00000000000A",
  "webhookId": "01K0EXAMPLEDELIVERY0000000A",
  "data": [
    {
      "markdown": "# Notice\n\nSample page text.\n\nContact: sales@example.invalid\n",
      "links": [
        "http://exampleonionq7x2mfk4lzr5w3ty6hbnc2jdu7avs4ekp5gw3xmlq2zr.onion/about",
        "http://exampleonionq7x2mfk4lzr5w3ty6hbnc2jdu7avs4ekp5gw3xmlq2zr.onion/contact"
      ],
      "metadata": {
        "title": "Notice",
        "description": "",
        "language": "en",
        "sourceURL": "http://exampleonionq7x2mfk4lzr5w3ty6hbnc2jdu7avs4ekp5gw3xmlq2zr.onion/notice",
        "url": "http://exampleonionq7x2mfk4lzr5w3ty6hbnc2jdu7avs4ekp5gw3xmlq2zr.onion/notice",
        "statusCode": 200,
        "contentType": "text/html",
        "scrapeId": "01K0EXAMPLECAPTURE0000000A",
        "onion": {
          "host": "exampleonionq7x2mfk4lzr5w3ty6hbnc2jdu7avs4ekp5gw3xmlq2zr.onion",
          "valid": true,
          "version": 3
        },
        "evidence": {
          "captureId": "01K0EXAMPLECAPTURE0000000A",
          "fetchedAt": "2026-11-26T10:00:00+00:00",
          "sha256Raw": "9f2c000000000000000000000000000000000000000000000000000000000000"
        }
      },
      "indicators": [
        {
          "type": "email",
          "value": "sales@example.invalid",
          "count": 1
        }
      ],
      "resources": [
        {
          "category": "image",
          "element": "img",
          "url": "http://exampleonionq7x2mfk4lzr5w3ty6hbnc2jdu7avs4ekp5gw3xmlq2zr.onion/logo.png",
          "label": "Logo",
          "title": "",
          "filename": "logo.png",
          "type": "image/png",
          "size": null,
          "download": {
            "status": "metadata_only"
          }
        }
      ]
    }
  ],
  "metadata": {
    "case": "1234"
  }
}
```

A `completed` event has an empty `data`.

```json
{
  "success": true,
  "type": "crawl.completed",
  "id": "01K0EXAMPLEJOB00000000000A",
  "webhookId": "01K0EXAMPLEDELIVERY0000000A",
  "data": [],
  "metadata": {
    "case": "1234"
  }
}
```

A page that failed sends `success: false`, an empty `data`, and in `error` the same short sentence the job’s errors route shows. A job that failed says why in `error`.

A body is at most 1.5 MiB. Over that, the document loses its `markdown`, `html`, `rawHtml` and `links`, and its `warning` starts with `content omitted (over 1.5 MiB); fetch it by scrapeId`. Read the page again with the job’s status route.

### A monitor’s payloads

On `monitor.page`, `data[0]` is the page that check serves at `GET /v2/monitor/{monitor_id}/checks/{check_id}`, with its diff: `monitorId`, `checkId`, `url`, `status`, `previousScrapeId`, `currentScrapeId`, `error`, `isMeaningful`, `judgment` and `diff`. `isMeaningful` is the goal check’s verdict on a `changed` page, and `null` otherwise. A page that errored sends `success: false`, with its code in `error`.

```json
{
  "success": true,
  "type": "monitor.page",
  "id": "01K0EXAMPLECHECK000000000A",
  "webhookId": "01K0EXAMPLEDELIVERY0000000A",
  "data": [
    {
      "monitorId": "01K0EXAMPLEMONITOR0000000A",
      "checkId": "01K0EXAMPLECHECK000000000A",
      "url": "http://exampleonionq7x2mfk4lzr5w3ty6hbnc2jdu7avs4ekp5gw3xmlq2zr.onion/notice",
      "status": "changed",
      "previousScrapeId": "01K0EXAMPLECAPTURE0000000B",
      "currentScrapeId": "01K0EXAMPLECAPTURE0000000A",
      "error": null,
      "isMeaningful": null,
      "judgment": null,
      "diff": {
        "text": "--- previous\n+++ current\n@@ -1,2 +1,2 @@\n # Notice board\n-Hours: 9 to 5\n+Hours: 9 to 6",
        "json": {
          "files": [
            {
              "chunks": [
                {
                  "content": "@@ -1,2 +1,2 @@",
                  "changes": [
                    {
                      "type": "normal",
                      "normal": true,
                      "ln1": 1,
                      "ln2": 1,
                      "content": " # Notice board"
                    },
                    {
                      "type": "del",
                      "del": true,
                      "ln": 2,
                      "content": "-Hours: 9 to 5"
                    },
                    {
                      "type": "add",
                      "add": true,
                      "ln": 2,
                      "content": "+Hours: 9 to 6"
                    }
                  ],
                  "oldStart": 1,
                  "oldLines": 2,
                  "newStart": 1,
                  "newLines": 2
                }
              ],
              "deletions": 1,
              "additions": 1,
              "from": "previous",
              "to": "current"
            }
          ]
        }
      }
    }
  ],
  "metadata": {
    "case": "1234"
  }
}
```

On `monitor.check.completed`, `data[0]` is `monitorId`, `checkId`, `status` and `summary`. `success` is `true` only when the check completed. A check that was partial or failed sends `error`: its own code, or `N of M pages failed`. It never holds page text or an address.

```json
{
  "success": true,
  "type": "monitor.check.completed",
  "id": "01K0EXAMPLECHECK000000000A",
  "webhookId": "01K0EXAMPLEDELIVERY0000000A",
  "data": [
    {
      "monitorId": "01K0EXAMPLEMONITOR0000000A",
      "checkId": "01K0EXAMPLECHECK000000000A",
      "status": "completed",
      "summary": {
        "totalPages": 1,
        "same": 0,
        "changed": 1,
        "new": 0,
        "removed": 0,
        "error": 0
      }
    }
  ],
  "metadata": {
    "case": "1234"
  }
}
```

A body over the size limit loses the page’s `diff.json`, then `diff.text`, then the judgment’s `meaningfulChanges`, until it fits, and `data[0].warning` says what went. Read the rest from the check.

A check shows what happened to its deliveries in `notificationStatus`: `{"webhook": {"attempted", "delivered", "queued", "dead"}}`, or `{}` when it has none.

## The signature

Each request carries `X-DarkCrawl-Signature: sha256=` and the hex HMAC-SHA256 of the raw body, keyed by your webhook signing secret: the UTF-8 bytes of the whole secret, `whsec_` included. Use the secret as it is: do not base64-decode it or strip `whsec_`. Libraries for Standard Webhooks (such as Svix’s) decode it and sign differently, so they do not fit here. The same value is in a second header, named the same with `Firecrawl` in the place of `DarkCrawl`, for receivers written for Firecrawl.

Where to find the secret:

- **On DarkCrawl’s hosted service**, your company has its own secret, and every delivery of its crawls, batches and monitors is signed with it. Your company’s owner finds it in the dashboard, under Settings > Company > Webhook signing secret. Showing it needs a sign-in in the last 15 minutes.
- **On a server you run yourself**, the secret is the server’s `DARKCRAWL_WEBHOOK_SECRET`. Without it, deliveries are not signed, and the job says so in its `warning`. Do not rely on the signature then: check that `id` is a job you started. If you run companies with sign-in on, each company’s deliveries are signed with its own secret, as on the hosted service; with sign-in off, every delivery uses `DARKCRAWL_WEBHOOK_SECRET`.

Check it on the raw bytes, before you parse the body, and compare in constant time:

```python
import hashlib, hmac

def verify(secret: str, body: bytes, header: str) -> bool:
    expected = "sha256=" + hmac.new(secret.encode(), body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected.encode(), header.encode())
```

### Rotating the secret

The owner can rotate the secret on the same card. The old secret stops working at once: there is no time when both work. Put the new secret in your receiver straight away. A delivery that fails your check in between is tried again only if your receiver answers `408`, `429` or `5xx`; any other answer ends it, as [Delivery](https://darkcrawl.dev/docs/api-reference/webhooks/#delivery) says.

## Delivery

A job’s events go out one at a time, in order, unless one is waiting for a retry. A `2xx` answer is delivered. Answer fast, and do the work afterwards.

`408`, `429`, `5xx` and a failed connection are tried again after 60 seconds, then 300, then 900, and then given up. Any other answer, a redirect included, is given up at once. `webhookId` stays the same on every try, so your receiver can drop a repeat it has already handled.

A delivery that was being sent when DarkCrawl restarted is sent again afterwards.

## Alert channels

An alert channel is a different thing: it tells you about an alert, such as a page that changed, and its webhook is signed as Standard Webhooks specifies, with `webhook-id`, `webhook-timestamp` and `webhook-signature` headers. Create one with `POST /darkcrawl/v1/channels`, as the [Alert channels](https://darkcrawl.dev/docs/api-reference/alert-channels/post-darkcrawl-v1-channels/) reference shows.
