0

Retry a Droplet Destroy with Associated Resources Request

by
Published Dec 20, 2024

If the status of a request to destroy a Droplet with its associated resources reported any errors, it can be retried by sending a POST request to the `/v2/droplets/$DROPLET_ID/destroy_with_associated_resources/retry` endpoint. Only one destroy can be active at a time per Droplet. If a retry is issued while another destroy is in progress for the Droplet a 409 status code will be returned. A successful response will include a 202 response code and no content.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Retry a Droplet Destroy with Associated Resources Request
7
 * If the status of a request to destroy a Droplet with its associated resources
8
reported any errors, it can be retried by sending a POST request to the
9
`/v2/droplets/$DROPLET_ID/destroy_with_associated_resources/retry` endpoint.
10

11
Only one destroy can be active at a time per Droplet. If a retry is issued
12
while another destroy is in progress for the Droplet a 409 status code will
13
be returned. A successful response will include a 202 response code and no
14
content.
15

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

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