Receive signed webhooks
Register an HTTPS endpoint with POST /v1/webhooks to be told when a batch job finishes or a monitored page changes, send it a test ping, read its deliveries, rotate its secret, and verify each signature in Node or Python.
Use a webhook when you would rather be told a batch job has finished than poll for it. Spicrawl sends a signed POST to your URL when the event happens. The notification carries the job or monitor summary, not the results: fetch those yourself. Requires an API key with the webhooks scope. GET routes also accept read.
A webhook is notify-only. Deliveries are retried on a fixed ladder, and an endpoint that keeps failing is switched off. Your receiver must answer quickly with a 2xx; do the real work after you have answered.
Register an endpoint
curl -X POST https://api.spicrawl.com/v1/webhooks \
-H "Authorization: Bearer $SPICRAWL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://hooks.example.com/spicrawl",
"name": "nightly-catalog",
"events": ["batch.completed", "batch.failed"],
"format": "json"
}'The response is 201 with the endpoint and its secret. The secret is returned only here and from rotate-secret. Keep it in your secret store, not in source.
Then pass the endpoint's id when you submit a batch:
{
"urls": ["https://example.com/products/1", "https://example.com/products/2"],
"webhook_endpoint_id": "0190f3a2-7c1e-7d4b-9a2f-3b8e5c6d7e80"
}| Field | Rule |
|---|---|
url | Required. https:// only, at most 2,048 characters. Private and internal addresses are refused. |
name | Optional. At most 100 characters. |
events | Optional. A non-empty subset of the events below. Defaults to ["batch.completed", "batch.failed"]. |
format | Optional. json (default), slack or discord. |
An organization may hold 20 endpoints. A twenty-first is refused with a 409; delete one first.
Events
| Event | Fires when | Payload data |
|---|---|---|
batch.completed | A batch job finishes with every item settled. | The job object, as GET /v1/batch/{id} returns it. |
batch.failed | A batch job ends as failed, for example when failure_threshold is reached. | The job object. Read error_code. |
monitor.changed | A change is confirmed on a monitored page, or a site monitor's run finds a change (a site digest). | monitor_id, name, url, detected_at, previous_hash, new_hash, diff (its first 4,000 characters) and changes_url. |
monitor.failed | A monitor is disabled after repeated failed checks. | monitor_id, name, url, reason (the last check error) and failed_at. |
ping is always delivered to every endpoint and is not listed in events. Subscribe only to the events your receiver handles, and ignore any other type you get.
Every event is a JSON document with this envelope:
{
"id": "01a1e8e1-c1d5-75fd-99eb-1573c72ced46",
"type": "batch.completed",
"created": 1763370000,
"data": { "id": "01J9Z6T3W9E21T5TZARVJRVN5C", "status": "completed", "total_items": 2 }
}id is the delivery id. It is the same on every retry of one event, so use it to drop duplicates. created is the Unix time the event was made, not the time of this attempt.
Slack and Discord formats
Set format to slack or discord to post to an incoming-webhook URL instead of your own service. The body is a single line:
format | Body | Example text |
|---|---|---|
slack | {"text": "…"} | Spicrawl batch 01J9Z6T3W9E21T5TZARVJRVN5C completed: 2/2 items |
discord | {"content": "…"} | the same line, at most 2,000 characters |
Use the incoming-webhook URL that Slack or Discord gives you as url. Signature headers are sent in these formats too. The ping line reads Spicrawl webhook test.
Test ping
curl -X POST https://api.spicrawl.com/v1/webhooks/$ENDPOINT_ID/test \
-H "Authorization: Bearer $SPICRAWL_API_KEY"The response is 202 with the delivery_id of a ping delivery. Its body is:
{"id":"…","type":"ping","created":1764064800,"data":{"event":"ping","endpoint_id":"0190f3a2-7c1e-7d4b-9a2f-3b8e5c6d7e80","created_at":"2026-11-25T10:00:00Z"}}A ping is signed and retried like any other delivery. Check that it arrived in the deliveries list below before you rely on the endpoint.
Deliveries
curl "https://api.spicrawl.com/v1/webhooks/$ENDPOINT_ID/deliveries?limit=20" \
-H "Authorization: Bearer $SPICRAWL_API_KEY"The list is newest first and holds one row per event and endpoint, not one per attempt. Each row gives:
| Field | Meaning |
|---|---|
id, event_id, event_type | The delivery, the object it is about, and the event. |
status | pending (waiting for its first attempt or a retry), delivering (in flight), delivered, failed (will be retried) or dead (given up). |
attempt, max_attempts | Tries so far, and the most that will be made. |
next_retry_at | When the next attempt is due, while it is failed. |
last_error | Why the last attempt failed. |
created_at | When the event was queued. |
Retries and auto-disable
A delivery succeeds on any 2xx response. Anything else, including a timeout, is retried on this ladder after the first attempt:
| Retry | Wait before it |
|---|---|
| 1 | 30 seconds |
| 2 | 1 minute |
| 3 | 5 minutes |
| 4 | 30 minutes |
| 5 | 1 hour |
| 6 | 1 day |
Each wait has about ±10% jitter. That is seven attempts in all. When the ladder runs out, the delivery is dead.
An endpoint that fails 100 deliveries in a row is disabled: enabled becomes false and disabled_reason says why. A success resets the count. Fix the receiver, then turn the endpoint back on:
curl -X PATCH https://api.spicrawl.com/v1/webhooks/$ENDPOINT_ID \
-H "Authorization: Bearer $SPICRAWL_API_KEY" \
-H "Content-Type: application/json" \
-d '{"enabled": true}'Re-enabling also clears disabled_reason and resets consecutive_failures to 0.
Rotate the secret
curl -X POST https://api.spicrawl.com/v1/webhooks/$ENDPOINT_ID/rotate-secret \
-H "Authorization: Bearer $SPICRAWL_API_KEY"Rotating returns a new secret and bumps secret_version. From then on, deliveries are signed with the new secret and carry kid equal to the new secret_version. Deliveries are not signed with the old secret any more, so change your receiver's secret in the same step you rotate it.
Verify signatures
Every delivery carries a signature in X-Spicrawl-Signature. X-ILayer-Signature has the same value and is kept for receivers that already read it. Check the signature before you trust the body.
The header looks like this:
X-Spicrawl-Signature: t=1763370000,v1=9c1e5b…,kid=1tis the Unix time, in seconds, at which the delivery was signed.v1is HMAC-SHA256 as lowercase hex.kidis the endpoint'ssecret_version.
The signed string is the decimal t, a ., and the raw request body, byte for byte:
signed string = "<t>." + raw_body
v1 = hex(HMAC-SHA256(key = secret, message = signed string))The key is the whole secret, whsec_…, as UTF-8 bytes. Then:
- Read the body as raw bytes. Do not parse it and serialise it again; the JSON spacing and key order will differ and the check will fail.
- Parse
tandv1from the header. - Refuse the delivery if
tis more than 300 seconds from your clock. This stops a captured delivery being replayed later. - Compute the HMAC and compare it with
v1in constant time.
import crypto from "node:crypto";
const TOLERANCE_SECONDS = 300;
// rawBody: the request body exactly as received (a Buffer or string).
// header: the X-Spicrawl-Signature value (X-ILayer-Signature works too).
export function verifySpicrawlSignature(rawBody, header, secret, now = Math.floor(Date.now() / 1000)) {
const fields = Object.fromEntries(
String(header ?? "")
.split(",")
.map((part) => part.trim().split("=", 2))
.filter(([k, v]) => k && v !== undefined)
);
const t = Number(fields.t);
const v1 = fields.v1;
if (!Number.isInteger(t) || !v1) return false;
if (Math.abs(now - t) > TOLERANCE_SECONDS) return false;
const body = Buffer.isBuffer(rawBody) ? rawBody : Buffer.from(rawBody, "utf8");
const expected = crypto
.createHmac("sha256", secret)
.update(`${t}.`)
.update(body)
.digest("hex");
const a = Buffer.from(expected, "utf8");
const b = Buffer.from(v1, "utf8");
return a.length === b.length && crypto.timingSafeEqual(a, b);
}
// Express: keep the body raw for this route, then verify before JSON.parse.
// app.post("/spicrawl", express.raw({ type: "application/json" }), (req, res) => {
// const ok = verifySpicrawlSignature(req.body, req.get("X-Spicrawl-Signature"), process.env.SPICRAWL_WEBHOOK_SECRET);
// if (!ok) return res.status(401).end();
// const event = JSON.parse(req.body);
// res.status(200).end();
// });Two checks catch most mistakes: a signature that fails for every delivery usually means the body was re-serialised before it was checked, and a signature that fails only after a while usually means the receiver's clock has drifted by more than five minutes.
Monitor payloads
A monitor.changed event carries the change, not the page. Fetch the full diff from changes_url if the first 4,000 characters are not enough:
{
"id": "01a1e8e1-c1d5-75fd-99eb-1573c72ced47",
"type": "monitor.changed",
"created": 1763370000,
"data": {
"monitor_id": "0190f5c4-2b7a-7e10-8d3f-6a1c9e4b2d70",
"name": "pricing-page",
"url": "https://example.com/pricing",
"detected_at": "2026-11-25T10:00:00Z",
"previous_hash": "3f1a…",
"new_hash": "9c2e…",
"diff": "- Pro: 49\n+ Pro: 59\n",
"changes_url": "/v1/monitors/0190f5c4-2b7a-7e10-8d3f-6a1c9e4b2d70/changes"
}
}A monitor.failed event has monitor_id, name, url, reason and failed_at in data. It means the monitor has stopped checking; re-enable it with PATCH /v1/monitors/{id} once the page is back. See Monitors.
Site digest payload
A whole-site monitor sends one monitor.changed per run that found a change or an addition or removal, not one per page. data has scope: "site" and the run's totals, and lists the pages that changed, were added or were removed:
{
"id": "01a1e8e2-d2e6-76fe-8a00-2684d83dee58",
"type": "monitor.changed",
"created": 1763370000,
"data": {
"monitor_id": "0190f9a0-3c4d-7e21-8f5a-2b7d1e9c4f03",
"name": "example-blog",
"url": "https://example.com/",
"scope": "site",
"detected_at": "2026-11-25T10:00:00Z",
"counts": {"checked": 12, "skipped": 180, "changed": 1, "added": 2, "removed": 0, "credits": 14},
"truncated": false,
"changed": [{"url": "https://example.com/blog/rates", "diff": "- Rate: 4%\n+ Rate: 5%\n"}],
"added": ["https://example.com/blog/new-post", "https://example.com/blog/another-post"],
"removed": [],
"changes_url": "/v1/monitors/0190f9a0-3c4d-7e21-8f5a-2b7d1e9c4f03/changes"
}
}countshas the run's totals: pageschecked,skipped(not fetched, sitemaplastmodunchanged),changed,added,removed, and thecreditsit spent.truncatedistruewhenmax_credits_per_runstopped the run early.changedlists at most 50 pages, each with a diff of at most 2,000 characters.addedandremovedlist at most 100 URLs each. The lists can be shorter thancounts.changes_urlreturns each run's digest in the change history.
The signature is verified exactly as for any other delivery, on the raw body.
Related
- Watch a page for changes: the monitors that fire
monitor.changedandmonitor.failed - Scrape thousands of URLs with a batch job: the job that fires
batch.completed - Batch webhook_endpoint_id: attach an endpoint to one job
Batch jobs
Submit up to 10,000 URLs per call to POST /v1/batch, poll the job until it is terminal, and page the JSONL results before they expire after 72 hours.
Monitors
Create a single-page monitor with POST /v1/monitors, run a check now, read the change history, and get a signed webhook when the page changes or the monitor is disabled.