# Webhooks

> Receive signed events when verifications, screenings and cases change.

## Registering an endpoint

Register an HTTPS endpoint under **Developers → Webhooks** in the [dashboard](https://app.aqoon.si/developers/webhooks). An endpoint belongs to one environment of one application and subscribes to the event kinds you choose. Registering endpoints needs a member with the `webhooks:write` permission (owners and developers); API keys cannot manage webhooks.

The signing secret is shown once. Store it where only your app can read it, like the API key. Use separate endpoints, or at least separate secrets, for sandbox and live.

## The payload

Each delivery is a `POST` with a JSON:API `events` resource. Events carry identifiers, never names or other personal data: fetch the resource with your API key when you need its current state.

```json
{
  "data": {
    "type": "events",
    "id": "0196d62b-7a10-7c55-8e2f-1a2b3c4d5e6f",
    "attributes": {
      "kind": "verification.completed",
      "timestamps": { "created": "2026-11-27T09:15:41.102Z" }
    },
    "relationships": {
      "resource": {
        "data": {
          "type": "verifications",
          "id": "0196d62a-4c1e-7d2b-9f3a-6b1c2d3e4f50"
        }
      }
    }
  }
}
```

Read `attributes.kind` for the event and `relationships.resource.data` for the resource it is about.

## Events

These are every event kind an endpoint can subscribe to.

| Event                                                | Sent when                                                                                                  |
| ---------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| `verification.completed`                             | A verification passed                                                                                      |
| `verification.failed`                                | A verification failed                                                                                      |
| `verification.expired`                               | A verification expired before the person finished it                                                       |
| `verification.duplicateFound`                        | The [duplicate-face search](people.md#duplicate-faces) found another person in your account with this face |
| `verification.screened`                              | A verified person was screened after a list became available                                               |
| `person.erased`                                      | A person's [erasure](people.md#erasing-a-person) has finished                                              |
| `document.assessed`                                  | A business document was read and compared with the registry                                                |
| `screening.potentialMatch`                           | A screening or monitor found a potential match                                                             |
| `screening.listingRemoved`                           | A listed party a subject matched was removed from its list                                                 |
| `screening.listingRestored`                          | A listed party that had been removed is back on its list                                                   |
| `risk.levelChanged`                                  | A subject's [risk](risk.md) level changed                                                                  |
| `case.opened`, `case.resolved`                       | A case was opened or decided                                                                               |
| `apiKey.created`, `apiKey.rotated`, `apiKey.revoked` | A key was created, rotated or revoked                                                                      |

Events reach the endpoints of the application whose API key caused them. Work started from the dashboard is recorded in `GET /v1/events` but has no endpoint to deliver to.

## Verifying signatures

Every delivery carries these headers:

| Header                | Meaning                                                                         |
| --------------------- | ------------------------------------------------------------------------------- |
| `Aqoonsi-Event-Id`    | The event's ID; the same on every retry                                         |
| `Aqoonsi-Delivery-Id` | This delivery's ID                                                              |
| `Aqoonsi-Timestamp`   | Unix seconds when it was signed                                                 |
| `Aqoonsi-Signature`   | `v1=<hex>`, an HMAC-SHA256 of `timestamp + "." + body` with your signing secret |

Verify the signature against the **raw** request body, before you parse it, and reject timestamps more than five minutes old. During a secret rotation the header holds several comma-separated `v1=` values; accept the request if any one matches.

```js
import { createHmac, timingSafeEqual } from "node:crypto";

// rawBody is the request body as a Buffer, before JSON parsing.
export function isAqoonsiWebhook(rawBody, timestamp, signature, secret) {
  if (!timestamp || !/^\d+$/.test(timestamp) || !signature) return false;
  if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false;

  const expected = createHmac("sha256", secret)
    .update(timestamp + ".")
    .update(rawBody)
    .digest();

  return signature.split(",").some((part) => {
    const match = /^v1=([\da-f]{64})$/i.exec(part.trim());
    return (
      match !== null && timingSafeEqual(Buffer.from(match[1], "hex"), expected)
    );
  });
}
```

## Responding and retries

Return a `2xx` as soon as you have stored the event durably, then process it asynchronously. Any other response, or no response, is retried after 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours and 24 hours.

- Deliveries can arrive more than once and out of order. Deduplicate by `Aqoonsi-Event-Id`, and read the resource for its current state instead of trusting the order of events.
- An endpoint that keeps failing is disabled automatically. Re-enable it in the dashboard once it is fixed.
- Inspect every attempt and request a retry under **Developers → Deliveries** in the [dashboard](https://app.aqoon.si/developers/deliveries).

## Rotating the signing secret

Rotate the secret from the endpoint's page in the dashboard. The old secret keeps signing alongside the new one for 24 hours, so deploy the new secret within that window.
