Edits history of script submission #11041 for ' Update an Alert (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Update an Alert
     * To update the settings of an Uptime alert, send a PUT request to `/v2/uptime/checks/$CHECK_ID/alerts/$ALERT_ID`.
    
     */
    export async function main(
      auth: Digitalocean,
      check_id: string,
      alert_id: string,
      body: {
        name?: string;
        type?: "latency" | "down" | "down_global" | "ssl_expiry";
        threshold?: number;
        comparison?: "greater_than" | "less_than";
        notifications?: {
          email: string[];
          slack: { channel: string; url: string }[];
        };
        period?: "2m" | "3m" | "5m" | "10m" | "15m" | "30m" | "1h";
      },
    ) {
      const url = new URL(
        `https://api.digitalocean.com/v2/uptime/checks/${check_id}/alerts/${alert_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