1 | |
2 | |
3 | * Return list of groups |
4 | * List all the groups in your organization. |
5 | **Token scopes**: `groups:read` |
6 | */ |
7 | export async function main( |
8 | auth: RT.Deel, |
9 | limit?: string | undefined, |
10 | sort_order?: 'ASC' | 'DESC' | undefined, |
11 | cursor?: string | undefined, |
12 | include_archived_groups?: string | undefined, |
13 | external_metadata?: string | undefined |
14 | ) { |
15 | const url = new URL(`https://api.letsdeel.com/rest/v2/groups`) |
16 | for (const [k, v] of [ |
17 | ['limit', limit], |
18 | ['sort_order', sort_order], |
19 | ['cursor', cursor], |
20 | ['include_archived_groups', include_archived_groups], |
21 | ['external_metadata', external_metadata] |
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 |
|