0

Get Actions of a Board

by
Published Oct 30, 2023
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 Actions of a Board
7
 *
8
 */
9
export async function main(
10
  auth: Trello,
11
  boardId: string,
12
  fields: string | undefined,
13
  filter: string | undefined,
14
  format: string | undefined,
15
  idModels: string | undefined,
16
  limit: string | undefined,
17
  member: string | undefined,
18
  member_fields: string | undefined,
19
  memberCreator: string | undefined,
20
  memberCreator_fields: string | undefined,
21
  page: string | undefined,
22
  reactions: string | undefined,
23
  before: string | undefined,
24
  since: string | undefined
25
) {
26
  const url = new URL(`https://api.trello.com/1/boards/${boardId}/actions`);
27
  for (const [k, v] of [
28
    ["fields", fields],
29
    ["filter", filter],
30
    ["format", format],
31
    ["idModels", idModels],
32
    ["limit", limit],
33
    ["member", member],
34
    ["member_fields", member_fields],
35
    ["memberCreator", memberCreator],
36
    ["memberCreator_fields", memberCreator_fields],
37
    ["page", page],
38
    ["reactions", reactions],
39
    ["before", before],
40
    ["since", since],
41
    ["key", auth.key],
42
    ["token", auth.token],
43
  ]) {
44
    if (v !== undefined && v !== "") {
45
      url.searchParams.append(k, v);
46
    }
47
  }
48
  const response = await fetch(url, {
49
    method: "GET",
50
    headers: {
51
      Authorization: undefined,
52
    },
53
    body: undefined,
54
  });
55
  if (!response.ok) {
56
    const text = await response.text();
57
    throw new Error(`${response.status} ${text}`);
58
  }
59
  return await response.text();
60
}
61