export type GetApiV1BillsIdXmlArgs = {id: number, summary?: boolean | undefined}; export type GetApiV1BillsIdXmlOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Download XML version of a bill * * GET /v1/Bills/{id}/xml */ export const getApiV1BillsIdXml = async (args: GetApiV1BillsIdXmlArgs, options?: GetApiV1BillsIdXmlOptions) => { const {baseUrl = "https://restapi.rev.io", fetch: fetchFn = fetch, basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.summary != null) query.append("summary", String(args.summary)) if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/Bills/${encodeURIComponent(String(args.id))}/xml${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 undefined };