0

Update a Check

by
Published Dec 20, 2024

To update the settings of an Uptime check, send a PUT request to `/v2/uptime/checks/$CHECK_ID`.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Update a Check
7
 * To update the settings of an Uptime check, send a PUT request to `/v2/uptime/checks/$CHECK_ID`.
8

9
 */
10
export async function main(
11
  auth: Digitalocean,
12
  check_id: string,
13
  body: {
14
    name?: string;
15
    type?: "ping" | "http" | "https";
16
    target?: string;
17
    regions?: "us_east" | "us_west" | "eu_west" | "se_asia"[];
18
    enabled?: false | true;
19
  },
20
) {
21
  const url = new URL(
22
    `https://api.digitalocean.com/v2/uptime/checks/${check_id}`,
23
  );
24

25
  const response = await fetch(url, {
26
    method: "PUT",
27
    headers: {
28
      "Content-Type": "application/json",
29
      Authorization: "Bearer " + auth.token,
30
    },
31
    body: JSON.stringify(body),
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39