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

# Webhooks

> Receive signed company watch events, verify raw request bodies, and handle retries and test deliveries.

> [!NOTE]
>
> Company Intelligence and Watchers is in closed beta. To use it, [get in touch](https://www.range.org/get-in-touch).

Register an HTTPS destination with [Create a Webhook Endpoint](https://docs.range.org/risk-api/companies/create-webhook-endpoint.md), then add its UUID to a watch's `destinations.webhook_endpoint_ids`. Store the signing secret securely when it is returned at creation.

## Delivery Types

| Type | `data` payload |
| - | - |
| `event.created` | New event matching a watch. |
| `event.updated` | Corrected or retracted event with a higher `version`. |
| `watch.status_changed` | Watch whose status changed between `pending_coverage`, `active`, and `paused`. |

## Payload

The delivery envelope has a UUID `id`, delivery `type`, `attempt`, `created_at`, and `data`. An event delivery looks like this:

```json theme={null}
{
  "id": "2bde7a12-e81b-579e-8d8e-4b317c1e109f",
  "type": "event.created",
  "attempt": 1,
  "created_at": "2026-12-01T09:14:23Z",
  "data": {
    "id": "ca4fb408f2e8b2ef6574b7170",
    "object": "event",
    "type": "ops.incident.started",
    "domain": "ops",
    "status": "active",
    "version": 1,
    "company": {
      "id": "6aa0498a-dac8-54d6-8f70-757fb7a78c92",
      "name": "Kestrel Payments"
    },
    "subject": {
      "type": "product",
      "id": "f7c0b8f1-577d-581b-ba53-bfa840607796",
      "name": "Card Authorization"
    },
    "summary": "Kestrel Payments reports an outage for Card Authorization in eu-west.",
    "fact_before": {
      "kind": "outage",
      "status": "confirmed",
      "service_status": "recovered",
      "provider_status": "operational"
    },
    "fact_after": {
      "kind": "outage",
      "status": "confirmed",
      "service_status": "down",
      "provider_status": "major_outage",
      "summary": "Card Authorization outage",
      "opened_at": "2026-12-01T09:11:00Z",
      "recovered_at": null
    },
    "affected": {
      "products": [
        "f7c0b8f1-577d-581b-ba53-bfa840607796"
      ],
      "regions": [
        "eu-west"
      ]
    },
    "confirmation": "primary",
    "confidence": 0.99,
    "sources": [
      {
        "url": "https://status.kestrelpay.example/incidents/7h2kq9",
        "publisher": "Kestrel Payments status page",
        "source_type": "status_page",
        "retrieved_at": "2026-12-01T09:13:58Z"
      }
    ],
    "effective_at": "2026-12-01T09:11:00Z",
    "disclosed_at": "2026-12-01T09:13:02Z",
    "detected_at": "2026-12-01T09:14:22Z",
    "path": [],
    "related_event_ids": [],
    "watch_ids": [
      "77900c12-055e-5255-9c85-480e00059964"
    ]
  }
}
```

## Headers

| Header | Meaning |
| - | - |
| `Range-Signature` | `t=<unix-seconds>,v1=<lowercase-hex-hmac>` |
| `Range-Delivery-Id` | Delivery UUID, stable across retries. |
| `Range-Event-Type` | Delivery type, such as `event.created`. |
| `User-Agent` | `Range-Webhooks/1.0` |

## Verify Signatures

Range signs the timestamp, a period, and the exact body bytes with HMAC-SHA256 using the endpoint's secret. Read the raw body before parsing JSON. Re-serializing JSON changes the signed bytes.

Reject missing or malformed signatures, timestamps outside your tolerance, and signatures that do not match. These examples use a five-minute tolerance in either direction and constant-time comparison. Keep the receiver's clock synchronized.

```javascript Node.js theme={null}
import crypto from "node:crypto";

export function verifyRangeSignature(rawBody, header, secret, toleranceSec = 300) {
  if (!Buffer.isBuffer(rawBody) || typeof header !== "string" || !secret) return false;
  const parts = {};
  for (const part of header.split(",")) {
    const match = /^(t|v1)=(.+)$/.exec(part.trim());
    if (!match || Object.hasOwn(parts, match[1])) return false;
    parts[match[1]] = match[2];
  }
  if (!/^\d+$/.test(parts.t ?? "") || !/^[0-9a-f]{64}$/.test(parts.v1 ?? "")) return false;
  const timestamp = Number(parts.t);
  if (!Number.isSafeInteger(timestamp) || Math.abs(Date.now() / 1000 - timestamp) > toleranceSec) return false;
  const expected = crypto.createHmac("sha256", secret)
    .update(parts.t + ".")
    .update(rawBody)
    .digest();
  const received = Buffer.from(parts.v1, "hex");
  return received.length === expected.length && crypto.timingSafeEqual(expected, received);
}
```

```python Python theme={null}
import hashlib
import hmac
import re
import time


def verify_range_signature(raw_body: bytes, header: str, secret: str, tolerance: int = 300) -> bool:
    if not isinstance(raw_body, bytes) or not isinstance(header, str) or not secret:
        return False
    parts = {}
    for part in header.split(","):
        key, sep, value = part.strip().partition("=")
        if not sep or key not in ("t", "v1") or key in parts:
            return False
        parts[key] = value
    if not re.fullmatch(r"[0-9]{1,16}", parts.get("t", "")):
        return False
    if not re.fullmatch(r"[0-9a-f]{64}", parts.get("v1", "")):
        return False
    timestamp = int(parts["t"])
    if abs(time.time() - timestamp) > tolerance:
        return False
    signed = parts["t"].encode("ascii") + b"." + raw_body
    expected = hmac.new(secret.encode(), signed, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, parts["v1"])
```

These functions return a boolean. Call them before parsing or processing the payload; reject a failed check. The [quickstart](https://docs.range.org/risk-api/companies/quickstart.md) shows a Node.js receiver that uses the verifier.

## Acknowledgment, Retries, and Recovery

Return a 2xx response promptly after accepting a delivery. For production handlers, durably enqueue it before acknowledging and process it asynchronously. Failed deliveries are retried with backoff. Repeatedly failing endpoints may be disabled.

Retries retain the delivery `id` and increase `attempt`. Deduplicate event work by event `id` and `version`, keeping the highest version. A timestamp check limits replay age; durable idempotency prevents repeated work within that window. Handle `watch.status_changed` separately from event deliveries.

Use [List Watch Events](https://docs.range.org/risk-api/companies/list-watch-events.md) to reconcile missed events. See [corrections and ordering](https://docs.range.org/risk-api/companies/watches-and-events.md#corrections-ordering-and-duplicates).

## Test an Endpoint

[Send a Test Event](https://docs.range.org/risk-api/companies/send-test-event.md) sends a signed sample `event.created` delivery. It returns `delivered`, `response_status`, and `duration_ms` so you can inspect your receiver's response:

```bash theme={null}
curl -X POST https://api.range.org/v1/risk/webhook-endpoints/70030f98-22b2-5677-b961-856b93680123/test \
  -H "Authorization: Bearer YOUR_API_KEY"
```

A successful test checks connectivity and handling of the sample. It does not generate a company change or establish coverage for the watched company.


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