0

Get the Board for an Action

by
Published Oct 30, 2023

Get the Board for an Action

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