Get custom field contexts default values

Returns a [paginated](#pagination) list of defaults for a custom 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 custom field contexts default values
8
 * Returns a [paginated](#pagination) list of defaults for a custom field.
9
 */
10
export async function main(
11
  auth: Jira,
12
  fieldId: string,
13
  contextId: string | undefined,
14
  startAt: string | undefined,
15
  maxResults: string | undefined
16
) {
17
  const url = new URL(
18
    `https://${auth.domain}.atlassian.net/rest/api/2/field/${fieldId}/context/defaultValue`
19
  );
20
  for (const [k, v] of [
21
    ["contextId", contextId],
22
    ["startAt", startAt],
23
    ["maxResults", maxResults],
24
  ]) {
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