0
Delete a project for a workspace
One script reply has been approved by the moderators Verified

Deletes this project. This is an irreversible operation.

You cannot delete a project that still contains repositories. To delete the project, delete or transfer the repositories first.

Example:

$ curl -X DELETE https://api.bitbucket.org/2.0/workspaces/bbworkspace1/projects/PROJ
Created by hugo697 197 days ago Viewed 5846 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 197 days ago
1
type Bitbucket = {
2
  username: string;
3
  password: string;
4
};
5
/**
6
 * Delete a project for a workspace
7
 * Deletes this project. This is an irreversible operation.
8

9
You cannot delete a project that still contains repositories.
10
To delete the project, delete
11
or transfer the repositories first.
12

13
Example:
14
```
15
$ curl -X DELETE https://api.bitbucket.org/2.0/workspaces/bbworkspace1/projects/PROJ
16
```
17
 */
18
export async function main(
19
  auth: Bitbucket,
20
  project_key: string,
21
  workspace: string
22
) {
23
  const url = new URL(
24
    `https://api.bitbucket.org/2.0/workspaces/${workspace}/projects/${project_key}`
25
  );
26

27
  const response = await fetch(url, {
28
    method: "DELETE",
29
    headers: {
30
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
31
    },
32
    body: undefined,
33
  });
34
  if (!response.ok) {
35
    const text = await response.text();
36
    throw new Error(`${response.status} ${text}`);
37
  }
38
  return await response.text();
39
}
40