0

Get report status

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 *Get report status* endpoint to return the metadata about report generation, such as its current status, date of request, and date of generation. You can either provide the ID of a report or use `latest` as the ID value to get the most recent generated *reportName* report for the company.

Script codat Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Codat = {
3
	encodedKey: string
4
}
5
/**
6
 * Get report status
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 *Get report status* endpoint to return the metadata about report generation, such as its current status, date of request, and date of generation.
12

13
You can either provide the ID of a report or use `latest` as the ID value to get the most recent generated *reportName* report for the company.
14

15

16
 */
17
export async function main(
18
	auth: Codat,
19
	companyId: string,
20
	reportType: 'spendAnalysis',
21
	reportId: string,
22
	maxAge: string | undefined
23
) {
24
	const url = new URL(
25
		`https://api.codat.io/companies/${companyId}/reports/${reportType}/${reportId}/status`
26
	)
27
	for (const [k, v] of [['maxAge', maxAge]]) {
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