0

Get Boards in an Organization

by
Published Oct 30, 2023

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