Get all issue field options

Returns a [paginated](#pagination) list of all the options of a select list issue field.

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 issue field options
8
 * Returns a [paginated](#pagination) list of all the options of a select list issue field.
9
 */
10
export async function main(
11
  auth: Jira,
12
  fieldKey: string,
13
  startAt: string | undefined,
14
  maxResults: string | undefined
15
) {
16
  const url = new URL(
17
    `https://${auth.domain}.atlassian.net/rest/api/2/field/${fieldKey}/option`
18
  );
19
  for (const [k, v] of [
20
    ["startAt", startAt],
21
    ["maxResults", maxResults],
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