Get accessible project type by key

Returns a [project type](https://confluence.atlassian.com/x/Var1Nw) if it is accessible to the user. **[Permissions](#permissions) required:** Permission to access Jira.

Script jira Verified

by hugo697 ยท 11/2/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 396 days ago
1
type Jira = {
2
  username: string;
3
  password: string;
4
  domain: string;
5
};
6
/**
7
 * Get accessible project type by key
8
 * Returns a [project type](https://confluence.atlassian.com/x/Var1Nw) if it is accessible to the user.
9

10
**[Permissions](#permissions) required:** Permission to access Jira.
11
 */
12
export async function main(
13
  auth: Jira,
14
  projectTypeKey: "software" | "service_desk" | "business" | "product_discovery"
15
) {
16
  const url = new URL(
17
    `https://${auth.domain}.atlassian.net/rest/api/2/project/type/${projectTypeKey}/accessible`
18
  );
19

20
  const response = await fetch(url, {
21
    method: "GET",
22
    headers: {
23
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
24
    },
25
    body: undefined,
26
  });
27
  if (!response.ok) {
28
    const text = await response.text();
29
    throw new Error(`${response.status} ${text}`);
30
  }
31
  return await response.json();
32
}
33