export type GetApiProductsHelpDeskAnalyticsExportCsvArgs = {from: string, to: string, team_id?: string | undefined, operator_id?: string | undefined}; export type GetApiProductsHelpDeskAnalyticsExportCsvOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Download the help desk analytics as CSV * * GET /products/help-desk/analytics/export.csv */ export const getApiProductsHelpDeskAnalyticsExportCsv = async (args: GetApiProductsHelpDeskAnalyticsExportCsvArgs, options?: GetApiProductsHelpDeskAnalyticsExportCsvOptions) => { const {baseUrl = "https://api.sparkvault.com/v1", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/csv") if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args.team_id != null) query.append("team_id", String(args.team_id)) if (args.operator_id != null) query.append("operator_id", String(args.operator_id)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/products/help-desk/analytics/export.csv${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() };