Add filter as favorite

Add a filter as a favorite for the user. **[Permissions](#permissions) required:** Permission to access Jira, however, the user can only favorite: * filters owned by the user. * filters shared with a group that the user is a member of. * filters shared with a private project that the user has *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for. * filters shared with a public project. * filters 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
 * Add filter as favorite
8
 * Add a filter as a favorite for the user.
9

10
**[Permissions](#permissions) required:** Permission to access Jira, however, the user can only favorite:
11

12
 *  filters owned by the user.
13
 *  filters shared with a group that the user is a member of.
14
 *  filters shared with a private project that the user has *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for.
15
 *  filters shared with a public project.
16
 *  filters shared with the public.
17
 */
18
export async function main(auth: Jira, id: string, expand: string | undefined) {
19
  const url = new URL(
20
    `https://${auth.domain}.atlassian.net/rest/api/2/filter/${id}/favourite`
21
  );
22
  for (const [k, v] of [["expand", expand]]) {
23
    if (v !== undefined && v !== "") {
24
      url.searchParams.append(k, v);
25
    }
26
  }
27
  const response = await fetch(url, {
28
    method: "PUT",
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