0

List Associated Resources for a Droplet

by
Published Dec 20, 2024

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.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * List Associated Resources for a Droplet
7
 * To list the associated billable resources that can be destroyed along with a
8
Droplet, send a GET request to the
9
`/v2/droplets/$DROPLET_ID/destroy_with_associated_resources` endpoint.
10

11
The response will be a JSON object containing `snapshots`, `volumes`, and
12
`volume_snapshots` keys. Each will be set to an array of objects containing
13
information about the associated resources.
14

15
 */
16
export async function main(auth: Digitalocean, droplet_id: string) {
17
  const url = new URL(
18
    `https://api.digitalocean.com/v2/droplets/${droplet_id}/destroy_with_associated_resources`,
19
  );
20

21
  const response = await fetch(url, {
22
    method: "GET",
23
    headers: {
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