0

List reports

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 *List reports* endpoint to return details (such as generation's current status, date of request, and date of generation) about all reports generated for a company. The query parameter can be used to filter the results.

Script codat Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Codat = {
3
	encodedKey: string
4
}
5
/**
6
 * List reports
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 *List reports* endpoint to return details (such as generation's current status, date of request, and date of generation) about all reports generated for a company. The query parameter can be used to filter the results.
12
 */
13
export async function main(
14
	auth: Codat,
15
	companyId: string,
16
	page: string | undefined,
17
	pageSize: string | undefined,
18
	query: string | undefined,
19
	orderBy: string | undefined
20
) {
21
	const url = new URL(`https://api.codat.io/companies/${companyId}/reports`)
22
	for (const [k, v] of [
23
		['page', page],
24
		['pageSize', pageSize],
25
		['query', query],
26
		['orderBy', orderBy]
27
	]) {
28
		if (v !== undefined && v !== '' && k !== undefined) {
29
			url.searchParams.append(k, v)
30
		}
31
	}
32

33
	const response = await fetch(url, {
34
		method: 'GET',
35
		headers: {
36
			Authorization: `Basic ${auth.encodedKey}`
37
		},
38
		body: undefined
39
	})
40
	if (!response.ok) {
41
		const text = await response.text()
42
		throw new Error(`${response.status} ${text}`)
43
	}
44
	return await response.json()
45
}
46