0

Get Boards that Member belongs to

by
Published Oct 30, 2023

Lists the boards that the user is a member of.

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 Boards that Member belongs to
7
 * Lists the boards that the user is a member of.
8
 */
9
export async function main(
10
  auth: Trello,
11
  id: string,
12
  filter:
13
    | "all"
14
    | "closed"
15
    | "members"
16
    | "open"
17
    | "organization"
18
    | "public"
19
    | "starred"
20
    | undefined,
21
  fields:
22
    | "id"
23
    | "name"
24
    | "desc"
25
    | "descData"
26
    | "closed"
27
    | "idMemberCreator"
28
    | "idOrganization"
29
    | "pinned"
30
    | "url"
31
    | "shortUrl"
32
    | "prefs"
33
    | "labelNames"
34
    | "starred"
35
    | "limits"
36
    | "memberships"
37
    | "enterpriseOwned"
38
    | undefined,
39
  lists: "all" | "closed" | "none" | "open" | undefined,
40
  organization: string | undefined,
41
  organization_fields: "id" | "name" | undefined
42
) {
43
  const url = new URL(`https://api.trello.com/1/members/${id}/boards`);
44
  for (const [k, v] of [
45
    ["filter", filter],
46
    ["fields", fields],
47
    ["lists", lists],
48
    ["organization", organization],
49
    ["organization_fields", organization_fields],
50
    ["key", auth.key],
51
    ["token", auth.token],
52
  ]) {
53
    if (v !== undefined && v !== "") {
54
      url.searchParams.append(k, v);
55
    }
56
  }
57
  const response = await fetch(url, {
58
    method: "GET",
59
    headers: {
60
      Authorization: undefined,
61
    },
62
    body: undefined,
63
  });
64
  if (!response.ok) {
65
    const text = await response.text();
66
    throw new Error(`${response.status} ${text}`);
67
  }
68
  return await response.json();
69
}
70