# Webhooks

> Get a signed POST on your server for new payments, refunds, goal completions, alerts and a daily summary, and verify each one.

Webhooks push events from Reveata to your own server as they happen, so you don't have to poll the [API](https://reveata.com/docs/api-and-cli). An admin of the website adds endpoints in **Site settings → Developer → Webhooks**.

## Events

| Event | When it is sent |
| --- | --- |
| `payment.created` | A new payment or a subscription renewal is recorded, with the channel, source and campaign it is credited to. |
| `payment.refunded` | A refund is recorded (amounts are negative). |
| `goal.completed` | A visitor completes a goal. At most one per goal per minute; `skippedSinceLast` counts the completions in between. Use the [goal completions API](https://reveata.com/api-reference) for exact counts. |
| `alert.fired` | One of the website's alerts or reports fires. |
| `summary.daily` | Once a day after midnight in the website's timezone: yesterday's visitors, goal completions, new customers and net revenue. |
| `webhook.test` | Only when you press **Send test**. |

## What a delivery looks like

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

```json
{
  "id": "evt_4kJ2…",
  "type": "payment.created",
  "createdAt": "2026-10-22T09:14:03.120Z",
  "website": { "id": "66f1…", "domain": "example.com" },
  "data": {
    "payment": {
      "transactionId": "ch_3P…",
      "type": "new",
      "amount": 4900,
      "currency": "USD",
      "attribution": { "channel": "organic_search", "source": "Google" }
    }
  }
}
```

Amounts are in minor units (`4900` is $49.00). These headers come with it:

| Header | Value |
| --- | --- |
| `Reveata-Event-Id` | The event id, the same on every retry. Store it to ignore duplicates. |
| `Reveata-Event` | The event type, e.g. `payment.created`. |
| `Reveata-Timestamp` | When this attempt was signed, in Unix seconds. |
| `Reveata-Signature` | `t=<timestamp>,v1=<signature>` |

## Verify the signature

When you add an endpoint, Reveata shows its signing secret once (`whsec_…`). Keep it on your server. The signature is a hex HMAC-SHA256 of `<timestamp>.<raw request body>`, keyed with that secret.

1. Read the raw body before any JSON parsing changes it.
2. Split `Reveata-Signature` into `t` and `v1`.
3. Compute `HMAC-SHA256(secret, t + "." + rawBody)` as hex and compare it with `v1` in constant time.
4. Refuse the request when `t` is more than 5 minutes away from your clock (replay protection).

```js
// Node.js (Express): app.post('/webhooks/reveata', express.raw({ type: 'application/json' }), handler)
import { createHmac, timingSafeEqual } from 'node:crypto';

export function verifyReveata(rawBody, header, secret, toleranceSec = 300) {
  const parts = Object.fromEntries(header.split(',').map((p) => p.split('=')));
  const age = Math.abs(Date.now() / 1000 - Number(parts.t));
  if (!parts.t || !parts.v1 || age > toleranceSec) return false;
  const expected = createHmac('sha256', secret).update(`${parts.t}.${rawBody}`).digest('hex');
  const a = Buffer.from(expected);
  const b = Buffer.from(parts.v1);
  return a.length === b.length && timingSafeEqual(a, b);
}
```

```python
# Python
import hashlib, hmac, time

def verify_reveata(raw_body: bytes, header: str, secret: str, tolerance: int = 300) -> bool:
    parts = dict(p.split("=", 1) for p in header.split(","))
    if abs(time.time() - int(parts.get("t", "0"))) > tolerance:
        return False
    signed = f"{parts['t']}.".encode() + raw_body
    expected = hmac.new(secret.encode(), signed, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, parts.get("v1", ""))
```

**Roll secret** issues a new secret at once; the old one stops signing immediately, so update your server right after.

## Answer quickly

Return any `2xx` status within 10 seconds. Do slow work after you answer. Redirects are not followed and count as failures.

## Retries

A delivery that fails (no answer, a timeout, or a status outside 200–299) is retried after 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours and 12 hours: 7 attempts over about 21 hours. The **Deliveries** list of an endpoint shows every event with its status, attempts, last HTTP status and error, and lets you send a finished one again (with the same event id).

If an endpoint fails 20 attempts in a row for more than a day, Reveata turns it off, drops its queued events and emails the website owner. Fix the endpoint and switch it back on; events from while it was off are not sent.

## Addresses

Endpoints must be public `https://` addresses. Private, local and cloud-metadata addresses are refused, both when you add the endpoint and on every delivery.
