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

# Webhooks

> Receive real-time Bevits events over HTTPS with Standard Webhooks signatures and automatic retries.

Register an HTTPS URL and Bevits sends a `POST` request to it whenever an event occurs in your organization (email delivered, opened, or clicked; Official WhatsApp message read or replied; unsubscribe; new customer; order update; or purchase created through the API). Every delivery is signed and retried for about 3 days on failure.

```http theme={null}
POST /webhooks/bevits HTTP/1.1
Host: api.example.com
Content-Type: application/json
webhook-id: wev_0mgc2k1a7000a1b2c3d4e5f6g7h8
webhook-timestamp: 1795440181
webhook-signature: v1,K5oZfzN95Z9UVu1EsfQmfVNQhnkZ2pj9o9NDN/H/pI4=
bevits-event-type: email.clicked

{
  "id": "wev_0mgc2k1a7000a1b2c3d4e5f6g7h8",
  "object": "webhook_event",
  "type": "email.clicked",
  "api_version": "2026-11-23",
  "occurred_at": "2026-11-23T14:03:00.000Z",
  "created_at": "2026-11-23T14:03:01.120Z",
  "livemode": true,
  "data": {
    "customer": { "id": "cus_ckabc123", "email": "ana@example.com", "phone": "+5511988887777", "external_id": "u_8842" },
    "email": { "id": "0f5c2a9e", "subject": "Your coupon is here", "to": "ana@example.com" },
    "source": { "type": "flow", "id": "flw_ckdef456", "name": "Welcome" },
    "link": { "url": "https://store.example.com/coupon" },
    "user_agent": "Mozilla/5.0"
  }
}
```

