0

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

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