1 | type Trello = { |
2 | key: string; |
3 | token: string; |
4 | }; |
5 | |
6 | * Get Members of Enterprise |
7 | * Get the members of an enterprise. |
8 | */ |
9 | export async function main( |
10 | auth: Trello, |
11 | id: string, |
12 | fields: string | undefined, |
13 | filter: string | undefined, |
14 | sort: string | undefined, |
15 | sortBy: string | undefined, |
16 | sortOrder: "ascending" | "descending" | "asc" | "desc" | "null" | undefined, |
17 | startIndex: string | undefined, |
18 | count: string | undefined, |
19 | organization_fields: string | undefined, |
20 | board_fields: string | undefined |
21 | ) { |
22 | const url = new URL(`https://api.trello.com/1/enterprises/${id}/members`); |
23 | for (const [k, v] of [ |
24 | ["fields", fields], |
25 | ["filter", filter], |
26 | ["sort", sort], |
27 | ["sortBy", sortBy], |
28 | ["sortOrder", sortOrder], |
29 | ["startIndex", startIndex], |
30 | ["count", count], |
31 | ["organization_fields", organization_fields], |
32 | ["board_fields", board_fields], |
33 | ["key", auth.key], |
34 | ["token", auth.token], |
35 | ]) { |
36 | if (v !== undefined && v !== "") { |
37 | url.searchParams.append(k, v); |
38 | } |
39 | } |
40 | const response = await fetch(url, { |
41 | method: "GET", |
42 | headers: { |
43 | Authorization: undefined, |
44 | }, |
45 | body: undefined, |
46 | }); |
47 | if (!response.ok) { |
48 | const text = await response.text(); |
49 | throw new Error(`${response.status} ${text}`); |
50 | } |
51 | return await response.json(); |
52 | } |
53 |
|