0

Download Excel report

by
Published Oct 17, 2025

The *Download Excel report* endpoint downloads the latest successfully generated Excel report of a specified report type for a given company. The downloadable Excel file is returned in the response. You can save it to your local machine. You can [learn more](https://docs.codat.io/lending/features/excel-download-overview#feature-components) about valid Excel report types.

Script codat Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Codat = {
3
	encodedKey: string
4
}
5
/**
6
 * Download Excel report
7
 * The *Download Excel report* endpoint downloads the latest successfully generated Excel report of a specified report type for a given company. 
8

9
The downloadable Excel file is returned in the response. You can save it to your local machine.
10

11
You can [learn more](https://docs.codat.io/lending/features/excel-download-overview#feature-components) about valid Excel report types.
12
 */
13
export async function main(
14
	auth: Codat,
15
	companyId: string,
16
	reportType: 'audit' | 'enhancedFinancials' | 'enhancedInvoices' | 'enhancedCashFlow' | undefined
17
) {
18
	const url = new URL(`https://api.codat.io/data/companies/${companyId}/assess/excel/download`)
19
	for (const [k, v] of [['reportType', reportType]]) {
20
		if (v !== undefined && v !== '' && k !== undefined) {
21
			url.searchParams.append(k, v)
22
		}
23
	}
24

25
	const response = await fetch(url, {
26
		method: 'GET',
27
		headers: {
28
			Authorization: `Basic ${auth.encodedKey}`
29
		},
30
		body: undefined
31
	})
32
	if (!response.ok) {
33
		const text = await response.text()
34
		throw new Error(`${response.status} ${text}`)
35
	}
36
	return await response.text()
37
}
38