0

Get Memberships of an Organization

by
Published Oct 30, 2023

List the memberships of a Workspace

Script trello Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 398 days ago
1
type Trello = {
2
  key: string;
3
  token: string;
4
};
5
/**
6
 * Get Memberships of an Organization
7
 * List the memberships of a Workspace
8
 */
9
export async function main(
10
  auth: Trello,
11
  id: string,
12
  filter:
13
    | "all"
14
    | "active"
15
    | "admin"
16
    | "deactivated"
17
    | "me"
18
    | "normal"
19
    | undefined,
20
  member: string | undefined
21
) {
22
  const url = new URL(
23
    `https://api.trello.com/1/organizations/${id}/memberships`
24
  );
25
  for (const [k, v] of [
26
    ["filter", filter],
27
    ["member", member],
28
    ["key", auth.key],
29
    ["token", auth.token],
30
  ]) {
31
    if (v !== undefined && v !== "") {
32
      url.searchParams.append(k, v);
33
    }
34
  }
35
  const response = await fetch(url, {
36
    method: "GET",
37
    headers: {
38
      Authorization: undefined,
39
    },
40
    body: undefined,
41
  });
42
  if (!response.ok) {
43
    const text = await response.text();
44
    throw new Error(`${response.status} ${text}`);
45
  }
46
  return await response.json();
47
}
48