Developer docs
Guide: receive and verify Beplan webhooks
Beplan sends a signed POST to your server when something happens: a post is published or fails, waits for approval, media is reviewed, a connection changes. Here is how to subscribe, verify each delivery, and handle retries.
Two kinds of webhook
| App webhook | Organization webhook | |
|---|---|---|
| Who sets it | The organization that owns an OAuth app, on the app's page | An admin, for their own organization |
| Receives events from | Every organization the app is connected to, where its connections can see what the event is about | That organization, all its workspaces |
| Extra events | Connection events about the app | |
| Envelope extras | via (always), connectionIds |
via only when an integration caused the event |
| Signed with | The app's own secret | The organization's secret |
Both deliver the same envelope with the same signature scheme. This guide is mostly about app webhooks; a personal token has no webhook of its own, but an admin can set up the organization's webhook in Beplan's organization settings, under Developer.
Subscribe
On the app's page (organization settings → Developer → your app), in Webhook:
- Address: a public
httpsURL. Beplan checks it doesn't lead to a private network when you save, and again on every delivery. - Events: the event types your app wants.
ping(the test) is always sent. - Save. Saving an address for the first time makes the signing secret (
whsec_…), shown once: put it in your server now. Make a new signing secret (it asks for your password) replaces it; the old one stops at once, even for deliveries already queued. - Send a test queues a
ping. Deliveries list the last ones (up to 100), newest first, with their status and the last HTTP status your server answered.
Which events reach an app
An event about an organization reaches your app when, at the time it is sent:
- one of your app's connections is active in that organization and its policy lets your app in;
- the event's workspace is in that connection's selection;
- that connection holds the event's read scope: posts:read for
post.*events, media:read formedia.*andraw_footage.uploaded.
Your app gets one delivery per event, even when several members connected it; connectionIds lists the app's connections that reach it. Connection events (connection.created, connection.updated, connection.revoked, connection.approved, connection.rejected) always go to the app concerned, whatever its scopes. The event catalog has every type with an example.
The delivery
POST <your address>
Content-Type: application/json
User-Agent: Beplan-Webhooks/1.0
webhook-id: b7c1e2d3-4f5a-4b6c-8d7e-9f0a1b2c3d4e
webhook-timestamp: 1763631000
webhook-signature: v1,<base64 HMAC-SHA256> The body is the envelope (schema version 1):
| Field | |
|---|---|
id |
The event's id, also in webhook-id. Each destination gets its own copy with its own id |
type |
The event type, like post.published |
schemaVersion |
1 |
occurredAt |
ISO 8601, UTC |
organization |
{ id, name } |
socialSet |
The workspace { id, name }, or null for an organization-level event |
actor |
The person who made the change { id, name }, or null |
url |
A page in Beplan about the resource (needs a signed-in person) |
data |
The event's payload; see the catalog |
via |
{ kind, clientId, clientName } when an integration made the change (kind: personal_token, app or mcp); on an app delivery it is always present and null for a change made in Beplan's app |
connectionIds |
App deliveries only: your connections that reach this event |
Ignore fields you don't know: the envelope and the payloads may gain fields.
Verify every delivery
Beplan signs with Standard Webhooks: webhook-signature is v1, followed by the base64 HMAC-SHA256 of <webhook-id>.<webhook-timestamp>.<raw body>, keyed with your secret's bytes (the part after whsec_, base64-decoded).
- Sign the raw body as received. Parsing and re-serializing JSON changes the bytes.
- Compare in constant time.
- Reject old timestamps to stop replays. Five minutes is a common tolerance; that number is our suggestion, not something Beplan enforces.
import { createHmac, timingSafeEqual } from "node:crypto";
/** Verifies a Beplan webhook delivery (Standard Webhooks). Throws when it is not authentic. */
export function verifyBeplanWebhook(
secret: string, // "whsec_…", from the app's Webhook settings
headers: { id: string | null; timestamp: string | null; signature: string | null },
rawBody: string, // the request body exactly as received, before any JSON parsing
toleranceSeconds = 5 * 60,
now = Math.floor(Date.now() / 1000),
): void {
const { id, timestamp, signature } = headers;
if (!id || !timestamp || !signature) throw new Error("missing webhook headers");
if (Math.abs(now - Number(timestamp)) > toleranceSeconds) throw new Error("timestamp too old or too new");
const key = Buffer.from(secret.replace(/^whsec_/, ""), "base64");
const expected = createHmac("sha256", key).update(`${id}.${timestamp}.${rawBody}`).digest();
// The header may hold several space-separated signatures ("v1,<base64> v1,<base64>").
const ok = signature.split(" ").some((entry) => {
const [version, value] = entry.split(",", 2);
if (version !== "v1" || !value) return false;
const given = Buffer.from(value, "base64");
return given.length === expected.length && timingSafeEqual(given, expected);
});
if (!ok) throw new Error("bad signature");
} import base64
import hashlib
import hmac
import time
def verify_beplan_webhook(secret, headers, raw_body, tolerance_seconds=300, now=None):
"""Verifies a Beplan webhook delivery (Standard Webhooks). Raises ValueError when it is not authentic.
secret: "whsec_…", from the app's Webhook settings.
headers: the request's headers (webhook-id, webhook-timestamp, webhook-signature).
raw_body: the request body exactly as received (bytes), before any JSON parsing.
"""
msg_id = headers.get("webhook-id")
timestamp = headers.get("webhook-timestamp")
signature = headers.get("webhook-signature")
if not msg_id or not timestamp or not signature:
raise ValueError("missing webhook headers")
now = int(time.time()) if now is None else now
if abs(now - int(timestamp)) > tolerance_seconds:
raise ValueError("timestamp too old or too new")
key = base64.b64decode(secret.removeprefix("whsec_"))
signed = msg_id.encode() + b"." + timestamp.encode() + b"." + raw_body
expected = base64.b64encode(hmac.new(key, signed, hashlib.sha256).digest()).decode()
# The header may hold several space-separated signatures ("v1,<base64> v1,<base64>").
for entry in signature.split(" "):
version, _, value = entry.partition(",")
if version == "v1" and hmac.compare_digest(value, expected):
return
raise ValueError("bad signature") To test your code: with the secret whsec_BwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc=, the id event-123, the timestamp 1700000000 and the body {"type":"webhook.test"}, the signature is v1,3xhgt798R4BQljTx3nZsGK/8n8dBdAKg36svgaMFOQo= (pass now = 1700000000, or the timestamp check refuses it). Beplan's own tests use the same values.
Answer fast, retry safely
- Answer with any
2xxwithin 10 seconds (5 to connect). Do the work after answering, from a queue. - Redirects are not followed: a
3xxcounts as a failure. 408,429, any5xx, a timeout or a refused connection are retried. Other4xxanswers fail the delivery for good.- Up to 10 attempts, the delay growing from about a minute to an hour, with some jitter. Retries send the same body and
webhook-id, with a new timestamp and signature. - Delivery is at least once: the same event can arrive twice. Deduplicate by
webhook-id. - Events can arrive out of order. Use
occurredAt, and read the resource from the API when the order matters.
Automatic disable
If an app's last 20 finished deliveries (tests aside) all failed, and the oldest of them is at least 24 hours old, Beplan turns the app's webhook off and emails the organization's app managers. The app page shows when and why. Fix your server, then save the webhook settings to turn it back on.
Connection events
They tell your app that what it can reach changed, before a call fails:
connection.created: someone connected your app to an organization.statusispendingwhile an admin has to approve it.connection.updated: the organizations, workspaces, status or scopes changed;status: "removed"means the organization was taken out.connection.approved/connection.rejected: an admin decided a pending connection.connection.revoked: your app lost access to this organization.reasonsays how (user,admin,app,replay,leaked,unused,staff, orrevoked_by_adminfor one organization), andwholeConnectionwhether every organization of the connection is gone. It is sent even though the connection no longer works.
Each carries data.connectionId. Match it with the connection.id your app reads from GET /v1/me for that person.