0

Get the Card for an Action

by
Published Oct 30, 2023

Get the card for an action

Script trello Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 399 days ago
1
type Trello = {
2
  key: string;
3
  token: string;
4
};
5
/**
6
 * Get the Card for an Action
7
 * Get the card for an action
8
 */
9
export async function main(
10
  auth: Trello,
11
  id: string,
12
  fields:
13
    | "id"
14
    | "address"
15
    | "badges"
16
    | "checkItemStates"
17
    | "closed"
18
    | "coordinates"
19
    | "creationMethod"
20
    | "dueComplete"
21
    | "dateLastActivity"
22
    | "desc"
23
    | "descData"
24
    | "due"
25
    | "dueReminder"
26
    | "email"
27
    | "idBoard"
28
    | "idChecklists"
29
    | "idLabels"
30
    | "idList"
31
    | "idMembers"
32
    | "idMembersVoted"
33
    | "idShort"
34
    | "idAttachmentCover"
35
    | "labels"
36
    | "limits"
37
    | "locationName"
38
    | "manualCoverAttachment"
39
    | "name"
40
    | "pos"
41
    | "shortLink"
42
    | "shortUrl"
43
    | "subscribed"
44
    | "url"
45
    | "cover"
46
    | "isTemplate"
47
    | undefined
48
) {
49
  const url = new URL(`https://api.trello.com/1/actions/${id}/card`);
50
  for (const [k, v] of [
51
    ["fields", fields],
52
    ["key", auth.key],
53
    ["token", auth.token],
54
  ]) {
55
    if (v !== undefined && v !== "") {
56
      url.searchParams.append(k, v);
57
    }
58
  }
59
  const response = await fetch(url, {
60
    method: "GET",
61
    headers: {
62
      Authorization: undefined,
63
    },
64
    body: undefined,
65
  });
66
  if (!response.ok) {
67
    const text = await response.text();
68
    throw new Error(`${response.status} ${text}`);
69
  }
70
  return await response.json();
71
}
72