0
Change filter owner
One script reply has been approved by the moderators Verified

Changes the owner of the filter.

Permissions required: Permission to access Jira. However, the user must own the filter or have the Administer Jira global permission.

Created by hugo697 639 days ago Viewed 22524 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 639 days ago
1
type Jira = {
2
  username: string;
3
  password: string;
4
  domain: string;
5
};
6
/**
7
 * Change filter owner
8
 * Changes the owner of the filter.
9

10
**[Permissions](#permissions) required:** Permission to access Jira. However, the user must own the filter or have the *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
11
 */
12
export async function main(
13
  auth: Jira,
14
  id: string,
15
  body: { accountId: string }
16
) {
17
  const url = new URL(
18
    `https://${auth.domain}.atlassian.net/rest/api/2/filter/${id}/owner`
19
  );
20

21
  const response = await fetch(url, {
22
    method: "PUT",
23
    headers: {
24
      "Content-Type": "application/json",
25
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
26
    },
27
    body: JSON.stringify(body),
28
  });
29
  if (!response.ok) {
30
    const text = await response.text();
31
    throw new Error(`${response.status} ${text}`);
32
  }
33
  return await response.json();
34
}
35