# Webhooks

> Be told when a check, analysis or article finishes, when something is approved or published, and when credits run low, with signed deliveries you can verify.

Web page: https://www.gotopeach.com/docs/api-webhooks (updated 2026-11-03)

> **In short.** Add an https endpoint in the developer console and choose its events. Peach posts each event to it as JSON, signed with the endpoint's secret using the Standard Webhooks scheme. Answer with a 2xx within 10 seconds; anything else is retried.

## Setting up an endpoint

In the developer console, on the Webhooks page, the account's owner or an admin adds an endpoint:

- **Address:** https, on the standard port. Addresses on private networks are refused.
- **Events:** at least one, from the list below.
- **Sites:** optionally, only events about some sites. See [Events and sites](#events-and-sites).
- **Signing secret:** `whsec_…`, shown once. Keep it in a private setting on your server. You can make a new one at any time, and the old one stops working at once.

An account can have up to 10 endpoints. **Send test** posts a `webhook.test` event to check your endpoint, and the console lists recent deliveries with their status, response and timing.

## What Peach sends

A `POST` with a JSON body:

```json
{
  "id": "msg_2f6c1d0e8a7b4c3d9e1f0a2b",
  "type": "check.finished",
  "createdAt": "2026-11-03T09:20:11.000Z",
  "data": { "checkId": "…", "siteId": "…", "domain": "acme.com", "status": "done", "kind": "manual" }
}
```

and three headers:

| Header | What it holds |
|---|---|
| `webhook-id` | The event's id, the same as `id` in the body. A retry keeps it, so use it to ignore an event you already handled. |
| `webhook-timestamp` | When this attempt was sent, in seconds since 1970 (UTC). |
| `webhook-signature` | `v1,` and the signature, in base64. |

## Events

| Event | Sent when | Fields in `data` |
|---|---|---|
| `check.finished` | A check of a site finished: one started through the API, in the app, or Peach's weekly check | checkId, siteId, domain, status, kind |
| `analysis.finished` | An analysis started through the API finished | jobId, analysisId, url |
| `topics.generated` | A topic batch started through the API finished | jobId, topics (how many) |
| `article.generated` | An article started through the API was written | jobId, articleId, outlineId |
| `opportunity.created` | New opportunities were found after a check | siteId, domain, checkId, created (how many) |
| `article.approved` | An article was approved | articleId, title, siteId, approvedBy |
| `article.published` | An article was published or published again, including through POST /articles/{id}/published | articleId, title, url, target, updated, siteId |
| `proof.verdict` | A day 7, 14 or 30 re-check of a published article has its result | articleId, siteId, day, verdict, final |
| `report.ready` | A weekly report with something in it is ready | reportId, siteId, domain, weekStart |
| `job.failed` | A background job started through the API failed. Its credits are refunded. | jobId, route, status, error |
| `credits.added` | Credits came in: the monthly grant, pilot credits or a purchase. A refunded purchase is sent with a negative amount. | kind (monthly, pilot, purchase or purchase_refunded), credits, balance |
| `credits.low` | The balance fell below the low-balance threshold | balance, threshold |
| `credits.depleted` | The balance reached zero, or a call was refused because the balance was too low for it | balance, required (when a call was refused) |

### Events and sites

An endpoint limited to some sites gets every event about one of those sites, and the `credits.*` events, which are about the whole account. An event Peach can't tie to a site (a job that failed before it could start) goes only to endpoints that cover every site.

## Verifying the signature

The signature is an HMAC-SHA256 of `webhook-id`, `webhook-timestamp` and the raw body, joined with full stops, keyed with your secret after `whsec_`, decoded from base64. This is the [Standard Webhooks](https://www.standardwebhooks.com/) scheme, so its libraries work too.

Verify the raw body exactly as it arrived, before any JSON parsing. In Node:

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

// rawBody: the request body as a string, exactly as received.
// secret: the endpoint's signing secret (whsec_...), read from your server's settings.
export function verifyPeachWebhook(rawBody, headers, secret) {
  const id = headers['webhook-id']
  const timestamp = headers['webhook-timestamp']
  const signatures = headers['webhook-signature']
  if (!id || !timestamp || !signatures) return false

  // Refuse deliveries more than 5 minutes old (or ahead), so a copied one can't be replayed.
  if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false

  const key = Buffer.from(secret.replace(/^whsec_/, ''), 'base64')
  const expected = crypto.createHmac('sha256', key).update(`${id}.${timestamp}.${rawBody}`).digest()

  return signatures.split(' ').some((entry) => {
    const [version, value] = entry.split(',')
    if (version !== 'v1' || !value) return false
    const given = Buffer.from(value, 'base64')
    return given.length === expected.length && crypto.timingSafeEqual(given, expected)
  })
}
```

With Express, read the body raw on that route:

```js
app.post('/webhooks/peach', express.raw({ type: 'application/json' }), (req, res) => {
  if (!verifyPeachWebhook(req.body.toString('utf8'), req.headers, process.env.PEACH_WEBHOOK_SECRET)) {
    return res.status(400).end()
  }
  const event = JSON.parse(req.body)
  // Handle event.type and event.data here. Skip event.id if you have seen it before.
  res.status(204).end()
})
```

## Delivery and retries

- Answer with any 2xx status within 10 seconds. Do slow work after answering.
- Anything else, or no answer, is retried after 1 minute, 5 minutes, 30 minutes, 2 hours and 6 hours: six attempts in all. After that the delivery is marked failed.
- Deliveries can arrive more than once and out of order. Use the event `id` to ignore repeats, and `createdAt` to order them.
- A test event is sent once and not retried.
- An endpoint whose last 50 attempts in a row all failed is turned off. The console shows it as Off; turn it back on there once it answers again.
