0

Get edit issue metadata

by
Published Nov 2, 2023

Returns the edit screen fields for an issue that are visible to and editable by the user.

Script jira Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 416 days ago
1
type Jira = {
2
  username: string;
3
  password: string;
4
  domain: string;
5
};
6
/**
7
 * Get edit issue metadata
8
 * Returns the edit screen fields for an issue that are visible to and editable by the user.
9
 */
10
export async function main(
11
  auth: Jira,
12
  issueIdOrKey: string,
13
  overrideScreenSecurity: string | undefined,
14
  overrideEditableFlag: string | undefined
15
) {
16
  const url = new URL(
17
    `https://${auth.domain}.atlassian.net/rest/api/2/issue/${issueIdOrKey}/editmeta`
18
  );
19
  for (const [k, v] of [
20
    ["overrideScreenSecurity", overrideScreenSecurity],
21
    ["overrideEditableFlag", overrideEditableFlag],
22
  ]) {
23
    if (v !== undefined && v !== "") {
24
      url.searchParams.append(k, v);
25
    }
26
  }
27
  const response = await fetch(url, {
28
    method: "GET",
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.json();
39
}
40