0

Get Member's Organizations

by
Published Oct 30, 2023

Get a member's Workspaces

Script trello Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 399 days ago
1
type Trello = {
2
  key: string;
3
  token: string;
4
};
5
/**
6
 * Get Member's Organizations
7
 * Get a member's Workspaces
8
 */
9
export async function main(
10
  auth: Trello,
11
  id: string,
12
  filter: "all" | "members" | "none" | "public" | undefined,
13
  fields: "id" | "name" | undefined,
14
  paid_account: string | undefined
15
) {
16
  const url = new URL(`https://api.trello.com/1/members/${id}/organizations`);
17
  for (const [k, v] of [
18
    ["filter", filter],
19
    ["fields", fields],
20
    ["paid_account", paid_account],
21
    ["key", auth.key],
22
    ["token", auth.token],
23
  ]) {
24
    if (v !== undefined && v !== "") {
25
      url.searchParams.append(k, v);
26
    }
27
  }
28
  const response = await fetch(url, {
29
    method: "GET",
30
    headers: {
31
      Authorization: undefined,
32
    },
33
    body: undefined,
34
  });
35
  if (!response.ok) {
36
    const text = await response.text();
37
    throw new Error(`${response.status} ${text}`);
38
  }
39
  return await response.json();
40
}
41