0

Refresh all data

by
Published Oct 17, 2025

Refreshes all data types with `fetch on first link` set to `true` for a given company. This is an asynchronous operation, and will bring updated data into Codat from the linked integration for you to view. [Read more](https://docs.codat.io/core-concepts/data-type-settings) about data type settings and `fetch on first link`.

Script codat Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Codat = {
3
	encodedKey: string
4
}
5
/**
6
 * Refresh all data
7
 * Refreshes all data types with `fetch on first link` set to `true` for a given company.
8

9
This is an asynchronous operation, and will bring updated data into Codat from the linked integration for you to view.
10

11
[Read more](https://docs.codat.io/core-concepts/data-type-settings) about data type settings and `fetch on first link`.
12
 */
13
export async function main(auth: Codat, companyId: string) {
14
	const url = new URL(`https://api.codat.io/companies/${companyId}/data/all`)
15

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