1 | |
2 | |
3 | * List of people |
4 | * Retrieve a list of People in your organization. |
5 | **Token scopes**: `people:read` |
6 | */ |
7 | export async function main( |
8 | auth: RT.Deel, |
9 | offset?: string | undefined, |
10 | limit?: string | undefined, |
11 | search?: string | undefined, |
12 | sort_by?: |
13 | | 'id' |
14 | | 'first_name' |
15 | | 'last_name' |
16 | | 'full_name' |
17 | | 'email' |
18 | | 'country' |
19 | | 'birth_date' |
20 | | 'hiring_type' |
21 | | 'start_date' |
22 | | 'team' |
23 | | 'job_title' |
24 | | 'hiring_status' |
25 | | 'completion_date' |
26 | | 'direct_manager' |
27 | | 'direct_reports_count' |
28 | | undefined, |
29 | sort_order?: 'asc' | 'desc' | undefined, |
30 | hiring_statuses?: string | undefined |
31 | ) { |
32 | const url = new URL(`https://api.letsdeel.com/rest/v2/people`) |
33 | for (const [k, v] of [ |
34 | ['offset', offset], |
35 | ['limit', limit], |
36 | ['search', search], |
37 | ['sort_by', sort_by], |
38 | ['sort_order', sort_order], |
39 | ['hiring_statuses', hiring_statuses] |
40 | ]) { |
41 | if (v !== undefined && v !== '') { |
42 | url.searchParams.append(k, v) |
43 | } |
44 | } |
45 | const response = await fetch(url, { |
46 | method: 'GET', |
47 | headers: { |
48 | Authorization: 'Bearer ' + auth.apiKey |
49 | }, |
50 | body: undefined |
51 | }) |
52 | if (!response.ok) { |
53 | const text = await response.text() |
54 | throw new Error(`${response.status} ${text}`) |
55 | } |
56 | return await response.json() |
57 | } |
58 |
|