0

Delete Project

by
Published Nov 2, 2023

Delete a project. By default it goes to the Jira recycle bin, where an admin can restore it; set `permanent` to delete it outright. Requires the Administer Jira permission.

Script jira Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 8 days ago
1
//native
2

3
async function get(auth: RT.Jira, path: string) {
4
  const response = await fetch(`https://${auth.domain}.atlassian.net${path}`, {
5
    headers: {
6
      Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
7
      Accept: "application/json",
8
    },
9
  })
10
  if (!response.ok) {
11
    throw new Error(`${response.status} ${await response.text()}`)
12
  }
13
  return await response.json()
14
}
15

16
export type DynSelect_project_id = string
17

18
// Resolver: the site's projects (first 100).
19
export async function project_id(auth: RT.Jira) {
20
  const { values } = await get(
21
    auth,
22
    "/rest/api/3/project/search?maxResults=100"
23
  )
24
  return values.map((p: { id: string; key: string; name: string }) => ({
25
    value: p.id,
26
    label: `${p.name} (${p.key})`,
27
  }))
28
}
29

30
/**
31
 * Delete Project
32
 * Delete a project. By default it goes to the Jira recycle bin, where an admin can restore it; set `permanent` to delete it outright. Requires the Administer Jira permission.
33
 */
34
export async function main(
35
  auth: RT.Jira,
36
  project_id: DynSelect_project_id,
37
  permanent: boolean | undefined
38
) {
39
  const url = new URL(
40
    `https://${auth.domain}.atlassian.net/rest/api/3/project/${project_id}`
41
  )
42

43
  url.searchParams.append("enableUndo", permanent ? "false" : "true")
44

45
  const response = await fetch(url, {
46
    method: "DELETE",
47
    headers: {
48
      Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
49
      Accept: "application/json",
50
    },
51
  })
52

53
  if (!response.ok) {
54
    throw new Error(`${response.status} ${await response.text()}`)
55
  }
56

57
  if (response.status === 204) return { success: true }
58
  return await response.json()
59
}
60

Other submissions
  • Submitted by hugo697 Typescript (fetch-only)
    Created 532 days ago
    1
    type Jira = {
    2
      username: string;
    3
      password: string;
    4
      domain: string;
    5
    };
    6
    /**
    7
     * Delete project
    8
     * Deletes a project.
    9
    
    
    10
    You can't delete a project if it's archived. To delete an archived project, restore the project and then delete it. To restore a project, use the Jira UI.
    11
    
    
    12
    **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
    13
     */
    14
    export async function main(
    15
      auth: Jira,
    16
      projectIdOrKey: string,
    17
      enableUndo: string | undefined
    18
    ) {
    19
      const url = new URL(
    20
        `https://${auth.domain}.atlassian.net/rest/api/2/project/${projectIdOrKey}`
    21
      );
    22
      for (const [k, v] of [["enableUndo", enableUndo]]) {
    23
        if (v !== undefined && v !== "") {
    24
          url.searchParams.append(k, v);
    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