0

Mark all Notifications as read

by
Published Oct 30, 2023

Mark all notifications as read

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
 * Mark all Notifications as read
7
 * Mark all notifications as read
8
 */
9
export async function main(
10
  auth: Trello,
11
  read: string | undefined,
12
  ids: string | undefined
13
) {
14
  const url = new URL(`https://api.trello.com/1/notifications/all/read`);
15
  for (const [k, v] of [
16
    ["read", read],
17
    ["ids", ids],
18
    ["key", auth.key],
19
    ["token", auth.token],
20
  ]) {
21
    if (v !== undefined && v !== "") {
22
      url.searchParams.append(k, v);
23
    }
24
  }
25
  const response = await fetch(url, {
26
    method: "POST",
27
    headers: {
28
      Authorization: undefined,
29
    },
30
    body: undefined,
31
  });
32
  if (!response.ok) {
33
    const text = await response.text();
34
    throw new Error(`${response.status} ${text}`);
35
  }
36
  return await response.json();
37
}
38