0

Delete an Existing Project

by
Published Dec 20, 2024

To delete a project, send a DELETE request to `/v2/projects/$PROJECT_ID`. To be deleted, a project must not have any resources assigned to it. Any existing resources must first be reassigned or destroyed, or you will receive a 412 error. 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 Project
7
 * To delete a project, send a DELETE request to `/v2/projects/$PROJECT_ID`. To
8
be deleted, a project must not have any resources assigned to it. Any existing
9
resources must first be reassigned or destroyed, or you will receive a 412 error.
10

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

14
 */
15
export async function main(auth: Digitalocean, project_id: string) {
16
  const url = new URL(`https://api.digitalocean.com/v2/projects/${project_id}`);
17

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