Edits history of script submission #11019 for ' Untag a Resource (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Untag a Resource
     * Resources can be untagged by sending a DELETE request to `/v2/tags/$TAG_NAME/resources` with an array of json objects containing `resource_id` and `resource_type` attributes.
    Currently only untagging of Droplets, Databases, Images, Volumes, and Volume Snapshots is supported. `resource_type` is expected to be the string `droplet`, `database`, `image`, `volume` or `volume_snapshot`. `resource_id` is expected to be the ID of the resource as a string.
     */
    export async function main(
      auth: Digitalocean,
      tag_id: string,
      body: {
        resources: {
          resource_id?: string;
          resource_type?: "droplet" | "image" | "volume" | "volume_snapshot";
        }[];
      },
    ) {
      const url = new URL(
        `https://api.digitalocean.com/v2/tags/${tag_id}/resources`,
      );
    
      const response = await fetch(url, {
        method: "DELETE",
        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