> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pocketsflow.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Webhooks

> Get a signed event on your server when a seller signs up, makes a sale, gets a refund or asks to withdraw.

Webhooks send your server an HTTPS `POST` the moment something happens in
your workspace, so your back office, risk checks and accounting stay in step
without polling.

## Events

| Event | When |
| - | - |
| `subaccount.created` | A seller signs up on your app. |
| `sale.paid` | A seller's sale is paid. |
| `sale.refunded` | A sale is refunded. |
| `withdrawal.requested` | A seller asks to withdraw and it waits for your approval. |
| `withdrawal.paid` | A withdrawal is paid out to the seller's bank. |
| `withdrawal.failed` | The bank transfer didn't go through. |
| `withdrawal.rejected` | You rejected a withdrawal. |

Subscribe to some of them, or to `*` for all (also the default).

## Add an endpoint

Up to 10 endpoints per workspace, `https://` only.

```bash theme={"system"}
curl -X POST https://api.pocketsflow.com/v1/enterprise/webhooks \
  -H "Authorization: Bearer ek_live_..." \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://hooks.example.com/pocketsflow", "events": ["withdrawal.requested", "sale.paid"] }'
```

The answer holds the endpoint's signing secret (`whsec_...`) **once**. Store
it as a secret; later reads show it masked. Lost it? Rotate it with
`POST /v1/enterprise/webhooks/{id}/rotate-secret`: the new one works at once.

With the SDK:

```ts theme={"system"}
const hook = await pf.enterprise.webhooks.create({
  url: "https://hooks.example.com/pocketsflow",
  events: ["withdrawal.requested"],
});
hook.secret; // whsec_..., shown once
await pf.enterprise.webhooks.test(hook.id); // sends a ping
```

## What you receive

```http theme={"system"}
POST /pocketsflow HTTP/1.1
Content-Type: application/json
X-Pocketsflow-Event: withdrawal.requested
X-Pocketsflow-Event-Id: evt_6c1f0b2a9d8e4f3a
X-Pocketsflow-Signature-V2: t=1764590400,v1=5f2b...

{
  "id": "evt_6c1f0b2a9d8e4f3a",
  "type": "withdrawal.requested",
  "created": 1764590400,
  "workspaceId": "65a0...",
  "data": {
    "id": "6745...",
    "userId": "auth0|6711a3d59e3f1a0012cd7788",
    "sellerName": "Maya Chen",
    "amount": "500.00",
    "currency": "USD",
    "feeUsd": "8.50",
    "pocketsflowFeeUsd": "5.00",
    "tenantFeeUsd": "3.50",
    "status": "pending"
  }
}
```

`data` is the same row the API answers: a withdrawal for `withdrawal.*`, a
transaction for `sale.*`, a sub-account for `subaccount.created`.

## Verify the signature

`v1` is the HMAC-SHA256, in hex, of `"<t>.<raw body>"` with your endpoint
secret. Check it before you trust the body, and reject old `t` values (say,
older than 5 minutes) to stop replays.

```ts SDK theme={"system"}
import { verifyWebhookSignature } from "pocketsflow";

app.post("/pocketsflow", express.raw({ type: "application/json" }), (req, res) => {
  const ok = verifyWebhookSignature(
    req.body.toString("utf8"),
    req.get("X-Pocketsflow-Signature-V2") ?? "",
    process.env.POCKETSFLOW_WEBHOOK_SECRET!,
  );
  if (!ok) return res.status(400).end();
  const event = JSON.parse(req.body.toString("utf8"));
  // dedupe on event.id, then handle event.type
  res.status(200).end();
});
```

```ts Node.js theme={"system"}
import crypto from "node:crypto";

function verify(rawBody: string, header: string, secret: string) {
  const parts = Object.fromEntries(header.split(",").map((p) => p.split("=")));
  const t = Number(parts.t);
  if (!t || Math.abs(Date.now() / 1000 - t) > 300) return false;
  const expected = crypto.createHmac("sha256", secret).update(`${t}.${rawBody}`).digest("hex");
  return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1 ?? ""));
}
```

## Retries and redelivery

* Answer with a `2xx` within 10 seconds. Anything else is a failure.
* A failed delivery is retried after 1 minute, 10 minutes and 1 hour.
* The same event can arrive twice: dedupe on `id` (also in
  `X-Pocketsflow-Event-Id`).
* `GET /v1/enterprise/webhooks/{id}/deliveries` lists the last 30 days, with
  each payload, status code and error.
  `POST .../deliveries/{deliveryId}/redeliver` sends one again (same event id,
  new signature).
* Turn an endpoint off without deleting it with
  `PATCH /v1/enterprise/webhooks/{id}` and `{ "active": false }`.

Full reference: [Webhooks](https://docs.pocketsflow.com/api-reference/enterprise.md#webhooks).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.