0

Generate report

by
Published Oct 17, 2025

> **Available as beta release** > > This endpoint is part of a beta release. Please contact your account manager if you want to enable it. Use the *Generate report* endpoint to initiate the generation of a report specified by the `reportType` parameter. This action triggers the system to refresh and pull the necessary data from the company's data sources to ensure the report contains the most up-to-date information.

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 report
7
 * > **Available as beta release**
8
>
9
> This endpoint is part of a beta release. Please contact your account manager if you want to enable it.
10

11
Use the *Generate report* endpoint to initiate the generation of a report specified by the `reportType` parameter.
12

13
This action triggers the system to refresh and pull the necessary data from the company's data sources to ensure the report contains the most up-to-date information.
14
 */
15
export async function main(auth: Codat, companyId: string, reportType: 'spendAnalysis') {
16
	const url = new URL(`https://api.codat.io/companies/${companyId}/reports/${reportType}`)
17

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