export type V4AutomationStatusPatch = {status: 'active' | 'inactive' | 'paused'}; export type PatchApiAutomationsAutomationIdStatusArgs = {automation_id: string, body: V4AutomationStatusPatch}; export type PatchApiAutomationsAutomationIdStatusOptions = {baseUrl?: string | undefined, secretAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Update automation status * * PATCH /automations/{automation_id}/status */ export const patchApiAutomationsAutomationIdStatus = async (args: PatchApiAutomationsAutomationIdStatusArgs, options?: PatchApiAutomationsAutomationIdStatusOptions) => { const {baseUrl = "https://api.qonversion.io/v4", fetch: fetchFn = fetch, secretAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (secretAuth !== undefined) headers.set('authorization', `Bearer ${secretAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/automations/${encodeURIComponent(String(args.automation_id))}/status${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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 };