Edits history of script submission #10790 for ' Destroy a Droplet and All of its Associated Resources (Dangerous) (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Destroy a Droplet and All of its Associated Resources (Dangerous)
     * To destroy a Droplet along with all of its associated resources, send a DELETE
    request to the `/v2/droplets/$DROPLET_ID/destroy_with_associated_resources/dangerous`
    endpoint.
     */
    export async function main(
      auth: Digitalocean,
      droplet_id: string,
      X_Dangerous: string,
    ) {
      const url = new URL(
        `https://api.digitalocean.com/v2/droplets/${droplet_id}/destroy_with_associated_resources/dangerous`,
      );
    
      const response = await fetch(url, {
        method: "DELETE",
        headers: {
          "X-Dangerous": X_Dangerous,
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 536 days ago