API Reference

Complete method reference for the webhooks.cc TypeScript SDK.

Constructor

import { WebhooksCC } from "@webhooks-cc/sdk";

const client = new WebhooksCC({
  apiKey: string,        // Required. Your API key.
  baseUrl?: string,      // Optional. Override API base URL.
  webhookUrl?: string,   // Optional. Override webhook receiver URL.
  timeout?: number,      // Optional. Request timeout in ms (default: 30000).
  hooks?: ClientHooks,   // Optional. Lifecycle hooks for observability.
});

Endpoints

client.endpoints.create

Create a new webhook endpoint. The slug is auto-generated.

create(options?: CreateEndpointOptions): Promise<Endpoint>
ParamTypeDescription
namestring?Display name

Returns: Endpoint object with id, url, slug, and name

client.endpoints.list

List all endpoints for your account.

list(): Promise<Endpoint[]>

Returns: Array of Endpoint objects

client.endpoints.get

Get a single endpoint by slug.

get(slug: string): Promise<Endpoint>

Returns: Endpoint object

client.endpoints.update

Update an endpoint's name or mock response configuration.

update(slug: string, options: UpdateEndpointOptions): Promise<Endpoint>
ParamTypeDescription
slugstringEndpoint slug
namestring?New display name
mockResponseobject | null?Mock response config { status, body, headers }, or null to clear

Returns: Updated Endpoint object

client.endpoints.delete

Delete an endpoint and all its captured requests.

delete(slug: string): Promise<void>

Returns: void

client.endpoints.send

Send a test webhook to an endpoint. Sends directly to the receiver, does not go through the API.

send(slug: string, options?: SendOptions): Promise<Response>
ParamTypeDescription
slugstringEndpoint slug
methodstring?HTTP method (default: "POST")
headersRecord?HTTP headers to include
bodyunknown?Request body (JSON-serialized)

Returns: Raw fetch Response from the receiver

client.endpoints.sendTemplate

Send a provider template webhook (Stripe, GitHub, Shopify, Twilio) with generated signature headers.

sendTemplate(slug: string, options: SendTemplateOptions): Promise<Response>
ParamTypeDescription
slugstringEndpoint slug
provider"stripe" | "github" | "shopify" | "twilio"Provider template to generate
templatestring?Provider-specific template preset (for example: pull_request.opened)
secretstringShared secret used for signature generation
eventstring?Provider event/topic override
methodstring?HTTP method override (defaults to POST)
timestampnumber?Unix timestamp override for Stripe signature generation
headersRecord?Additional headers
bodyunknown?Template body override. For Twilio string overrides, provide URL-encoded key/value pairs.

Returns: Raw fetch Response from the receiver

Requests

client.requests.list

List captured requests for an endpoint.

list(endpointSlug: string, options?: ListRequestsOptions): Promise<Request[]>
ParamTypeDescription
endpointSlugstringEndpoint slug
limitnumber?Max results (default: 50)
sincenumber?Only return requests after this timestamp (ms)

Returns: Array of Request objects

client.requests.get

Get a single captured request by ID.

get(requestId: string): Promise<Request>

Returns: Request object with method, headers, body, queryParams, etc.

client.requests.waitFor

Poll for incoming requests until one matches or timeout expires. Accepts human-readable duration strings.

waitFor(endpointSlug: string, options?: WaitForOptions): Promise<Request>
ParamTypeDescription
endpointSlugstringEndpoint slug to monitor
timeoutnumber | string?Max wait time — ms or "30s", "5m", "1h" (default: 30000)
pollIntervalnumber | string?Interval between polls (default: 500)
matchfunction?Filter function: (request) => boolean

Returns: First matching Request, or first request if no match filter

client.requests.subscribe

Stream incoming requests via SSE as an async iterator. No automatic reconnection.

