0

List accounts

by
Published Oct 17, 2025

The *List accounts* endpoint returns a list of [accounts](https://docs.codat.io/sync-for-payables-api#/schemas/Account) for a given company's connection. [Accounts](https://docs.codat.io/sync-for-payables-api#/schemas/Account) are the categories a business uses to record accounting transactions. Before using this endpoint, you must have [retrieved data for the company](https://docs.codat.io/sync-for-payables-api#/operations/refresh-company-data).

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 accounts
7
 * The *List accounts* endpoint returns a list of [accounts](https://docs.codat.io/sync-for-payables-api#/schemas/Account) for a given company's connection.
8

9
[Accounts](https://docs.codat.io/sync-for-payables-api#/schemas/Account) are the categories a business uses to record accounting transactions.
10

11
Before using this endpoint, you must have [retrieved data for the company](https://docs.codat.io/sync-for-payables-api#/operations/refresh-company-data).
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}/data/accounts`)
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