export type GetApiInvoicesInvoiceIdPdfArgs = {invoice_id: string, customer_id?: string | undefined}; export type GetApiInvoicesInvoiceIdPdfOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Download the invoice as PDF * * GET /invoices/{invoice_id}/pdf */ export const getApiInvoicesInvoiceIdPdf = async (args: GetApiInvoicesInvoiceIdPdfArgs, options?: GetApiInvoicesInvoiceIdPdfOptions) => { const {baseUrl = "https://api.app.lastaccountingcompany.com/portal", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/pdf") if (args.customer_id != null) query.append("customer_id", String(args.customer_id)) if (apiKey !== undefined) headers.set('authorization', `Bearer ${apiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/invoices/${encodeURIComponent(String(args.invoice_id))}/pdf${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.blob() };