Edits history of script submission #10731 for ' Create a New Check (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Create a New Check
     * To create an Uptime check, send a POST request to `/v2/uptime/checks` specifying the attributes
    in the table below in the JSON body.
    
     */
    export async function main(
      auth: Digitalocean,
      body: {
        name?: string;
        type?: "ping" | "http" | "https";
        target?: string;
        regions?: "us_east" | "us_west" | "eu_west" | "se_asia"[];
        enabled?: false | true;
      },
    ) {
      const url = new URL(`https://api.digitalocean.com/v2/uptime/checks`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 536 days ago