# Webhooks

> For AI agents: the index of these docs is at https://scrapelyserp.com/docs/llms.txt (every page it lists has a Markdown version like this one).

Scrapely pushes watchlist events to HTTPS endpoints you register. Each endpoint has its own signing secret, so you can prove every delivery came from Scrapely, rotate a secret without missing one, and route lists to different receivers.

## Endpoints {#endpoints}

An **endpoint** is a URL of yours that receives events. Register up to 10 per account under **Dashboard → Developers → Webhooks**, or with the API. Each has a description (up to 120 characters), an on/off switch, a list of the events it subscribes to, and **its own signing secret**.

The secret (`whsec_…`) is returned once, when you create the endpoint or rotate its secret, and never again: it is stored encrypted, and lists show only its last four characters. Save it straight into your receiver's secret store.

:::codeGroup{syncKey="lang"}
```bash title="cURL"
curl -X POST "https://api.scrapelyserp.com/v1/webhook_endpoints" \
  -H "Authorization: Bearer $SCRAPELY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/hooks/scrapely",
    "description": "Production",
    "events": ["watchlist.product.changed", "watchlist.run.completed"]
  }'
```
```python title="Python"
import os
import requests

HEADERS = {"Authorization": f"Bearer {os.environ['SCRAPELY_API_KEY']}"}

r = requests.post(
    "https://api.scrapelyserp.com/v1/webhook_endpoints",
    headers=HEADERS,
    json={
        "url": "https://example.com/hooks/scrapely",
        "description": "Production",
        "events": ["watchlist.product.changed", "watchlist.run.completed"],
    },
    timeout=30,
)
r.raise_for_status()
data = r.json()
save_secret(data["id"], data["secret"])  # returned only now
```
```javascript title="Node.js"
const res = await fetch('https://api.scrapelyserp.com/v1/webhook_endpoints', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.SCRAPELY_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    url: 'https://example.com/hooks/scrapely',
    description: 'Production',
    events: ['watchlist.product.changed', 'watchlist.run.completed'],
  }),
  signal: AbortSignal.timeout(30_000),
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
saveSecret(data.id, data.secret); // returned only now
```
:::

