# Webhooks

> Get told when something happens, such as a new version, instead of polling. Every delivery is signed, so you can check it came from aeyho.

On the web: https://www.aeyho.com/docs/api/webhooks

## Making a webhook

```bash
curl -X POST https://www.aeyho.com/api/v1/webhooks \
  -H "Authorization: Bearer $AEYHO_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{"url": "https://example.com/hooks/aeyho", "events": ["version.created", "comment.resolved"]}'
```

The answer has a `secret` (`whsec_…`). It's shown only this once: keep it with your other secrets.

- The link must be `https`, on a public name (not an address), on the standard port, with no login in it.
- Leave out `events` to get every event.
- An account has at most 5 webhooks.
- Webhooks made with a test key get only the test event. See [test mode](/docs/api/test-mode).

## Events

| Event | When |
|---|---|
| `version.created` | A reel has a new version: made, changed, fixed or restored. |
| `comment.resolved` | A fix resolved a comment. One event per comment. |
| `reel.done` | A reel or carousel is made. |
| `reel.failed` | A reel or carousel couldn't be made. |
| `credits.low` | The credit balance is running low. |
| `post.published` | A scheduled post went out. |
| `webhook.test` | You asked for a test (`POST /webhooks/{webhookId}/test`). |

## What a delivery looks like

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

```json
{
  "type": "comment.resolved",
  "timestamp": "2026-11-28T10:15:00.000Z",
  "data": { "commentId": "c_123", "versionId": "v_456", "projectId": "reel_123" }
}
```

`projectId` is the reel's id. For `version.created`, `data` has `version` (the new version) and `projectId`. Fetch `GET /reels/{reelId}/versions` for the version in the API's own shape.

It comes with three headers, as the [Standard Webhooks](https://www.standardwebhooks.com/) spec has them:

| Header | What it is |
|---|---|
| `webhook-id` | The delivery's id (`msg_…`). The same on every retry: use it to skip a delivery you've already handled. |
| `webhook-timestamp` | When this try was sent, in Unix seconds. |
| `webhook-signature` | `v1,` and the signature, in base64. |

## Answering

Answer with any `2xx` within 10 seconds. Do the slow work after you answer.

Anything else (another status, a timeout, no answer) is tried again after 30 seconds, 2 minutes, 10 minutes, 1 hour, 6 hours and 12 hours. After the last try the delivery is marked failed. `GET /webhooks/{webhookId}/deliveries` shows the last 50 deliveries, with their status, tries and the last answer.

## Checking the signature

The signature is an HMAC-SHA256 of `{webhook-id}.{webhook-timestamp}.{body}`, keyed with your secret: the part after `whsec_`, decoded from base64. Check it against the raw body, exactly as it arrived, before you parse it. Also refuse a timestamp more than 5 minutes away from now, so an old delivery can't be sent again.

### Node

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

/** True when a delivery is from aeyho. `body` is the raw body as a string. */
export function verifyAeyho(secret, headers, body) {
  const id = headers["webhook-id"];
  const timestamp = headers["webhook-timestamp"];
  const signatures = headers["webhook-signature"] ?? "";
  if (!id || !timestamp) return false;
  if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false;
  const key = Buffer.from(secret.replace(/^whsec_/, ""), "base64");
  const expected = createHmac("sha256", key).update(`${id}.${timestamp}.${body}`).digest();
  return signatures.split(" ").some((s) => {
    const [version, sig] = s.split(",");
    if (version !== "v1" || !sig) return false;
    const got = Buffer.from(sig, "base64");
    return got.length === expected.length && timingSafeEqual(got, expected);
  });
}
```

With Express, read the raw body:

```js
import express from "express";

const app = express();
app.post("/hooks/aeyho", express.raw({ type: "application/json" }), (req, res) => {
  const body = req.body.toString("utf8");
  if (!verifyAeyho(process.env.AEYHO_WEBHOOK_SECRET, req.headers, body)) return res.sendStatus(401);
  res.sendStatus(204);
  const event = JSON.parse(body);
  // handle event.type here, once per webhook-id
});
```

### Python

```python
import base64
import hashlib
import hmac
import time


def verify_aeyho(secret: str, headers: dict, body: bytes) -> bool:
    """True when a delivery is from aeyho. `body` is the raw body, as bytes."""
    msg_id = headers.get("webhook-id")
    timestamp = headers.get("webhook-timestamp")
    signatures = headers.get("webhook-signature", "")
    if not msg_id or not timestamp:
        return False
    if abs(time.time() - int(timestamp)) > 300:
        return False
    key = base64.b64decode(secret.removeprefix("whsec_"))
    signed = f"{msg_id}.{timestamp}.".encode() + body
    expected = base64.b64encode(hmac.new(key, signed, hashlib.sha256).digest()).decode()
    return any(
        hmac.compare_digest(s.split(",", 1)[1], expected)
        for s in signatures.split()
        if s.startswith("v1,")
    )
```

With Flask:

```python
from flask import Flask, request

app = Flask(__name__)


@app.post("/hooks/aeyho")
def aeyho_hook():
    headers = {k.lower(): v for k, v in request.headers.items()}
    if not verify_aeyho(AEYHO_WEBHOOK_SECRET, headers, request.get_data()):
        return "", 401
    event = request.get_json()
    # handle event["type"] here, once per webhook-id
    return "", 204
```

Libraries that follow the Standard Webhooks spec check these signatures too.

## Testing

Send yourself a test event, then look at the delivery:

```bash
curl -X POST https://www.aeyho.com/api/v1/webhooks/wh_123/test \
  -H "Authorization: Bearer $AEYHO_KEY"

curl https://www.aeyho.com/api/v1/webhooks/wh_123/deliveries \
  -H "Authorization: Bearer $AEYHO_KEY"
```

To stop a webhook, `DELETE /webhooks/{webhookId}`.

## Try it

```bash
curl https://www.aeyho.com/api/v1/webhooks \
  -H "Authorization: Bearer $AEYHO_KEY"
```
