0

List Notifications

by
Published Oct 17, 2025
Script tomorrow Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Tomorrow = {
3
  apiKey: string;
4
};
5
/**
6
 * List Notifications
7
 *
8
 */
9
export async function main(
10
  auth: Tomorrow,
11
  startTime: string | undefined,
12
  endTime: string | undefined,
13
  alertIds: string | undefined,
14
  notificationTypes: string | undefined,
15
  recipients: string | undefined,
16
  status: string | undefined,
17
  locationIds: string | undefined,
18
  Accept_Encoding?: string,
19
) {
20
  const url = new URL(`https://api.tomorrow.io/v4/notifications`);
21
  for (const [k, v] of [
22
    ["startTime", startTime],
23
    ["endTime", endTime],
24
    ["alertIds", alertIds],
25
    ["notificationTypes", notificationTypes],
26
    ["recipients", recipients],
27
    ["status", status],
28
    ["locationIds", locationIds],
29
  ]) {
30
    if (v !== undefined && v !== "" && k !== undefined) {
31
      url.searchParams.append(k, v);
32
    }
33
  }
34
  const response = await fetch(url, {
35
    method: "GET",
36
    headers: {
37
      ...(Accept_Encoding ? { "Accept-Encoding": Accept_Encoding } : {}),
38
      ApiKey: auth.apiKey,
39
    },
40
    body: undefined,
41
  });
42
  if (!response.ok) {
43
    const text = await response.text();
44
    throw new Error(`${response.status} ${text}`);
45
  }
46
  return await response.json();
47
}
48