0

List bills

by
Published Oct 17, 2025

The *List bills* endpoint returns a list of [bills](https://docs.codat.io/sync-for-payables-api#/schemas/Bill) for a given company's connection. [Bills](https://docs.codat.io/sync-for-payables-api#/schemas/Bill) are invoices that represent the SMB's financial obligations to their supplier for a purchase of goods or services.

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

9
[Bills](https://docs.codat.io/sync-for-payables-api#/schemas/Bill) are invoices that represent the SMB's financial obligations to their supplier for a purchase of goods or services.
10
 */
11
export async function main(
12
	auth: Codat,
13
	companyId: string,
14
	page: string | undefined,
15
	pageSize: string | undefined,
16
	query: string | undefined,
17
	orderBy: string | undefined
18
) {
19
	const url = new URL(`https://api.codat.io/companies/${companyId}/data/bills`)
20
	for (const [k, v] of [
21
		['page', page],
22
		['pageSize', pageSize],
23
		['query', query],
24
		['orderBy', orderBy]
25
	]) {
26
		if (v !== undefined && v !== '' && k !== undefined) {
27
			url.searchParams.append(k, v)
28
		}
29
	}
30

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