Add notifications to notification scheme

Adds notifications to a notification scheme. You can add up to 1000 notifications per request. *Deprecated: The notification type `EmailAddress` is no longer supported in Cloud. Refer to the [changelog](https://developer.atlassian.com/cloud/jira/platform/changelog/#CHANGE-1031) for more details.* **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).

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 notifications to notification scheme
8
 * Adds notifications to a notification scheme. You can add up to 1000 notifications per request.
9

10
*Deprecated: The notification type `EmailAddress` is no longer supported in Cloud. Refer to the [changelog](https://developer.atlassian.com/cloud/jira/platform/changelog/#CHANGE-1031) for more details.*
11

12
**[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
13
 */
14
export async function main(
15
  auth: Jira,
16
  id: string,
17
  body: {
18
    notificationSchemeEvents: {
19
      event: { id: string; [k: string]: unknown };
20
      notifications: {
21
        notificationType: string;
22
        parameter?: string;
23
        [k: string]: unknown;
24
      }[];
25
      [k: string]: unknown;
26
    }[];
27
    [k: string]: unknown;
28
  }
29
) {
30
  const url = new URL(
31
    `https://${auth.domain}.atlassian.net/rest/api/2/notificationscheme/${id}/notification`
32
  );
33

34
  const response = await fetch(url, {
35
    method: "PUT",
36
    headers: {
37
      "Content-Type": "application/json",
38
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
39
    },
40
    body: JSON.stringify(body),
41
  });
42
  if (!response.ok) {
43
    const text = await response.text();
44
    throw new Error(`${response.status} ${text}`);
45
  }
46
  return await response.json();
47
}
48