# Receive approval webhooks

Subscribe to `request.approval_required` to learn when an operation is waiting for multi-user approval. The event identifies the pending request. An eligible approver still needs to [submit a signed decision](/develop/approvals).

Approval webhooks do not depend on managed transaction services. Discover the supported events and signing public key through `GET /v1/system-info`.

## Register a receiver

Use an HTTPS URL reachable from your vault deployment. Private, loopback, and other prohibited destinations are rejected. Your caller needs the `manage_webhooks` Administrative Policy capability.

Save a subscription body as `webhook.json`:

```json
{
  "url": "https://your-service.example.com/crypto-vault/approvals",
  "events": ["request.approval_required"]
}
```

Set `CV_BASE` and `CV_TOKEN` for your deployment. Compute the [mutation authentication headers](/develop/authentication/machine-users) for `POST /v1/webhooks` and the exact bytes of `webhook.json`, then submit:

```bash
curl --fail-with-body --silent --show-error \
  -X POST "$CV_BASE/v1/webhooks" \
  -H "Authorization: $CV_TOKEN" \
  -H "Content-Type: application/json" \
  -H "X-Request-Timestamp: $TS_HEX" \
  -H "X-Request-Nonce: $NONCE_HEX" \
  -H "X-Request-Assertion: $ASSERTION" \
  --data-binary @webhook.json
```

A new subscription is enabled. If creation returns `202`, preserve the request ID and follow the [request lifecycle](/develop/signing/request-lifecycle) before treating the subscription as active.

Use `GET /v1/webhooks` to list subscriptions and `GET /v1/webhooks/{webhook_id}` to inspect one. Use `PATCH /v1/webhooks/{webhook_id}` to change its URL, events, or status, and `DELETE` on the same path to remove it. See the [API reference](/api-reference) for complete schemas.

## Verify deliveries

Crypto Vault sends the event as JSON with these headers:

| Header | Meaning |
|---|---|
| `X-CV-Event-Id` | Event identifier; compare it with the signed body's `event_id` |
| `X-CV-Timestamp` | Decimal Unix timestamp in seconds for this delivery attempt |
| `X-CV-Signature` | `ed25519=` followed by the signature in standard Base64 |

The Ed25519 signature covers the timestamp, a literal dot, and the **original body bytes**: `timestamp + "." + body`. Preserve the raw body before JSON parsing. Re-serializing the JSON can change the bytes and invalidate verification.

Retrieve the public key from your configured vault URL over HTTPS. Do not take a key or vault URL from the incoming notification:

```bash
curl --fail-with-body --silent --show-error "$CV_BASE/v1/system-info" \
  | jq -er '.webhook_signing_public_key' > webhook-public.pem
```

For a captured delivery, save the raw body as `body.json`. Save this example as `verify-webhook.mjs` and run it with Node.js 24. Pass the three header values in the order shown. The example uses a five-minute freshness tolerance; choose a tolerance appropriate for your receiver and keep its clock synchronized.

```js
import { readFileSync } from 'node:fs';
import { createPublicKey, verify } from 'node:crypto';

const [bodyPath, timestamp, signatureHeader, eventId] = process.argv.slice(2);
if (!bodyPath || !/^\d+$/.test(timestamp ?? '') ||
    !signatureHeader?.startsWith('ed25519=') || !eventId) {
  throw new Error('Usage: node verify-webhook.mjs BODY TIMESTAMP SIGNATURE EVENT_ID');
}
const seconds = Number(timestamp);
if (!Number.isSafeInteger(seconds) || Math.abs(Date.now() / 1000 - seconds) > 300) {
  throw new Error('Delivery timestamp is outside the accepted window');
}
const body = readFileSync(bodyPath);
const key = createPublicKey(readFileSync('webhook-public.pem'));
const signature = Buffer.from(signatureHeader.slice('ed25519='.length), 'base64');
const message = Buffer.concat([Buffer.from(`${timestamp}.`, 'utf8'), body]);
if (signature.length !== 64 || !verify(null, message, key, signature)) {
  throw new Error('Invalid webhook signature');
}
const event = JSON.parse(body.toString('utf8'));
if (event.event_id !== eventId) throw new Error('Event ID does not match the signed body');
if (event.schema_version !== 1 || event.event_type !== 'request.approval_required') {
  throw new Error('Unsupported event');
}
console.log('Verified approval notification:', event.event_id, event.data.request_id);
```

```bash
node verify-webhook.mjs body.json "$X_CV_TIMESTAMP" "$X_CV_SIGNATURE" "$X_CV_EVENT_ID"
```

## Acknowledge and deduplicate

After verification, durably record the event or enqueue it for processing before returning `2xx`. Keep a durable record of processed `event_id` values so repeated deliveries do not create duplicate work. A retry preserves the event ID and body but carries a new delivery timestamp and signature.

Crypto Vault retries network failures, timeouts, `408`, `429`, and `5xx` responses with backoff. Other unsuccessful responses are treated as terminal; redirects are not followed. Do not depend on unlimited retries. Use the approval-request API to reconcile pending work if your receiver was unavailable.

Read the current request before asking for a decision: a notification may arrive after the request has changed state. Acknowledging delivery does not approve, reject, or complete the operation.
