Get filter

Returns a filter. This operation can be accessed anonymously. **[Permissions](#permissions) required:** None, however, the filter is only returned where it is: * owned by the user. * shared with a group that the user is a member of. * shared with a private project that the user has *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for. * shared with a public project. * shared with the public.

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 filter
8
 * Returns a filter.
9

10
This operation can be accessed anonymously.
11

12
**[Permissions](#permissions) required:** None, however, the filter is only returned where it is:
13

14
 *  owned by the user.
15
 *  shared with a group that the user is a member of.
16
 *  shared with a private project that the user has *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for.
17
 *  shared with a public project.
18
 *  shared with the public.
19
 */
20
export async function main(
21
  auth: Jira,
22
  id: string,
23
  expand: string | undefined,
24
  overrideSharePermissions: string | undefined
25
) {
26
  const url = new URL(
27
    `https://${auth.domain}.atlassian.net/rest/api/2/filter/${id}`
28
  );
29
  for (const [k, v] of [
30
    ["expand", expand],
31
    ["overrideSharePermissions", overrideSharePermissions],
32
  ]) {
33
    if (v !== undefined && v !== "") {
34
      url.searchParams.append(k, v);
35
    }
36
  }
37
  const response = await fetch(url, {
38
    method: "GET",
39
    headers: {
40
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
41
    },
42
    body: undefined,
43
  });
44
  if (!response.ok) {
45
    const text = await response.text();
46
    throw new Error(`${response.status} ${text}`);
47
  }
48
  return await response.json();
49
}
50