export type CreateApiCampaignsArgs = {body: {name: string, account_id: string, organization_code: string, country: string, channel: 'WHATSAPP_MESSAGE' | 'PHONE_CALL', focus?: string | undefined, schedule: {daily_start_time: string, daily_end_time: string, time_zone: string}, duration: {start_at: string, end_at: string}}}; export type CreateApiCampaignsOptions = {baseUrl?: string | undefined, publicApiKey?: string | undefined, privateSecretKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * POST /campaigns */ export const createApiCampaigns = async (args: CreateApiCampaignsArgs, options?: CreateApiCampaignsOptions) => { const {baseUrl = "https://api-sandbox.y.uno/v1", fetch: fetchFn = fetch, publicApiKey, privateSecretKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (publicApiKey !== undefined) headers.set("PUBLIC-API-KEY", publicApiKey) if (privateSecretKey !== undefined) headers.set("PRIVATE-SECRET-KEY", privateSecretKey) const url = `${baseUrl.replace(/\/+$/, '')}/campaigns${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 };