Register modules

Registers a list of modules. **[Permissions](#permissions) required:** Only Connect apps can make this request.

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
 * Register modules
8
 * Registers a list of modules.
9

10
**[Permissions](#permissions) required:** Only Connect apps can make this request.
11
 */
12
export async function main(
13
  auth: Jira,
14
  body: { modules: { [k: string]: unknown }[]; [k: string]: unknown }
15
) {
16
  const url = new URL(
17
    `https://${auth.domain}.atlassian.net/rest/atlassian-connect/1/app/module/dynamic`
18
  );
19

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