export type CreateApiV1ExternalEventsWebhookArgs = {event_id_location: 'headers' | 'querystring' | 'payload', event_id_path: string, account_id: string, project_id: string, body: {[key: string]: unknown}}; export type CreateApiV1ExternalEventsWebhookOptions = {baseUrl?: string | undefined, polyApiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * External events webhook (provider → PolyAI) * * POST /v1/external-events/webhook */ export const createApiV1ExternalEventsWebhook = async (args: CreateApiV1ExternalEventsWebhookArgs, options?: CreateApiV1ExternalEventsWebhookOptions) => { const {baseUrl = "https://api.us.poly.ai", fetch: fetchFn = fetch, polyApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args.event_id_location != null) query.append("event_id_location", String(args.event_id_location)) if (args.event_id_path != null) query.append("event_id_path", String(args.event_id_path)) if (args.account_id != null) query.append("account_id", String(args.account_id)) if (args.project_id != null) query.append("project_id", String(args.project_id)) if (polyApiKey !== undefined) headers.set("X-API-KEY", polyApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/external-events/webhook${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 };