export type CreateApiV2MessagesArgs = {sender_id: number, 'receiver_ids[]': Array, body: string, 'X-Time-Zone'?: string | undefined, 'X-Metric-Units'?: boolean | undefined}; export type CreateApiV2MessagesOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; /** * Send bulk messages to your users (v2) * * POST /v2/messages */ export const createApiV2Messages = async (args: CreateApiV2MessagesArgs, options?: CreateApiV2MessagesOptions) => { const {baseUrl = "https://api.gomotive.com", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.sender_id != null) query.append("sender_id", String(args.sender_id)) for (const item of args['receiver_ids[]'] ?? []) query.append("receiver_ids[]", String(item)) if (args.body != null) query.append("body", String(args.body)) if (args['X-Time-Zone'] != null) headers.set("X-Time-Zone", String(args['X-Time-Zone'])) if (args['X-Metric-Units'] != null) headers.set("X-Metric-Units", String(args['X-Metric-Units'])) if (sec0 !== undefined) headers.set("x-api-key", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/v2/messages${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return (await res.json()) as unknown };