Search resolutions

Returns a [paginated](#pagination) list of resolutions. The list can contain all resolutions or a subset determined by any combination of these criteria: * a list of resolutions IDs. * whether the field configuration is a default. This returns resolutions from company-managed (classic) projects only, as there is no concept of default resolutions in team-managed projects. **[Permissions](#permissions) required:** Permission to access Jira.

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
 * Search resolutions
8
 * Returns a [paginated](#pagination) list of resolutions. The list can contain all resolutions or a subset determined by any combination of these criteria:
9

10
 *  a list of resolutions IDs.
11
 *  whether the field configuration is a default. This returns resolutions from company-managed (classic) projects only, as there is no concept of default resolutions in team-managed projects.
12

13
**[Permissions](#permissions) required:** Permission to access Jira.
14
 */
15
export async function main(
16
  auth: Jira,
17
  startAt: string | undefined,
18
  maxResults: string | undefined,
19
  id: string | undefined,
20
  onlyDefault: string | undefined
21
) {
22
  const url = new URL(
23
    `https://${auth.domain}.atlassian.net/rest/api/2/resolution/search`
24
  );
25
  for (const [k, v] of [
26
    ["startAt", startAt],
27
    ["maxResults", maxResults],
28
    ["id", id],
29
    ["onlyDefault", onlyDefault],
30
  ]) {
31
    if (v !== undefined && v !== "") {
32
      url.searchParams.append(k, v);
33
    }
34
  }
35
  const response = await fetch(url, {
36
    method: "GET",
37
    headers: {
38
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
39
    },
40
    body: undefined,
41
  });
42
  if (!response.ok) {
43
    const text = await response.text();
44
    throw new Error(`${response.status} ${text}`);
45
  }
46
  return await response.json();
47
}
48