1 | type Trello = { |
2 | key: string; |
3 | token: string; |
4 | }; |
5 | |
6 | * Get Users of an Enterprise |
7 | * Get an enterprise's users. You can choose to retrieve licensed members, board guests, etc. |
8 | */ |
9 | export async function main( |
10 | auth: Trello, |
11 | id: string, |
12 | licensed: string | undefined, |
13 | deactivated: string | undefined, |
14 | collaborator: string | undefined, |
15 | managed: string | undefined, |
16 | admin: string | undefined, |
17 | activeSince: string | undefined, |
18 | inactiveSince: string | undefined, |
19 | search: string | undefined, |
20 | startIndex: string | undefined |
21 | ) { |
22 | const url = new URL( |
23 | `https://api.trello.com/1/enterprises/${id}/members/query` |
24 | ); |
25 | for (const [k, v] of [ |
26 | ["licensed", licensed], |
27 | ["deactivated", deactivated], |
28 | ["collaborator", collaborator], |
29 | ["managed", managed], |
30 | ["admin", admin], |
31 | ["activeSince", activeSince], |
32 | ["inactiveSince", inactiveSince], |
33 | ["search", search], |
34 | ["startIndex", startIndex], |
35 | ["key", auth.key], |
36 | ["token", auth.token], |
37 | ]) { |
38 | if (v !== undefined && v !== "") { |
39 | url.searchParams.append(k, v); |
40 | } |
41 | } |
42 | const response = await fetch(url, { |
43 | method: "GET", |
44 | headers: { |
45 | Authorization: undefined, |
46 | }, |
47 | body: undefined, |
48 | }); |
49 | if (!response.ok) { |
50 | const text = await response.text(); |
51 | throw new Error(`${response.status} ${text}`); |
52 | } |
53 | return await response.json(); |
54 | } |
55 |
|