Get all screen tabs

Returns the list of tabs for a screen. **[Permissions](#permissions) required:** * *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg). * *Administer projects* [project permission](https://confluence.atlassian.com/x/yodKLg) when the project key is specified, providing that the screen is associated with the project through a Screen Scheme and Issue Type Screen Scheme.

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 all screen tabs
8
 * Returns the list of tabs for a screen.
9

10
**[Permissions](#permissions) required:**
11

12
 *  *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
13
 *  *Administer projects* [project permission](https://confluence.atlassian.com/x/yodKLg) when the project key is specified, providing that the screen is associated with the project through a Screen Scheme and Issue Type Screen Scheme.
14
 */
15
export async function main(
16
  auth: Jira,
17
  screenId: string,
18
  projectKey: string | undefined
19
) {
20
  const url = new URL(
21
    `https://${auth.domain}.atlassian.net/rest/api/2/screens/${screenId}/tabs`
22
  );
23
  for (const [k, v] of [["projectKey", projectKey]]) {
24
    if (v !== undefined && v !== "") {
25
      url.searchParams.append(k, v);
26
    }
27
  }
28
  const response = await fetch(url, {
29
    method: "GET",
30
    headers: {
31
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
32
    },
33
    body: undefined,
34
  });
35
  if (!response.ok) {
36
    const text = await response.text();
37
    throw new Error(`${response.status} ${text}`);
38
  }
39
  return await response.json();
40
}
41