# Webhooks

> Events, signatures, retries and redelivery.

activQC tells your server when something happens: a run finished, a verdict changed, a person decided, a draft was
submitted. Each webhook is signed, retried until your server takes it, and kept in an event log you can read and
replay.

## Add an endpoint

In the console: **Developers → Webhooks**. Or through the API:

```bash
curl -s -X POST "$ACTIVQC_BASE_URL/v1/webhook_endpoints" \
  -H "Authorization: Bearer $ACTIVQC_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{ "url": "https://api.yourlabel.com/activqc", "enabled_events": ["qc.run.completed", "qc.review.decided"] }'
```

The answer includes the **signing secret**, once. An empty `enabled_events` list means every event. The URL must be
`https` and reachable from the internet.

## Live and test

An endpoint hears **live** events or **test** events, never both. Made in the console it is live unless you choose
test; made through the API it is the kind of the key that makes it (`mode` in the answer). An endpoint made before
this choice existed is `both` until you choose on the Webhooks page. Every event says which it is:

```json
{ "id": "evt_7c1e9a2b3c4d", "type": "qc.run.completed", "created_at": "2026-11-25T09:41:16Z", "livemode": true, "data": { } }
```

## Events

| Event | When |
|---|---|
| `qc.run.completed` | A run has its first verdict. `matching` says where each track's matching result came from. |
| `qc.run.verdict_changed` | An answer or a re-check changed the verdict. |
| `qc.clarification.created` / `qc.clarification.answered` | A question was asked, or answered. |
| `qc.review.opened` | A release went to a person. |
| `qc.review.decided` | A person decided: `final_decision`, the reasons and a note for the artist. |
| `release_draft.submitted` | A draft was sent for checking (Draft API or the embedded builder). |
| `audio.classification.completed` | A vocal or instrumental batch is answered. |
| `ping` | A test you sent from the console or `POST /v1/webhook_endpoints/{id}/test`. |

## Check the signature

Every delivery carries `X-Wqc-Signature: t=<unix time>,v1=<hex>`. The `v1` value is an HMAC-SHA256, made with your
signing secret, of `<t>.<raw body>`. Reject the delivery if the signature does not match or `t` is more than five
minutes away from your clock. While you rotate a secret, a header carries one `v1` per secret; accept any that
matches.

```js
import crypto from 'node:crypto'

export function verify(rawBody, header, secret) {
  const parts = Object.fromEntries(header.split(',').map((p) => p.split('=')))
  const signatures = header.split(',').filter((p) => p.startsWith('v1=')).map((p) => p.slice(3))
  const fresh = Math.abs(Date.now() / 1000 - Number(parts.t)) < 300
  const expected = crypto.createHmac('sha256', secret).update(`${parts.t}.${rawBody}`).digest('hex')
  return fresh && signatures.some((s) => s.length === expected.length && crypto.timingSafeEqual(Buffer.from(s), Buffer.from(expected)))
}
```

```ruby
def verify(raw_body, header, secret)
  t = header[/t=(\d+)/, 1].to_i
  expected = OpenSSL::HMAC.hexdigest("SHA256", secret, "#{t}.#{raw_body}")
  fresh = (Time.now.to_i - t).abs < 300
  fresh && header.scan(/v1=(\h+)/).flatten.any? { |sig| ActiveSupport::SecurityUtils.secure_compare(sig, expected) }
end
```

Sign the **raw** body exactly as received, before any JSON parsing.

## Retries

Answer with any `2xx` within ten seconds. Anything else (or no answer) is retried after 1 minute, 5 minutes,
30 minutes, 2 hours and 6 hours, then hourly for three days. Use the event's `id` to ignore a delivery you have
already handled.

Every event is kept in the event log (`GET /v1/events`), including ones that reached no endpoint, and any of them
can be sent again with `POST /v1/events/{id}/redeliver`, to endpoints of its kind. A delivery that is still being
retried is left to its own retries (`requeued` counts those sent now). Tests and sending again are limited to a few a
minute for each account (`429 rate_limited`).
