export type KlaviyoSubscriptionWebhookRequestKlaviyoSubscriptionWebhookUpdateType = 'EMAIL' | 'SMS'; export type KlaviyoSubscriptionWebhookRequest = {external_id: number, type: KlaviyoSubscriptionWebhookRequestKlaviyoSubscriptionWebhookUpdateType, value: boolean}; export type CreateApiKlaviyoFlowsSubscriptionChangedArgs = {'X-API-Key': string, 'X-Klaviyo-Flow-ID': string, body: KlaviyoSubscriptionWebhookRequest}; export type CreateApiKlaviyoFlowsSubscriptionChangedOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * POST /klaviyo/flows/subscription-changed */ export const createApiKlaviyoFlowsSubscriptionChanged = async (args: CreateApiKlaviyoFlowsSubscriptionChangedArgs, options: CreateApiKlaviyoFlowsSubscriptionChangedOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['X-API-Key'] != null) headers.set("X-API-Key", String(args['X-API-Key'])) if (args['X-Klaviyo-Flow-ID'] != null) headers.set("X-Klaviyo-Flow-ID", String(args['X-Klaviyo-Flow-ID'])) const url = `${baseUrl.replace(/\/+$/, '')}/klaviyo/flows/subscription-changed${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 };