0

Get a Board

by
Published Oct 30, 2023

Request a single board.

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 a Board
7
 * Request a single board.
8
 */
9
export async function main(
10
  auth: Trello,
11
  id: string,
12
  actions: string | undefined,
13
  boardStars: string | undefined,
14
  cards: string | undefined,
15
  card_pluginData: string | undefined,
16
  checklists: string | undefined,
17
  customFields: string | undefined,
18
  fields: string | undefined,
19
  labels: string | undefined,
20
  lists: string | undefined,
21
  members: string | undefined,
22
  memberships: string | undefined,
23
  pluginData: string | undefined,
24
  organization: string | undefined,
25
  organization_pluginData: string | undefined,
26
  myPrefs: string | undefined,
27
  tags: string | undefined
28
) {
29
  const url = new URL(`https://api.trello.com/1/boards/${id}`);
30
  for (const [k, v] of [
31
    ["actions", actions],
32
    ["boardStars", boardStars],
33
    ["cards", cards],
34
    ["card_pluginData", card_pluginData],
35
    ["checklists", checklists],
36
    ["customFields", customFields],
37
    ["fields", fields],
38
    ["labels", labels],
39
    ["lists", lists],
40
    ["members", members],
41
    ["memberships", memberships],
42
    ["pluginData", pluginData],
43
    ["organization", organization],
44
    ["organization_pluginData", organization_pluginData],
45
    ["myPrefs", myPrefs],
46
    ["tags", tags],
47
    ["key", auth.key],
48
    ["token", auth.token],
49
  ]) {
50
    if (v !== undefined && v !== "") {
51
      url.searchParams.append(k, v);
52
    }
53
  }
54
  const response = await fetch(url, {
55
    method: "GET",
56
    headers: {
57
      Authorization: undefined,
58
    },
59
    body: undefined,
60
  });
61
  if (!response.ok) {
62
    const text = await response.text();
63
    throw new Error(`${response.status} ${text}`);
64
  }
65
  return await response.json();
66
}
67