0

Delete an Existing Droplet

by
Published Dec 20, 2024

To delete a Droplet, send a DELETE request to `/v2/droplets/$DROPLET_ID`. A successful request will receive a 204 status code with no body in response. This indicates that the request was processed successfully.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Delete an Existing Droplet
7
 * To delete a Droplet, send a DELETE request to `/v2/droplets/$DROPLET_ID`.
8

9
A successful request will receive a 204 status code with no body in response.
10
This indicates that the request was processed successfully.
11

12
 */
13
export async function main(auth: Digitalocean, droplet_id: string) {
14
  const url = new URL(`https://api.digitalocean.com/v2/droplets/${droplet_id}`);
15

16
  const response = await fetch(url, {
17
    method: "DELETE",
18
    headers: {
19
      Authorization: "Bearer " + auth.token,
20
    },
21
    body: undefined,
22
  });
23
  if (!response.ok) {
24
    const text = await response.text();
25
    throw new Error(`${response.status} ${text}`);
26
  }
27
  return await response.json();
28
}
29