0

Retrieve invoices

by
Published Oct 17, 2025

Retrieve a list of paid invoices for your workforce. **Token scopes**: `accounting:read`

Script deel Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Retrieve invoices
4
 * Retrieve a list of paid invoices for your workforce.
5
 **Token scopes**: `accounting:read`
6
 */
7
export async function main(
8
	auth: RT.Deel,
9
	issued_from_date?: string | undefined,
10
	issued_to_date?: string | undefined,
11
	entities?: string | undefined,
12
	limit?: string | undefined,
13
	offset?: string | undefined
14
) {
15
	const url = new URL(`https://api.letsdeel.com/rest/v2/invoices`)
16
	for (const [k, v] of [
17
		['issued_from_date', issued_from_date],
18
		['issued_to_date', issued_to_date],
19
		['entities', entities],
20
		['limit', limit],
21
		['offset', offset]
22
	]) {
23
		if (v !== undefined && v !== '') {
24
			url.searchParams.append(k, v)
25
		}
26
	}
27
	const response = await fetch(url, {
28
		method: 'GET',
29
		headers: {
30
			Authorization: 'Bearer ' + auth.apiKey
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