Create, update, test, rotate, and delete webhook subscriptions from the SDK.
The client.webhooks namespace wraps the webhook management API. Use it to register endpoints, adjust filters, rotate signing secrets, and verify deliveries in your handler. For the full event catalogue and payload shapes, see the Webhooks tab.
Each webhook subscribes to a single event and delivers to one HTTPS endpoint. Pass optional filters to narrow the deliveries and a secret to enable signature verification.
test delivers a synthetic payload to the configured URL so you can confirm your handler is reachable and verifies signatures correctly. Use it any time you change the URL or the signing secret.
listEvents returns every event type you can subscribe to, along with the filter keys each one accepts. This is the source of truth for what to pass as event and filters.
const { data } = await client.webhooks.listEvents();for (const info of data.events) { console.log(info.event, info.applicable_filters);}
Every delivery includes two headers your handler should inspect:
Header
Value
X-Webhook-ID
UUID of the webhook subscription that fired.
X-Webhook-Signature
sha256=<hex>, an HMAC-SHA256 of the raw request body using the webhook’s secret. Only present when a secret is configured.
Recompute the HMAC over the raw bytes of the request body and compare with a constant-time check. Parsing the body to JSON before hashing will break the comparison.
Always hash the raw body bytes, not the parsed JSON. Middleware that parses JSON before your handler runs (for example, Express’s default body-parser) will make verification fail. Mount express.raw on the webhook route as shown above.
Every delivery arrives as a JSON WebhookDeliveryEnvelope wrapping the event-specific payload:
import type { WebhookEvent } from "@structbuild/sdk";
WebhookEvent is a discriminated union over every supported event, keyed on the event field. Each variant narrows data to the matching payload shape, so a single switch gives you full type safety across every event type you subscribe to.
import type { WebhookEvent } from "@structbuild/sdk";function handle(delivery: WebhookEvent) { switch (delivery.event) { case "trader_whale_trade": console.log(delivery.data.trader, delivery.data.amount_usd); break; case "probability_spike": console.log( delivery.data.condition_id, delivery.data.spike_pct, ); break; case "market_created": console.log(delivery.data.condition_id, delivery.data.market_slug); break; case "trader_global_pnl": console.log(delivery.data.trader, delivery.data.realized_pnl_usd); break; case "close_to_bond": console.log(delivery.data.condition_id, delivery.data.price); break; }}
Test deliveries carry the same payload shape but append _test to the event name. Drop the suffix when you want to route a test through the same handlers as the real event, or reject them outright when running in production.
Return any 2xx status within 10 seconds to acknowledge a delivery. Non-2xx responses and timeouts trigger retries with exponential backoff. See Webhook Response Format for the full retry policy and payload envelope.