0

Get notification scheme

by
Published Nov 2, 2023

Returns a [notification scheme](https://confluence.atlassian.com/x/8YdKLg), including the list of events and the recipients who will receive notifications for those events. **[Permissions](#permissions) required:** Permission to access Jira, however, the user must have permission to administer at least one project associated with the notification scheme.

Script jira Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 416 days ago
1
type Jira = {
2
  username: string;
3
  password: string;
4
  domain: string;
5
};
6
/**
7
 * Get notification scheme
8
 * Returns a [notification scheme](https://confluence.atlassian.com/x/8YdKLg), including the list of events and the recipients who will receive notifications for those events.
9

10
**[Permissions](#permissions) required:** Permission to access Jira, however, the user must have permission to administer at least one project associated with the notification scheme.
11
 */
12
export async function main(auth: Jira, id: string, expand: string | undefined) {
13
  const url = new URL(
14
    `https://${auth.domain}.atlassian.net/rest/api/2/notificationscheme/${id}`
15
  );
16
  for (const [k, v] of [["expand", expand]]) {
17
    if (v !== undefined && v !== "") {
18
      url.searchParams.append(k, v);
19
    }
20
  }
21
  const response = await fetch(url, {
22
    method: "GET",
23
    headers: {
24
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
25
    },
26
    body: undefined,
27
  });
28
  if (!response.ok) {
29
    const text = await response.text();
30
    throw new Error(`${response.status} ${text}`);
31
  }
32
  return await response.json();
33
}
34