export type GetApiContactsExportArgs = {list_id?: string | undefined, status?: ('subscribed' | 'pending' | 'unsubscribed' | 'bounced' | 'complained' | 'dormant') | undefined, query?: string | undefined, tag?: string | undefined, source?: ('form' | 'api' | 'import') | undefined, after?: string | undefined, before?: string | undefined, segment_id?: string | undefined}; export type GetApiContactsExportOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Export contacts as CSV * * GET /contacts/export */ export const getApiContactsExport = async (args: GetApiContactsExportArgs, options?: GetApiContactsExportOptions) => { const {baseUrl = "https://sendhq.cc/api/v1", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/csv") if (args.list_id != null) query.append("list_id", String(args.list_id)) if (args.status != null) query.append("status", String(args.status)) if (args.query != null) query.append("query", String(args.query)) if (args.tag != null) query.append("tag", String(args.tag)) if (args.source != null) query.append("source", String(args.source)) if (args.after != null) query.append("after", String(args.after)) if (args.before != null) query.append("before", String(args.before)) if (args.segment_id != null) query.append("segment_id", String(args.segment_id)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/contacts/export${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.text() };