0

Destroy a Droplet and All of its Associated Resources (Dangerous)

by
Published Dec 20, 2024

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.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Destroy a Droplet and All of its Associated Resources (Dangerous)
7
 * To destroy a Droplet along with all of its associated resources, send a DELETE
8
request to the `/v2/droplets/$DROPLET_ID/destroy_with_associated_resources/dangerous`
9
endpoint.
10
 */
11
export async function main(
12
  auth: Digitalocean,
13
  droplet_id: string,
14
  X_Dangerous: string,
15
) {
16
  const url = new URL(
17
    `https://api.digitalocean.com/v2/droplets/${droplet_id}/destroy_with_associated_resources/dangerous`,
18
  );
19

20
  const response = await fetch(url, {
21
    method: "DELETE",
22
    headers: {
23
      "X-Dangerous": X_Dangerous,
24
      Authorization: "Bearer " + auth.token,
25
    },
26
    body: undefined,
27
  });
28
  if (!response.ok) {
29
    const text = await response.text();
30
    throw new Error(`${response.status} ${text}`);
31
  }
32
  return await response.json();
33
}
34