0

List companies

by
Published Oct 17, 2025

The *List companies* endpoint returns a list of [companies](https://docs.

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

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