0

Get a specific field on an Action

by
Published Oct 30, 2023

Get a specific property of 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 a specific field on an Action
7
 * Get a specific property of an action
8
 */
9
export async function main(
10
  auth: Trello,
11
  id: string,
12
  field:
13
    | "id"
14
    | "idMemberCreator"
15
    | "data"
16
    | "type"
17
    | "date"
18
    | "limits"
19
    | "display"
20
    | "memberCreator"
21
) {
22
  const url = new URL(`https://api.trello.com/1/actions/${id}/${field}`);
23
  for (const [k, v] of [
24
    ["key", auth.key],
25
    ["token", auth.token],
26
  ]) {
27
    if (v !== undefined && v !== "") {
28
      url.searchParams.append(k, v);
29
    }
30
  }
31
  const response = await fetch(url, {
32
    method: "GET",
33
    headers: {
34
      Authorization: undefined,
35
    },
36
    body: undefined,
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.json();
43
}
44