0

Get a Notification

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 a Notification
7
 *
8
 */
9
export async function main(
10
  auth: Trello,
11
  id: string,
12
  board: string | undefined,
13
  board_fields:
14
    | "id"
15
    | "name"
16
    | "desc"
17
    | "descData"
18
    | "closed"
19
    | "idMemberCreator"
20
    | "idOrganization"
21
    | "pinned"
22
    | "url"
23
    | "shortUrl"
24
    | "prefs"
25
    | "labelNames"
26
    | "starred"
27
    | "limits"
28
    | "memberships"
29
    | "enterpriseOwned"
30
    | undefined,
31
  card: string | undefined,
32
  card_fields:
33
    | "id"
34
    | "address"
35
    | "badges"
36
    | "checkItemStates"
37
    | "closed"
38
    | "coordinates"
39
    | "creationMethod"
40
    | "dueComplete"
41
    | "dateLastActivity"
42
    | "desc"
43
    | "descData"
44
    | "due"
45
    | "dueReminder"
46
    | "email"
47
    | "idBoard"
48
    | "idChecklists"
49
    | "idLabels"
50
    | "idList"
51
    | "idMembers"
52
    | "idMembersVoted"
53
    | "idShort"
54
    | "idAttachmentCover"
55
    | "labels"
56
    | "limits"
57
    | "locationName"
58
    | "manualCoverAttachment"
59
    | "name"
60
    | "pos"
61
    | "shortLink"
62
    | "shortUrl"
63
    | "subscribed"
64
    | "url"
65
    | "cover"
66
    | "isTemplate"
67
    | undefined,
68
  display: string | undefined,
69
  entities: string | undefined,
70
  fields:
71
    | "id"
72
    | "unread"
73
    | "type"
74
    | "date"
75
    | "dateRead"
76
    | "data"
77
    | "card"
78
    | "board"
79
    | "idMemberCreator"
80
    | "idAction"
81
    | "reactions"
82
    | undefined,
83
  list: string | undefined,
84
  member: string | undefined,
85
  member_fields: "id" | undefined,
86
  memberCreator: string | undefined,
87
  memberCreator_fields: "id" | undefined,
88
  organization: string | undefined,
89
  organization_fields: "id" | "name" | undefined
90
) {
91
  const url = new URL(`https://api.trello.com/1/notifications/${id}`);
92
  for (const [k, v] of [
93
    ["board", board],
94
    ["board_fields", board_fields],
95
    ["card", card],
96
    ["card_fields", card_fields],
97
    ["display", display],
98
    ["entities", entities],
99
    ["fields", fields],
100
    ["list", list],
101
    ["member", member],
102
    ["member_fields", member_fields],
103
    ["memberCreator", memberCreator],
104
    ["memberCreator_fields", memberCreator_fields],
105
    ["organization", organization],
106
    ["organization_fields", organization_fields],
107
    ["key", auth.key],
108
    ["token", auth.token],
109
  ]) {
110
    if (v !== undefined && v !== "") {
111
      url.searchParams.append(k, v);
112
    }
113
  }
114
  const response = await fetch(url, {
115
    method: "GET",
116
    headers: {
117
      Authorization: undefined,
118
    },
119
    body: undefined,
120
  });
121
  if (!response.ok) {
122
    const text = await response.text();
123
    throw new Error(`${response.status} ${text}`);
124
  }
125
  return await response.json();
126
}
127