# Webhooks & Event Dispatching

> Subscribing to collection data changes with HMAC-SHA256 signature verification.

- **Category:** Build & Integrate
- **Canonical Guide:** https://pottr.tangble.com/docs/webhooks

---

>
Subscribing to collection data changes with HMAC-SHA256 signature verification.

## Supported Events

<ul>
<li>`entry.created`: Triggered when a new entry is created via `POST`.</li>
<li>`entry.updated`: Triggered when an entry is updated via `PUT` or `PATCH`.</li>
<li>`entry.deleted`: Triggered when an entry is soft-deleted via `DELETE`.</li>
<li>`*`: Wildcard event triggering on all three operations.</li>
</ul>

## Managing Webhooks

Webhooks are managed via REST routes requiring the **Secret Key** (`sk_live_...`):

<table class="docs-table">
<thead>
<tr>
<th>Method</th>
<th>Endpoint</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>GET</td>
<td>`/webhooks`</td>
<td>List all registered webhooks.</td>
</tr>
<tr>
<td>POST</td>
<td>`/webhooks`</td>
<td>Register a new webhook (`url`, `event`, optional `collection`). Returns signing secret.</td>
</tr>
<tr>
<td>DELETE</td>
<td>`/webhooks/{id}`</td>
<td>Delete a webhook subscription by ID.</td>
</tr>
<tr>
<td>GET</td>
<td>`/webhooks/{id}`</td>
<td>Fetch one webhook.</td>
</tr>
<tr>
<td>PUT</td>
<td>`/webhooks/{id}`</td>
<td>Update the `url`, `event`, `collection` or `active` flag.</td>
</tr>
<tr>
<td>POST</td>
<td>`/webhooks/{id}/regenerate-secret`</td>
<td>Issue a new signing secret. The old one stops working immediately.</td>
</tr>
<tr>
<td>POST</td>
<td>`/webhooks/{id}/test`</td>
<td>Send a test ping and return latency and status. Pro and Business only.</td>
</tr>
</tbody>
</table>

## Webhook Payload Structure

**File: `Webhook JSON Payload`**

```json
{
  "event": "entry.created",
  "timestamp": 1714999999,
  "payload": {
    "collection": "tasks",
    "entry": {
      "id": "42",
      "title": "Deploy update",
      "created_at": "2026-05-06 12:00:00"
    }
  }
}
```

## Signature Verification (HMAC-SHA256)

Every delivery includes an `X-Pottr-Signature` header containing `sha256=<hex_hash>`. Compute the HMAC using the raw request body and your webhook secret:

**File: `verify-webhook.js (Node.js)`**

```javascript
const crypto = require('crypto');

function verifyPottrWebhook(rawBodyBuffer, signatureHeader, secret) {
  const expectedSignature = 'sha256=' + crypto
    .createHmac('sha256', secret)
    .update(rawBodyBuffer)
    .digest('hex');

  return crypto.timingSafeEqual(
    Buffer.from(signatureHeader),
    Buffer.from(expectedSignature)
  );
}
```

## Security & Delivery Rules

<ul>
<li>**HTTPS Destination Required:** Webhook URLs must use `https://`.</li>
<li>**SSRF Protections:** Localhost, loopback IPs (`127.0.0.1`), private subnets (`10.0.0.0/8`, `192.168.0.0/16`), and raw IP addresses are rejected.</li>
<li>**Background Delivery:** Deliveries are sent by WP-Cron after the API response, so they never slow down your requests. Each attempt has a 5-second timeout, so acknowledge with `2xx` immediately and do the work afterwards. (Sites that disable WP-Cron deliver inline.)</li>
<li>**Delivery Log:** Every attempt is logged with its response. Any non-2xx response is recorded as `failed`. Pottr does not retry failed deliveries, so make your endpoint idempotent and use the log to investigate.</li>
<li>**Retention:** Delivery history is kept for your plan's log retention period.</li>
<li>**Plan Limits:** Free allows 1 webhook, Pro 10, Business unlimited.</li>
</ul>
