0

Generate Excel report

by
Published Oct 17, 2025

The *Generate Excel report* endpoint requests the production of a downloadable Excel file for a report type specified in the `reportType` query parameter.

Script codat Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Codat = {
3
	encodedKey: string
4
}
5
/**
6
 * Generate Excel report
7
 * The *Generate Excel report* endpoint requests the production of a downloadable Excel file for a report type specified in the `reportType` query parameter.
8
 */
9
export async function main(
10
	auth: Codat,
11
	companyId: string,
12
	reportType: 'audit' | 'enhancedFinancials' | 'enhancedInvoices' | 'enhancedCashFlow' | undefined
13
) {
14
	const url = new URL(`https://api.codat.io/data/companies/${companyId}/assess/excel`)
15
	for (const [k, v] of [['reportType', reportType]]) {
16
		if (v !== undefined && v !== '' && k !== undefined) {
17
			url.searchParams.append(k, v)
18
		}
19
	}
20

21
	const response = await fetch(url, {
22
		method: 'POST',
23
		headers: {
24
			Authorization: `Basic ${auth.encodedKey}`
25
		},
26
		body: undefined
27
	})
28
	if (!response.ok) {
29
		const text = await response.text()
30
		throw new Error(`${response.status} ${text}`)
31
	}
32
	return await response.json()
33
}
34