**Full reference →** [`POST /v1/webhook_endpoints`](/reference/webhook-endpoints#create-webhook-endpoint), [`GET /v1/webhook_endpoints`](/reference/webhook-endpoints#list-webhook-endpoints), [`PATCH /v1/webhook_endpoints/{id}`](/reference/webhook-endpoints#update-webhook-endpoint)

## Which endpoint gets what {#routing}

| The event is from | It goes to |
| --- | --- |
| A watchlist with `webhook_url` (or `webhook_endpoint_id`) | That endpoint only, whatever it subscribes to. One way to send a client's lists to the client's own receiver. |
| A watchlist without one | Every enabled endpoint subscribed to that event (`events: null` means every event). |
| `POST /v1/webhook_endpoints/{id}/test` | That endpoint only, once, without retries. |

| Event | Sent when |
| --- | --- |
| `watchlist.product.changed` | A notify route fired on a change (the default pipeline: a tracked field moved). |
| `watchlist.product.matched` | A notify route fired on any other branch, such as a value test. |
| `watchlist.product.delisted` | An item came back `not_found` and was delisted. |
| `watchlist.mention.found` | A mention list found posts its queries had not seen before. |
| `watchlist.run.completed` | A run finished, was skipped or failed. Always sent, last. |
| `monitor.alert` | A monitor alert went to this endpoint as a notification destination: the alert plus its template rendering (`rendered`). |
| `webhook.test` | You press **Send test** or call `/test`. |

Payloads field by field, with examples: [Webhook events](/reference/webhook-events).

## Delivery and retries {#delivery}

Every delivery is a `POST` with a JSON envelope (`id`, `type`, `created_at`, `data`) and five headers: the signature, the event type, the delivery id, the attempt number and the receiving endpoint's id.

Answer with any **2xx within 10 seconds**, then do the work (queue it). Anything else (a 4xx or 5xx, a timeout, a redirect) is a failure, and the same event is sent again on this schedule:

| Attempt | Sent |
| --- | --- |
| 1 | When the event happens |
| 2 | 10 s after attempt 1 failed |
| 3 | 1 min after attempt 2 failed |
| 4 | 5 min after attempt 3 failed |
| 5 | 30 min after attempt 4 failed |
| 6 | 2 h after attempt 5 failed |

- Redirects are never followed. A destination refused for safety (see below) is not retried.
- Delivery is **at least once**: a retry can arrive after a response Scrapely did not see. `Scrapely-Delivery` (the event id) is the same on every attempt: record the ones you processed and skip repeats.
- Every attempt is listed in the dashboard's delivery log with its status code and duration.
- Missed everything during an outage? `GET /v1/watchlists/{id}/items?changed_since=…` returns what changed meanwhile.

## Verifying signatures {#verifying-signatures}

Anyone can POST to your URL. The signature proves a delivery came from Scrapely, unmodified, and recently:

1. `Scrapely-Signature` looks like `t=1792000000,v1=5f2b…`: a Unix timestamp and one or more signatures.
2. Each `v1` is the hex HMAC-SHA256 of `<t>.<raw body>`, keyed with the endpoint's secret. `Scrapely-Endpoint` names the endpoint, so a receiver serving several knows which secret to use.
3. Compute it yourself and accept the delivery when it equals any `v1`, compared in constant time.
4. Refuse a `t` more than 5 minutes from now: the timestamp is inside the signature, so a captured delivery cannot be replayed later.

:::hint{style="warning" title="Use the raw body"}
Verify the exact bytes you received, before parsing JSON. Re-serialising changes whitespace and the signature will not match.
:::

Copy-paste verification code for Python, Node.js, Go and PHP: [Verifying signatures](/reference/webhook-events#verifying-signatures). Then press **Send test** (or call `/test`) to prove it end to end.

## Rotating a secret {#rotating-secrets}

Rotate from the endpoint's row in the dashboard, or with `POST /v1/webhook_endpoints/{id}/rotate`. The new secret is returned once and signs every delivery from that moment. By default the old one keeps signing too, for 24 hours, so nothing fails while you deploy:

```mermaid
sequenceDiagram
  participant You
  participant Scrapely
  participant Receiver as Your receiver
  You->>Scrapely: rotate, overlap true
  Scrapely-->>You: new secret, shown once
  Note over Scrapely,Receiver: Overlap starts: 24 h of double signatures
  Scrapely->>Receiver: delivery signed v1=new, v1=old
  Receiver-->>Scrapely: 2xx, the old secret matches
  You->>Receiver: deploy the new secret
  Scrapely->>Receiver: delivery signed v1=new, v1=old
  Receiver-->>Scrapely: 2xx, the new secret matches
  Note over Scrapely,Receiver: Overlap ends: only v1=new
  Scrapely->>Receiver: delivery signed v1=new
  Receiver-->>Scrapely: 2xx
```

_With overlap, every delivery carries one signature per secret for 24 hours; the receiver accepts whichever it holds._

| Rotate with | Use it when | What happens |
| --- | --- | --- |
| `{ "overlap": true }` (default) | Routine rotation | Two `v1=` per delivery for 24 hours (`previous_secret_expires_at` says until when). Deploy the new secret within that window. |
| `{ "overlap": false }` | The secret may have leaked | The old secret stops at once. Deliveries fail verification (and are retried) until your receiver has the new one. |

**Full reference →** [`POST /v1/webhook_endpoints/{id}/rotate`](/reference/webhook-endpoints#rotate-webhook-endpoint-secret), [`POST /v1/webhook_endpoints/{id}/test`](/reference/webhook-endpoints#test-webhook-endpoint)

## Allowed destinations {#destinations}

An endpoint URL must be `https://`, on port 443 or 1024–65535, and resolve to a public address. Loopback, private, link-local and cloud metadata addresses are refused when the endpoint is registered and again at every delivery.

For local development, expose your receiver through a tunnel (such as ngrok or Cloudflare Tunnel) or point an endpoint at a request inspector.

---

## For AI agents

- This page for a human reader: https://scrapelyserp.com/docs/webhooks
- The whole space as one Markdown file: https://scrapelyserp.com/docs/llms-full.txt
- Live search + fetch over MCP: https://scrapelyserp.com/docs/_api/public/orgs/affc5b0f-d3c2-423a-8143-9d10db5736ae/spaces/981e6275-da3f-446c-82de-889f59c83b6f/mcp
  - Install (Claude CLI): `claude mcp add scrapely --transport http https://scrapelyserp.com/docs/_api/public/orgs/affc5b0f-d3c2-423a-8143-9d10db5736ae/spaces/981e6275-da3f-446c-82de-889f59c83b6f/mcp`

This Markdown is the same content the page renders — safe to quote and to ground answers in.
