# Webhooks

> **Not live on production yet.** This guide follows the published API contract. Its steps work once these parts answer in production: Webhooks.

> **Answer.** KRIN webhooks send your server events such as a conversion held or a payout sent. Each delivery is signed with your endpoint's secret. Check the signature, reject anything older than 5 minutes and dedupe on the event id.

## Add an endpoint

Add an endpoint in the console under Settings, Webhooks. Give it an https URL and the event types you want.

- The URL is https on port 443 with a public host name. IP addresses and KRIN hosts are refused.
- Each side of your organization can have up to 10 endpoints.
- If your organization has both sides, choose the side. It can't change later.
- Adding an endpoint and any change to it, including turning it on or off, needs a person signed in with a passkey. So API keys can't add or change endpoints.

The signing secret starts with `kws_` and is shown once, when you add the endpoint. Store it on your server.

## Event types

| Side | Event types |
|---|---|
| Publisher | `conversion.held`, `conversion.reversed`, `statement.issued`, `payout.sent`, `placement.paused`, `tier.changed`, `delivery.failing`, `case.opened`, `case.decided`, `case.closed` |
| Advertiser | `offer.status_changed`, `offer.checks_completed`, `conversion.approved`, `reversal.completed`, `balance.low`, `topup.succeeded`, `recovery_credit.created` |

An endpoint gets only its own side's events. Sandbox and test events carry `test: true` and never move money.

## Check every delivery

Each delivery has a `Krin-Signature` header:

```
Krin-Signature: t=<unix seconds>,v1=<hex HMAC-SHA256>
```

`v1` is the HMAC-SHA256 of `t`, a full stop, and the raw request body, keyed with your endpoint's secret.

1. Compute the HMAC over `t + "." + raw body` and compare it with `v1` in constant time (for example `crypto.timingSafeEqual` in Node or `hmac.compare_digest` in Python).
2. Reject the delivery if `t` is more than 5 minutes from your clock.
3. Dedupe on the event id (`whe_...`). The same event can arrive more than once.
4. Answer 2xx quickly, then do the work.

## Ids

| Prefix | What it is |
|---|---|
| `whk_` | An endpoint |
| `whe_` | One event, the same for every endpoint it went to. Dedupe on it |
| `whd_` | One event sent to one endpoint |

`evt_` is still an offer event, not a webhook.

## Retries, turning off and replay

- KRIN retries a failed delivery with backoff for 72 hours, then marks it failed.
- An endpoint whose deliveries keep failing is turned off. Its status shows `failing`. Turning it on again in the console resets the count.
- When KRIN turns an endpoint off, your organization's owners and admins get an email. Fix the endpoint, then turn it on again in Settings, Webhooks.
- Replay sends delivered or failed deliveries again, to the endpoint's current URL. It covers events up to 30 days old, up to 1000 a call. The endpoint must be on.
- Deleting an endpoint deletes its secret. Deliveries still waiting fail as `endpoint_deleted`.

API keys can list endpoints and deliveries, delete endpoints and replay, on their own side only.

## What a delivery looks like

Each delivery is a `POST` with a JSON body:

```json
{
  "id": "whe_...",
  "type": "conversion.held",
  "created_at": "2026-12-05T14:00:00Z",
  "data": { },
  "test": false
}
```

- `id` is the event id. It's also in the `Krin-Event-Id` header. Dedupe on it.
- `data` is the object the event is about, in the same shape the API returns it, for example a conversion, a statement or a placement. The API reference shows the shape for each type.
- `test` is `true` for sandbox and test events, which never move money.

Headers: `Krin-Signature`, `Krin-Event-Id` (`whe_...`), `Krin-Delivery` (`whd_...`, one per endpoint), `Content-Type: application/json` and `User-Agent: KRIN-Webhooks/1`.

## Errors

`webhook_limit` (409) and `webhook_disabled` (409). See [Error codes](https://docs.krin.io/en/errors/).
