# Webhooks (/webhooks)



A webhook sends each Finic [event](/webhooks/events) to your HTTPS endpoint as it happens, so you don't have to poll. Webhooks and events belong to your whole organization, not to one product. Today the events come from [KYB](/kyb): business records, screenings, verifications and monitoring. Scores, ask and Identify don't send events yet.

## Add an endpoint [#add-an-endpoint]

Add an endpoint with an API key an admin created. `url` must be public and `https`. `event_types` takes types, groups such as `screening.*`, or `*`:

```bash
curl https://api.finic.ai/v1/webhook_endpoints \
  -H "Authorization: Bearer $FINIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://example.com/webhooks/finic", "event_types": ["screening.*", "verification.completed", "business.status_changed"] }'
```

The response has the signing `secret`, `whsec_…`, shown only this once. Keep it. An organization has at most 20 endpoints. You can also manage endpoints in the Finic app, under **Settings → Webhooks**.

Each delivery is a `POST` of the event, as [`GET /v1/events`](/webhooks/events#reading-events) shows it.

## Verify the signature [#verify-the-signature]

Deliveries are signed by the [Standard Webhooks](https://www.standardwebhooks.com) specification, with three headers: `webhook-id` (the event's id), `webhook-timestamp` (Unix seconds) and `webhook-signature`. The signature is `v1,` and the base64 HMAC-SHA256 of `<webhook-id>.<webhook-timestamp>.<body>`, keyed with the secret's bytes after `whsec_`, base64-decoded. The Standard Webhooks libraries check it for you (`pip install standardwebhooks`):

```python
from standardwebhooks.webhooks import Webhook

wh = Webhook(FINIC_WEBHOOK_SECRET)  # "whsec_..."

def handle(request):
    event = wh.verify(request.body, request.headers)  # raises if the signature is wrong
    ...
```

Check the signature on the raw body, before parsing it. Refuse a timestamp that's minutes old.

After you rotate the secret (`POST /v1/webhook_endpoints/{id}/rotate_secret`), deliveries are signed with the old secret too, for 24 hours, so `webhook-signature` can hold two signatures, separated by a space.

## Delivery and retries [#delivery-and-retries]

* Answer with a `2xx` within 10 seconds. Do the work after you answer.
* Otherwise Finic tries again after 5 seconds, 5 minutes, 30 minutes, and 2, 5, 10 and 14 hours. After that, the delivery is `failed`.
* Redirects aren't followed.
* Delivery is at least once, and in no set order. Use `webhook-id` to skip an event you've had, and `seq` to put events in order.
* An endpoint that answers `410`, or fails for 5 days with no delivery taken, is disabled (`webhook_endpoint.disabled`), and what it has yet to get is cancelled. Events while it's disabled aren't sent later: read them from `GET /v1/events`, then turn the endpoint on again with `PATCH` and `"status": "enabled"`.

`GET /v1/webhook_deliveries` lists deliveries, with each one's status, attempts and the HTTP status your endpoint answered with. Send one again with `POST /v1/webhook_deliveries/{id}/retry`, and a test event with `POST /v1/webhook_endpoints/{id}/test`. Finished deliveries are kept for 30 days.
