0

List reconciled invoices

by
Published Oct 17, 2025

Gets a list of invoices linked to the corresponding banking transaction

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 reconciled invoices
7
 * Gets a list of invoices linked to the corresponding banking transaction
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
) {
16
	const url = new URL(`https://api.codat.io/companies/${companyId}/reports/enhancedInvoices`)
17
	for (const [k, v] of [
18
		['page', page],
19
		['pageSize', pageSize],
20
		['query', query]
21
	]) {
22
		if (v !== undefined && v !== '' && k !== undefined) {
23
			url.searchParams.append(k, v)
24
		}
25
	}
26

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