export type CreateApiEngageProfileUnionArgs = {ip?: number | undefined, strict?: number | undefined, verbose?: number | undefined, callback?: string | undefined, body: Array<{$token: string, $distinct_id: string, $union: {[key: string]: Array}}>}; export type CreateApiEngageProfileUnionOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Union To List Property * * POST /engage#profile-union */ export const createApiEngageProfileUnion = async (args: CreateApiEngageProfileUnionArgs, options?: CreateApiEngageProfileUnionOptions) => { const {baseUrl = "https://mixpanel.com/api/query", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "text/plain") if (args.ip != null) query.append("ip", String(args.ip)) if (args.strict != null) query.append("strict", String(args.strict)) if (args.verbose != null) query.append("verbose", String(args.verbose)) if (args.callback != null) query.append("callback", String(args.callback)) const url = `${baseUrl.replace(/\/+$/, '')}/engage#profile-union${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 res.text() };