* **Respond quickly:** return any `2xx` status within **15 seconds**. Enqueue the payload and process it asynchronously.
* **Verify the signature:** signatures follow the [Standard Webhooks](https://www.standardwebhooks.com/) spec, with libraries for Node.js, Python, PHP, Go, Ruby, Java, Rust, and C#.
* **Deduplicate on `webhook-id`:** events may be delivered more than once; `webhook-id` (`wev_…`) stays identical across retries and manual resends.

## Delivery guarantees

| Guarantee | Behavior |
| - | - |
| At-least-once delivery | Every event is persisted before sending and retried until your URL returns `2xx` or all 10 attempts finish (about 3 days). |
| Immutable `id` | The body `id` and `webhook-id` header (`wev_…`) never change across retries or manual resends. |
| No ordering guarantee | Retries and concurrent deliveries can arrive out of order. Sort by `occurred_at` when order matters. |
| 15-second timeout | Responses taking longer than 15 seconds fail with `timeout` and are retried. |
| 30-day retention | Delivery logs and attempt history are kept for 30 days for inspection and resend. |

## Create an endpoint

Create endpoints under **Settings → Webhooks** or via the API (requires the `write` scope because webhooks export customer data):

```bash theme={null}
curl https://api.bevits.com/v1/webhook-endpoints \
  -H "Authorization: Bearer $BEVITS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://api.example.com/webhooks/bevits",
    "events": ["email.clicked", "contact.unsubscribed", "whatsapp.message.replied"],
    "description": "ERP"
  }'
```

The `201` response returns the signing secret (`whsec_…`) **only once**. Store it on your server and verify the integration with a test event:

```bash theme={null}
curl https://api.bevits.com/v1/webhook-endpoints/wep_0mgc2k1a7000a1b2c3d4e5f6g7/test \
  -H "Authorization: Bearer $BEVITS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "type": "order.paid" }'
```

The test event contains sample data with `livemode: false` and returns the HTTP status your URL responded with, the duration in milliseconds, and the start of the response body.

| Field | Rule |
| - | - |
| `url` | Public `https` URL, up to 2,048 characters, no embedded credentials. Redirects are not followed. |
| `events` | Event types from the [catalog](#event-catalog), or `["*"]` to subscribe to all current and future types. |
| `description` | Optional, up to 255 characters. |

Each organization supports up to **20 endpoints**.

## Verify the signature

The `webhook-signature` header uses the format `v1,<hmac>`, where `<hmac>` is the base64-encoded HMAC-SHA256 of `{webhook-id}.{webhook-timestamp}.{raw_body}`. The signing key is the base64-decoded bytes after `whsec_`.

Always verify against the **raw request body** before parsing JSON.

```javascript Node.js theme={null}
import { Webhook } from "standardwebhooks";

const wh = new Webhook(process.env.BEVITS_WEBHOOK_SECRET);

app.post("/webhooks/bevits", express.raw({ type: "application/json" }), (req, res) => {
  let event;

  try {
    event = wh.verify(req.body, req.headers);
  } catch {
    return res.status(400).send("invalid signature");
  }

  queue.add(event); // process asynchronously
  res.sendStatus(200);
});
```

```python Python theme={null}
from standardwebhooks.webhooks import Webhook

wh = Webhook(os.environ["BEVITS_WEBHOOK_SECRET"])

@app.post("/webhooks/bevits")
def bevits_webhook(request):
    try:
        event = wh.verify(request.body, request.headers)
    except Exception:
        return Response(status=400)

    queue.put(event)  # process asynchronously
    return Response(status=200)
```

```php PHP theme={null}
use StandardWebhooks\Webhook;

$wh = new Webhook(getenv('BEVITS_WEBHOOK_SECRET'));

try {
    $event = $wh->verify(file_get_contents('php://input'), getallheaders());
} catch (Exception $e) {
    http_response_code(400);
    exit;
}

http_response_code(200);
```

Manual verification without a library:

```javascript theme={null}
import { createHmac, timingSafeEqual } from "node:crypto";

function isValid(secret, headers, rawBody) {
  const id = headers["webhook-id"];
  const timestamp = Number(headers["webhook-timestamp"]);

  // Reject timestamps more than 5 minutes from your clock to prevent replay attacks.
  if (Math.abs(Date.now() / 1000 - timestamp) > 300) return false;

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

  return headers["webhook-signature"].split(" ").some((signature) => {
    const received = Buffer.from(signature.replace(/^v1,/, ""), "base64");

    return received.length === expected.length && timingSafeEqual(received, expected);
  });
}
```

> [!NOTE]
>
> Each attempt is re-signed with its send timestamp. A retry of an older event arrives with a current `webhook-timestamp` and passes the 5-minute replay check.

### Rotate the signing secret

Call `POST /v1/webhook-endpoints/{endpoint_id}/rotate-secret` to generate a new secret. The current secret continues signing alongside the new one for `expire_current_in_hours` (default **24**, maximum **168**; `0` expires it immediately). During that overlap window, `webhook-signature` contains both space-separated signatures so you can roll out the new secret without dropping events.

## Retries, concurrency, and circuit breaker

| Attempt | Delay after previous attempt |
| - | - |
| 1 | immediate |
| 2 | 1 minute |
| 3 | 5 minutes |
| 4 | 30 minutes |
| 5 | 2 hours |
| 6 | 5 hours |
| 7 | 10 hours |
| 8 | 14 hours |
| 9 | 20 hours |
| 10 | 24 hours |

* Any non-`2xx` status (including `4xx`), timeout, or connection error triggers a retry.
* Delays include up to **10%** jitter to spread traffic after an outage.
* After the 10th failed attempt, the delivery moves to `failed` and can be resent manually.
* **Concurrency:** each URL receives at most **6 concurrent requests**.
* **Circuit breaker:** after 5 consecutive failures, Bevits pauses deliveries to the endpoint for increasing intervals (30 seconds up to 1 hour) and sends a single probe delivery. A `2xx` resumes normal delivery immediately; paused deliveries do not lose retry attempts.

### Automatic disable

If **every** attempt to an endpoint fails for **5 consecutive days**, Bevits disables it (`disabled_reason: "failing"`) and notifies store administrators by email. A single `2xx` response resets the counter.

While an endpoint is auto-disabled, new events continue to be recorded for up to 30 days as `failed` deliveries with `error_code: "endpoint_disabled"`. After fixing your server, re-enable the endpoint (`status: "enabled"`) and call `/recover` to replay missed events. Manually disabled endpoints (`disabled_reason: "manual"`) do not record new events.

## Delivery log, resend, and recovery

| Operation | Route |
| - | - |
| List deliveries (filter by `endpoint_id`, `status`, `event_type`) | `GET /v1/webhook-deliveries` |
| Inspect one delivery, its signed payload, and all attempts | `GET /v1/webhook-deliveries/{delivery_id}` |
| Resend a single delivery immediately | `POST /v1/webhook-deliveries/{delivery_id}/retry` |
| Re-queue all failed deliveries since a timestamp | `POST /v1/webhook-endpoints/{endpoint_id}/recover` |

Manual resends reuse the same `webhook-id` and work even while an endpoint is disabled, so you can verify a fix before re-enabling it.

## Event catalog

Call `GET /v1/webhook-event-types` for the complete catalog with sample `data` payloads for every type.

When available, `data.customer` identifies the customer (on `email.*`, `whatsapp.message.*`, and `order.*` events, `customer` can be `null` if no customer record is linked):

```json theme={null}
{ "id": "cus_ckabc123", "email": "ana@example.com", "phone": "+5511988887777", "external_id": "u_8842" }
```

`external_id` matches the `customer.external_id` sent to `POST /v1/customers` or the [custom events API](https://docs.bevits.com/en/api-reference/custom-events.md). Message events include `source`: `{ "type": "flow" | "campaign", "id", "name" }`, or `null` when sent from the inbox.

### Email

Applies to both flows and campaigns.

| Type | Trigger | Extra fields in `data` (besides `customer`, `email`, `source`) |
| - | - | - |
| `email.delivered` | Recipient mail server accepted the message | — |
| `email.opened` | Email was opened. Can fire more than once (some mail clients prefetch images) | `user_agent` |
| `email.clicked` | Tracked link was clicked (fires once per click) | `link.url`, `user_agent` |
| `email.bounced` | Email bounced. Hard bounces automatically unsubscribe the address | `bounce.type` (`hard` or `soft`), `bounce.subtype`, `bounce.diagnostic` |
| `email.complained` | Recipient marked the email as spam | `complaint.feedback_type` |

### Customers

| Type | Trigger | Fields in `data` |
| - | - | - |
| `contact.unsubscribed` | Customer opted out of one or more channels | `customer`, `channels` (`email`, `whatsapp`, `sms`), `reason`, `source` |
| `customer.created` | A new customer was created via the API (`POST /v1/customers`, a custom event or `POST /v1/purchases`) or a store integration in real time | `customer` (full customer object), `origin` (`api`, `nuvemshop`, `shopify`, `woocommerce`…) |

`contact.unsubscribed` `reason` values: `unsubscribe_link`, `spam_complaint`, `hard_bounce`, `whatsapp_opt_out`, `manual`, or `api`.

Initial store imports and events sent with `backfill: true` do not emit `customer.created`. For API-created customers, `data.customer` matches the object returned by `POST /v1/customers` and `GET /v1/customers/{customer_id}`, and is never duplicated on retries or when the customer already existed (`200`).

```json theme={null}
{
  "customer": {
    "object": "customer",
    "id": "cus_ckabc123",
    "name": "Ana Souza",
    "email": "ana@example.com",
    "phone": "+5511988887777",
    "external_id": "u_8842",
    "source": "API",
    "is_subscribed": true,
    "is_subscribed_to_email": true,
    "created_at": "2026-11-24T14:03:00.000Z",
    "updated_at": "2026-11-24T14:03:00.000Z",
    "html_url": "https://app.bevits.com/customers/ckabc123",
    "tags": [],
    "attributes": { "plan": "vip" }
  },
  "origin": "api"
}
```

### Official WhatsApp

| Type | Trigger | Fields in `data` |
| - | - | - |
| `whatsapp.message.delivered` | Message reached the customer's device | `customer`, `message.id`, `message.to`, `source` |
| `whatsapp.message.read` | Customer read the message (when read receipts are enabled) | `customer`, `message.id`, `message.to`, `source` |
| `whatsapp.message.replied` | Customer sent a message to the store's number | `customer` (or `null`), `message.id`, `message.from`, `message.type`, `message.text`, `in_reply_to` |

`message.id` is Meta's message ID (`wamid…`). `in_reply_to` is populated when the customer replied by quoting an earlier message.

### Orders

Emitted in real time for native Nuvemshop, Shopify, and WooCommerce integrations.

| Type | Trigger |
| - | - |
| `order.created` | Store created an order |
| `order.paid` | Payment was confirmed |
| `order.fulfilled` | Order was shipped or invoiced |
| `order.cancelled` | Order was cancelled |

```json theme={null}
{
  "customer": { "id": "cus_ckabc123", "email": "ana@example.com", "phone": "+5511988887777", "external_id": null },
  "order": {
    "id": "pur_ckpqr987",
    "platform": "nuvemshop",
    "platform_order_id": "1650012345",
    "number": "10293",
    "status": "paid",
    "total": 189.9,
    "currency": "BRL",
    "created_at": "2026-11-23T14:00:00.000Z"
  }
}
```

* `order.id` is `null` until the order becomes a stored purchase in Bevits (for example, an unpaid newly created order).
* `order.total` is a decimal in major currency units (for example, `189.9`), not cents.

### Purchases created through the API

For organizations without a store integration, whose sales are recorded through the API: with `POST /v1/purchases` or by their [order and payment events](https://docs.bevits.com/en/api-reference/recommended-events.md#sales-reported-through-the-api).

| Type | Trigger | Fields in `data` |
| - | - | - |
| `purchase.created` | A purchase was created through the API (`POST /v1/purchases`) or by an event | `purchase` (full purchase object), `origin` (`api` for `POST /v1/purchases`, `event` for an event) |

`data.purchase` matches the object returned by `POST /v1/purchases` and `GET /v1/purchases/{purchase_id}`, and is never duplicated on retries or when a purchase with the same `external_id` already existed (`200`): each purchase sends one `purchase.created`, whether the event or `POST /v1/purchases` created it. Events sent with `backfill: true` create purchases without this webhook. Orders from connected stores still arrive as `order.*` events. The customer comes in `purchase.customer_id`; look it up with `GET /v1/customers/{customer_id}`.

```json theme={null}
{
  "purchase": {
    "object": "purchase",
    "id": "pur_ckabc123",
    "customer_id": "cus_ckabc123",
    "external_id": "ord_77120",
    "order_id_on_integration_platform": "ord_77120",
    "order_number": "10293",
    "platform": "api",
    "status": "open",
    "payment_status": "paid",
    "currency": "BRL",
    "purchase_value_in_cents": 17990,
    "subtotal_amount_in_cents": 17990,
    "total_amount_in_cents": 18990,
    "shipping_cost_customer_in_cents": 1000,
    "coupons": [],
    "created_at": "2026-11-24T14:00:00.000Z",
    "updated_at": "2026-11-24T14:00:01.000Z"
  },
  "origin": "api"
}
```

## Versioning

`api_version` is pinned when the endpoint is created. New fields may be added to `data` without notice — ignore unknown fields in your parser. Removing, renaming, or changing a field's type only happens in a new version.

## Error reference

| `code` | HTTP | Cause |
| - | - | - |
| `invalid_webhook_url` | `422` | URL is not `https`, includes embedded credentials, or has a `#fragment`. Includes `suggestion` when switching `http` to `https` fixes it. |
| `private_webhook_url` | `422` | Host resolves to `localhost`, a private IP, or an internal network address. |
| `unknown_event_type` | `422` | Event type is not in the catalog. Includes `suggestion` for close matches (e.g. `customer.unsubscribed` → `contact.unsubscribed`). |
| `invalid_event_selection` | `422` | `"*"` combined with specific event types in the same array. |
| `duplicate_endpoint_url` | `409` | URL is already registered for this organization. |
| `endpoint_limit_reached` | `409` | Organization already has 20 endpoints. |
| `endpoint_disabled` | `409` | Attempted to test or recover deliveries on a disabled endpoint. |
| `recover_window_exceeded` | `422` | `since` is older than the 30-day delivery log window. |
| `endpoint_not_found`, `delivery_not_found` | `404` | ID does not exist in this organization. |

Possible attempt `error_code` values: `timeout`, `connection_failed`, `dns_failed`, `private_address`, `tls_error`, `redirect_not_followed`, `non_2xx_response`, `endpoint_disabled`, `endpoint_deleted`, and `internal_error`.

## Next steps

* [Custom events](https://docs.bevits.com/en/api-reference/custom-events.md): send events from your backend to Bevits.
* [Authentication](https://docs.bevits.com/en/api-reference/authentication.md): create an API key with the `write` scope.


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