0

List data connections

by
Published Oct 17, 2025

Retrieve previously created data connections.

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 data connections
7
 * Retrieve previously created data connections.
8
 */
9
export async function main(
10
	auth: Codat,
11
	companyId: string,
12
	page: string | undefined,
13
	pageSize: string | undefined,
14
	query: string | undefined,
15
	orderBy: string | undefined
16
) {
17
	const url = new URL(`https://api.codat.io/meta/companies/${companyId}/connections`)
18
	for (const [k, v] of [
19
		['page', page],
20
		['pageSize', pageSize],
21
		['query', query],
22
		['orderBy', orderBy]
23
	]) {
24
		if (v !== undefined && v !== '' && k !== undefined) {
25
			url.searchParams.append(k, v)
26
		}
27
	}
28

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