export type WebhookInExecute = {category: string, data: Record}; export type BodyWebhooksExecuteApiV5WebhooksExecutePost = {webhook: WebhookInExecute}; export type CreateApiApiV5WebhooksExecuteArgs = {body: BodyWebhooksExecuteApiV5WebhooksExecutePost}; export type CreateApiApiV5WebhooksExecuteOptions = {baseUrl?: string | undefined, RWAPIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; /** * Execute webhook * * POST /api/v5/webhooks/execute */ export const createApiApiV5WebhooksExecute = async (args: CreateApiApiV5WebhooksExecuteArgs, options?: CreateApiApiV5WebhooksExecuteOptions) => { const {baseUrl = "https://api.pavlok.com", fetch: fetchFn = fetch, RWAPIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (RWAPIKeyHeader !== undefined) headers.set("Authorization", RWAPIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/api/v5/webhooks/execute${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };