0

Retrieve a single contract

by
Published Oct 17, 2025

Retrieve a single contract. **Token scopes**: `contracts:read`

Script deel Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Retrieve a single contract
4
 * Retrieve a single contract.
5
 **Token scopes**: `contracts:read`
6
 */
7
export async function main(
8
	auth: RT.Deel,
9
	contract_id: string,
10
	expand?: 'cost_centers' | undefined
11
) {
12
	const url = new URL(`https://api.letsdeel.com/rest/v2/contracts/${contract_id}`)
13
	for (const [k, v] of [['expand', expand]]) {
14
		if (v !== undefined && v !== '') {
15
			url.searchParams.append(k, v)
16
		}
17
	}
18
	const response = await fetch(url, {
19
		method: 'GET',
20
		headers: {
21
			Authorization: 'Bearer ' + auth.apiKey
22
		},
23
		body: undefined
24
	})
25
	if (!response.ok) {
26
		const text = await response.text()
27
		throw new Error(`${response.status} ${text}`)
28
	}
29
	return await response.json()
30
}
31