Get all screen tab fields

Returns all fields for a screen tab. **[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 tab fields
8
 * Returns all fields for a screen tab.
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
  tabId: string,
19
  projectKey: string | undefined
20
) {
21
  const url = new URL(
22
    `https://${auth.domain}.atlassian.net/rest/api/2/screens/${screenId}/tabs/${tabId}/fields`
23
  );
24
  for (const [k, v] of [["projectKey", projectKey]]) {
25
    if (v !== undefined && v !== "") {
26
      url.searchParams.append(k, v);
27
    }
28
  }
29
  const response = await fetch(url, {
30
    method: "GET",
31
    headers: {
32
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
33
    },
34
    body: undefined,
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42