Search for filters

Returns a [paginated](#pagination) list of filters.

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 for filters
8
 * Returns a [paginated](#pagination) list of filters.
9
 */
10
export async function main(
11
  auth: Jira,
12
  filterName: string | undefined,
13
  accountId: string | undefined,
14
  owner: string | undefined,
15
  groupname: string | undefined,
16
  groupId: string | undefined,
17
  projectId: string | undefined,
18
  id: string | undefined,
19
  orderBy:
20
    | "description"
21
    | "-description"
22
    | "+description"
23
    | "favourite_count"
24
    | "-favourite_count"
25
    | "+favourite_count"
26
    | "id"
27
    | "-id"
28
    | "+id"
29
    | "is_favourite"
30
    | "-is_favourite"
31
    | "+is_favourite"
32
    | "name"
33
    | "-name"
34
    | "+name"
35
    | "owner"
36
    | "-owner"
37
    | "+owner"
38
    | "is_shared"
39
    | "-is_shared"
40
    | "+is_shared"
41
    | undefined,
42
  startAt: string | undefined,
43
  maxResults: string | undefined,
44
  expand: string | undefined,
45
  overrideSharePermissions: string | undefined
46
) {
47
  const url = new URL(
48
    `https://${auth.domain}.atlassian.net/rest/api/2/filter/search`
49
  );
50
  for (const [k, v] of [
51
    ["filterName", filterName],
52
    ["accountId", accountId],
53
    ["owner", owner],
54
    ["groupname", groupname],
55
    ["groupId", groupId],
56
    ["projectId", projectId],
57
    ["id", id],
58
    ["orderBy", orderBy],
59
    ["startAt", startAt],
60
    ["maxResults", maxResults],
61
    ["expand", expand],
62
    ["overrideSharePermissions", overrideSharePermissions],
63
  ]) {
64
    if (v !== undefined && v !== "") {
65
      url.searchParams.append(k, v);
66
    }
67
  }
68
  const response = await fetch(url, {
69
    method: "GET",
70
    headers: {
71
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
72
    },
73
    body: undefined,
74
  });
75
  if (!response.ok) {
76
    const text = await response.text();
77
    throw new Error(`${response.status} ${text}`);
78
  }
79
  return await response.json();
80
}
81