Edits history of script submission #11031 for ' Update a Check (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Update a Check
     * To update the settings of an Uptime check, send a PUT request to `/v2/uptime/checks/$CHECK_ID`.
    
     */
    export async function main(
      auth: Digitalocean,
      check_id: string,
      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/${check_id}`,
      );
    
      const response = await fetch(url, {
        method: "PUT",
        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