0

Create an Alert

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
 * Create an Alert
7
 *
8
 */
9
export async function main(
10
  auth: Tomorrow,
11
  body: {
12
    name: string;
13
    insight: string;
14
    isActive?: false | true;
15
    notifications?: string;
16
    lightningConfig?: string;
17
  },
18
  Accept_Encoding?: string,
19
) {
20
  const url = new URL(`https://api.tomorrow.io/v4/alerts`);
21

22
  const response = await fetch(url, {
23
    method: "POST",
24
    headers: {
25
      ...(Accept_Encoding ? { "Accept-Encoding": Accept_Encoding } : {}),
26
      "Content-Type": "application/json",
27
      ApiKey: auth.apiKey,
28
    },
29
    body: JSON.stringify(body),
30
  });
31
  if (!response.ok) {
32
    const text = await response.text();
33
    throw new Error(`${response.status} ${text}`);
34
  }
35
  return await response.json();
36
}
37