1 | |
2 | |
3 | * List of contracts |
4 | * Retrieve a list of contracts. |
5 | **Token scopes**: `contracts:read` |
6 | */ |
7 | export async function main( |
8 | auth: RT.Deel, |
9 | after_cursor?: string | undefined, |
10 | limit?: string | undefined, |
11 | order_direction?: 'asc' | 'desc' | undefined, |
12 | types?: string | undefined, |
13 | statuses?: string | undefined, |
14 | team_id?: string | undefined, |
15 | external_id?: string | undefined, |
16 | countries?: string | undefined, |
17 | currencies?: string | undefined, |
18 | search?: string | undefined, |
19 | sort_by?: 'contract_title' | 'worker_name' | undefined, |
20 | expand?: 'cost_centers' | undefined |
21 | ) { |
22 | const url = new URL(`https://api.letsdeel.com/rest/v2/contracts`) |
23 | for (const [k, v] of [ |
24 | ['after_cursor', after_cursor], |
25 | ['limit', limit], |
26 | ['order_direction', order_direction], |
27 | ['types', types], |
28 | ['statuses', statuses], |
29 | ['team_id', team_id], |
30 | ['external_id', external_id], |
31 | ['countries', countries], |
32 | ['currencies', currencies], |
33 | ['search', search], |
34 | ['sort_by', sort_by], |
35 | ['expand', expand] |
36 | ]) { |
37 | if (v !== undefined && v !== '') { |
38 | url.searchParams.append(k, v) |
39 | } |
40 | } |
41 | const response = await fetch(url, { |
42 | method: 'GET', |
43 | headers: { |
44 | Authorization: 'Bearer ' + auth.apiKey |
45 | }, |
46 | body: undefined |
47 | }) |
48 | if (!response.ok) { |
49 | const text = await response.text() |
50 | throw new Error(`${response.status} ${text}`) |
51 | } |
52 | return await response.json() |
53 | } |
54 |
|