0

Create a New Check

by
Published Dec 20, 2024

To create an Uptime check, send a POST request to `/v2/uptime/checks` specifying the attributes in the table below in the JSON body.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Create a New Check
7
 * To create an Uptime check, send a POST request to `/v2/uptime/checks` specifying the attributes
8
in the table below in the JSON body.
9

10
 */
11
export async function main(
12
  auth: Digitalocean,
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(`https://api.digitalocean.com/v2/uptime/checks`);
22

23
  const response = await fetch(url, {
24
    method: "POST",
25
    headers: {
26
      "Content-Type": "application/json",
27
      Authorization: "Bearer " + auth.token,
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