0

Invoice line items by contract

by
Published Oct 17, 2025

Retrieve invoice line items for a given contract id. **Token scopes**: `invoice-adjustments:read`

Script deel Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Invoice line items by contract
4
 * Retrieve invoice line items for a given contract id.
5
 **Token scopes**: `invoice-adjustments:read`
6
 */
7
export async function main(
8
	auth: RT.Deel,
9
	contract_id: string,
10
	contract_types?: string | undefined,
11
	types?: string | undefined,
12
	statuses?: string | undefined,
13
	invoice_id?: string | undefined,
14
	reporter_id?: string | undefined,
15
	date_from?: string | undefined,
16
	date_to?: string | undefined,
17
	limit?: string | undefined,
18
	offset?: string | undefined
19
) {
20
	const url = new URL(
21
		`https://api.letsdeel.com/rest/v2/contracts/${contract_id}/invoice-adjustments`
22
	)
23
	for (const [k, v] of [
24
		['contract_types', contract_types],
25
		['types', types],
26
		['statuses', statuses],
27
		['invoice_id', invoice_id],
28
		['reporter_id', reporter_id],
29
		['date_from', date_from],
30
		['date_to', date_to],
31
		['limit', limit],
32
		['offset', offset]
33
	]) {
34
		if (v !== undefined && v !== '') {
35
			url.searchParams.append(k, v)
36
		}
37
	}
38
	const response = await fetch(url, {
39
		method: 'GET',
40
		headers: {
41
			Authorization: 'Bearer ' + auth.apiKey
42
		},
43
		body: undefined
44
	})
45
	if (!response.ok) {
46
		const text = await response.text()
47
		throw new Error(`${response.status} ${text}`)
48
	}
49
	return await response.json()
50
}
51