Webhook delivery

Verify Pigeon webhook notifications and use them to trigger cursor pulls.

On this page

Subscribe to changes

Bootstrap a snapshot and cursor for the connection. Register your public HTTPS endpoint with POST /v1/webhooks and subscribe to feed.changed. Use the same active connection’s OAuth access token or personal access token.

bash
curl --fail-with-body \
  --header "Authorization: Bearer $PIGEON_ACCESS_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{"url":"https://connector.example/webhooks/pigeon","events":["feed.changed"]}' \
  https://api.sendtopigeon.com/v1/webhooks

Registration replaces the existing endpoint and signing secret for that connection. Save the returned secret in private storage. If Pigeon returns HTTP 422 webhook_url_invalid or webhook_url_private, check that the URL is valid, uses HTTPS and points to a publicly reachable host. On webhook_events_invalid, check the event names against the webhook request schema.

Verify and enqueue

Use the original request bytes, before parsing JSON. The plain HTTP receiver verifies the Standard Webhooks signature and rejects timestamps more than five minutes ahead of or behind its clock.

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

const WEBHOOK_TIMESTAMP_TOLERANCE_SECONDS = 5 * 60;

export function verifyWebhook(rawBody, headers, secret) {
  const id = headers.get("webhook-id");
  const timestamp = headers.get("webhook-timestamp");
  if (
    !id ||
    !timestamp ||
    !/^\d+$/.test(timestamp) ||
    Math.abs(Date.now() / 1000 - Number(timestamp)) > WEBHOOK_TIMESTAMP_TOLERANCE_SECONDS
  ) {
    throw new Error("Invalid event timestamp");
  }

  const key = Buffer.from(secret.replace(/^whsec_/, ""), "base64");
  const signature = createHmac("sha256", key)
    .update(`${id}.${timestamp}.`)
    .update(rawBody)
    .digest("base64");
  const expected = Buffer.from(`v1,${signature}`);
  const valid = (headers.get("webhook-signature") ?? "").split(" ").some((value) => {
    const actual = Buffer.from(value);
    return actual.length === expected.length && timingSafeEqual(actual, expected);
  });
  if (!valid) throw new Error("Invalid event signature");
  return id;
}

Pass the request body as a Node.js Buffer and its headers as a Headers object. The verified body is a CloudEvents envelope. For feed.changed, save the verified delivery ID and enqueue a pull durably before returning HTTP 204. A duplicate ID can be acknowledged without starting another job.

Pull records from the feed

Read the change feed from the last committed cursor. Webhooks carry notifications without record bodies, and deliveries can be retried or coalesced. Poll periodically as a fallback.

If deliveries fail, check HTTPS reachability, signature verification and the receiver's responses. The feed remains available while the grant is active. When a connection is paused, Pigeon keeps the webhook registration and stops new deliveries until the connection is active again.