Edits history of script submission #10898 for ' List Associated Resources for a Droplet (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * List Associated Resources for a Droplet
     * To list the associated billable resources that can be destroyed along with a
    Droplet, send a GET request to the
    `/v2/droplets/$DROPLET_ID/destroy_with_associated_resources` endpoint.
    
    The response will be a JSON object containing `snapshots`, `volumes`, and
    `volume_snapshots` keys. Each will be set to an array of objects containing
    information about the associated resources.
    
     */
    export async function main(auth: Digitalocean, droplet_id: string) {
      const url = new URL(
        `https://api.digitalocean.com/v2/droplets/${droplet_id}/destroy_with_associated_resources`,
      );
    
      const response = await fetch(url, {
        method: "GET",
        headers: {
          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