subscribe(slug: string, options?: SubscribeOptions): AsyncIterable<Request>
ParamTypeDescription
slugstringEndpoint slug
signalAbortSignal?Signal to cancel the subscription
timeoutnumber | string?Max stream duration

Returns: AsyncIterable of Request objects

client.requests.replay

Replay a captured request to a target URL. Sends the original method, headers, and body. Hop-by-hop headers are stripped.

replay(requestId: string, targetUrl: string): Promise<Response>
ParamTypeDescription
requestIdstringID of the captured request
targetUrlstringURL to send the replayed request to

Returns: Raw fetch Response from the target

Introspection

client.describe

Returns a static description of all SDK operations and their parameters. No API call is made. Useful for AI agents and tool discovery.

describe(): SDKDescription

Returns: Object with version, endpoints (7 operations), and requests (5 operations)

Matchers

Composable functions that return (request) => boolean. Use with waitFor or filter logic.

import {
  matchMethod,
  matchHeader,
  matchBodyPath,
  matchJsonField,
  matchAll,
  matchAny,
} from "@webhooks-cc/sdk";

matchMethod("POST")                         // match by HTTP method
matchHeader("x-github-event")               // match header presence
matchHeader("x-github-event", "push")       // match header value
matchBodyPath("data.object.id", "obj_123")  // match nested JSON path
matchJsonField("type", "checkout")           // match top-level JSON field
matchAll(matchMethod("POST"), matchHeader("stripe-signature"))
matchAny(matchMethod("GET"), matchMethod("POST"))

Provider Detection

Each helper checks for a provider-specific header (case-insensitive).

import {
  isStripeWebhook,    // stripe-signature
  isGitHubWebhook,    // x-github-event
  isShopifyWebhook,   // x-shopify-hmac-sha256
  isSlackWebhook,     // x-slack-signature
  isTwilioWebhook,    // x-twilio-signature
  isPaddleWebhook,    // paddle-signature
  isLinearWebhook,    // linear-signature
} from "@webhooks-cc/sdk";

Duration Strings

timeout and pollInterval accept human-readable strings alongside milliseconds.

"500ms"  →    500
"30s"    →  30000
"5m"     → 300000
"1h"     → 3600000
500      →    500    // numbers passed through

Types

interface Endpoint {
  id: string;
  slug: string;
  name?: string;
  url?: string;
  createdAt: number;
}

interface Request {
  id: string;
  endpointId: string;
  method: string;
  path: string;
  headers: Record<string, string>;
  body?: string;
  queryParams: Record<string, string>;
  contentType?: string;
  ip: string;
  size: number;
  receivedAt: number;
}

interface UpdateEndpointOptions {
  name?: string;
  mockResponse?: {
    status: number;
    body: string;
    headers: Record<string, string>;
  } | null;
}

interface SendOptions {
  method?: string;
  headers?: Record<string, string>;
  body?: unknown;
}

interface WaitForOptions {
  timeout?: number | string;
  pollInterval?: number | string;
  match?: (request: Request) => boolean;
}

interface CreateEndpointOptions {
  name?: string;
}

interface ListRequestsOptions {
  limit?: number;
  since?: number;
}

interface SubscribeOptions {
  signal?: AbortSignal;
  timeout?: number | string;
}

type TemplateProvider = "stripe" | "github" | "shopify" | "twilio";

interface SendTemplateOptions {
  provider: TemplateProvider;
  template?: string;
  secret: string;
  event?: string;
  method?: string;
  headers?: Record<string, string>;
  body?: unknown;
  timestamp?: number;
}

Error Classes

Errors include actionable recovery hints when the server message is generic.

import {
  WebhooksCCError,   // Base error (has statusCode)
  UnauthorizedError, // 401 — includes link to get API key
  NotFoundError,     // 404 — suggests using endpoints.list()
  RateLimitError,    // 429 — includes retryAfter seconds
  TimeoutError,      // Request timeout
} from "@webhooks-cc/sdk";