Webhooks

Owner-configured webhook endpoints - event catalog, payload shape, signature verification, retries, delivery logs, and secret rotation.

Updated

Open in ClaudeOpen in ChatGPT
On this page

Postkub can push events to your own HTTPS endpoint when things happen in your workspace: publications move, comments arrive, replies resolve. You register the endpoint as the workspace owner; deliveries are signed so your receiver can trust them.

Warning

Webhook endpoints are owner-only configuration. They are created in the dashboard or through the human-session owner API, and external API keys can never manage them - a key that sends an Authorization header to these routes is rejected with 403 KEY_LANE_FORBIDDEN. Receiving events requires no Postkub key at all; your receiver verifies signatures with the endpoint secret instead.

Registering an endpoint

Create an endpoint in the dashboard, or with an owner session against POST /api/v1/owner/webhook-endpoints (an Idempotency-Key header is required, as on every mutation):

{
  "label": "ops receiver",
  "url": "https://ops.example.com/hooks/postkub",
  "eventTypes": ["post.published", "post.failed"]
}

The response returns requestId, the endpoint object (id, label, url, eventTypes, status, revision), and the signing secret - shown exactly once, never retrievable again. Store it immediately.

Constraints: at most 20 endpoints per workspace; label up to 100 characters; url up to 2048 characters; the URL must be HTTPS in production, must not embed credentials, and must point at a public destination (private and loopback addresses are rejected). Updates use PATCH /api/v1/owner/webhook-endpoints/{id} with expectedRevision; revoking uses DELETE and stops all future deliveries.

Event catalog

You subscribe each endpoint to the event types it wants. The catalog:

Event typeFired when
post.scheduledA schedule or queue-slot publication is accepted
post.publishedA publication target finishes as published on the platform
post.failedA publication target ends in a failure state
post.cancelledA publication target is cancelled
post.attention_requiredA target needs a human look - blocked, review, or unknown outcome
comment.receivedComment sync stores a new platform comment
reply.sentA comment reply is confirmed sent
reply.failedA comment reply ends failed
reply.attention_requiredA reply ends with an unknown outcome
media.readyAn uploaded media asset finished processing
media.failedAn uploaded media asset failed processing
account.disconnectedA social account lost its connection

Warning

Planned events: media.ready, media.failed, and account.disconnected are in the subscription catalog today, but the current event pipeline does not emit them yet (ยังไม่เปิดให้ใช้). Subscribing is accepted and harmless; do not build critical flows on them until they start arriving.

Post events name one publication target and never imply that every target of the post succeeded. Check GET /api/v1/posts/{id} for the full picture.

Payload shape

Every delivery posts a JSON envelope with Content-Type: application/json and the user agent Postkub-Webhooks/1.0:

{
  "id": "8c1d4f7a-2b3e-4c6d-9a5f-0e7b8d2c1a4f",
  "type": "post.published",
  "version": 1,
  "createdAt": "2026-12-01T09:00:05.000Z",
  "data": {
    "publicationId": "pub_5a7c1e",
    "postId": "post_9f2e1c",
    "socialAccountId": "acc_31d8b0",
    "revision": 2,
    "postRevision": 3,
    "status": "published"
  }
}
  • id - the stable event ID, identical across every delivery and replay of this event. Deduplicate on it.
  • type - one of the catalog entries above.
  • version - integer payload schema version; 1 today. Filter on it if you want to be strict about future changes.
  • data - the event payload. Publication events carry publicationId, postId, socialAccountId, revision, postRevision, status, and may add attemptId and code for failures. comment.received carries commentId, threadId, socialAccountId, provider, platform, providerCommentId, contextProviderPostId, postTargetId, and providerCreatedAt. Reply events carry replyId, commentId, socialAccountId, revision, attemptId, and code.

Verifying signatures

Every delivery carries three headers:

HeaderValue
Postkub-Event-IdThe event ID from the envelope
Postkub-TimestampUnix seconds, refreshed on every attempt
Postkub-Signaturev1= followed by lowercase hex HMAC-SHA-256

The signature covers the UTF-8 string timestamp + "." + eventId + "." + rawBody, keyed with your endpoint secret. Verify it before parsing the body, in constant time, and reject timestamps older than five minutes. Read the raw body bytes exactly as received - re-serializing JSON changes the bytes and breaks the signature.

import { createHmac, timingSafeEqual } from "node:crypto";

export function verifyPostkubWebhook(rawBody: string, headers: {
  "postkub-event-id": string;
  "postkub-timestamp": string;
  "postkub-signature": string;
}, secret: string, nowSeconds = Math.floor(Date.now() / 1000)): boolean {
  const timestamp = Number(headers["postkub-timestamp"]);
  if (!Number.isFinite(timestamp) || Math.abs(nowSeconds - timestamp) > 300) return false;
  const expected = "v1=" + createHmac("sha256", secret)
    .update(`${timestamp}.${headers["postkub-event-id"]}.${rawBody}`, "utf8")
    .digest("hex");
  const provided = headers["postkub-signature"].trim();
  return provided.length === expected.length &&
    timingSafeEqual(Buffer.from(provided, "utf8"), Buffer.from(expected, "utf8"));
}
import hashlib
import hmac
import time


def verify_postkub_webhook(raw_body: str, event_id: str, timestamp: str,
                           signature: str, secret: str) -> bool:
    now = int(time.time())
    ts = int(timestamp)
    if abs(now - ts) > 300:
        return False
    expected = hmac.new(
        secret.encode("utf-8"),
        f"{ts}.{event_id}.{raw_body}".encode("utf-8"),
        hashlib.sha256,
    ).hexdigest()
    return hmac.compare_digest(signature.strip(), "v1=" + expected)

Delivery and retry behavior

  • Delivery is at-least-once and unordered. A crash between sending and recording can repeat an event, so receivers deduplicate on Postkub-Event-Id.
  • Any 2xx status counts as delivered. Respond quickly; each attempt must finish within a 10-second deadline.
  • Network failures, timeouts, 408, 429, and 5xx responses are retried. If your receiver sends Retry-After, Postkub honors it before its own schedule.
  • Redirect responses (3xx) are never followed, and any other 4xx is terminal - a 404 receiver URL fails immediately rather than burning retries.
  • Retries use jittered exponential backoff starting near 30 seconds and capped at one hour, inside a budget of at most 10 attempts or 24 hours from the first attempt, whichever comes first. After that the delivery is marked dead and stops automatically.
  • Response bodies are read up to 64 KiB and truncated beyond that; payloads larger than 512 KiB are never sent.

Delivery log and replay

The owner API exposes per-endpoint delivery diagnostics at GET /api/v1/owner/webhook-endpoints/{id}/deliveries (paginated, with an optional status filter of pending, succeeded, or dead). Each delivery row reports attemptCount, replayCount, lastHttpStatusCode, lastErrorCode, lastErrorMessage, a short responseSnippet, nextAttemptAt, and the relevant timestamps.

A dead delivery can be replayed manually after you fix your receiver: POST /api/v1/owner/webhook-endpoints/{id}/deliveries/{deliveryId}/replay with an Idempotency-Key returns 202. A replay keeps the original event ID and signs the same payload bytes, but starts a fresh attempt budget and increments replayCount.

Secret rotation

POST /api/v1/owner/webhook-endpoints/{id}/rotate (with expectedRevision and an Idempotency-Key) issues a new signing secret, shown once in the response. The previous secret keeps verifying deliveries for a 24-hour overlap, so you can update your receiver without losing events. During the overlap, try the new secret first and fall back to the old one; after 24 hours, accept only the new secret. Old secrets are never shown again.