0

List transaction categories

by
Published Oct 17, 2025

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

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