Find components for projects

Returns a [paginated](#pagination) list of all components in a project, including global (Compass) components when applicable. This operation can be accessed anonymously. **[Permissions](#permissions) required:** *Browse Projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project.

Script jira Verified

by hugo697 ยท 3/6/2024

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
 * Find components for projects
8
 * Returns a [paginated](#pagination) list of all components in a project, including global (Compass) components when applicable.
9

10
This operation can be accessed anonymously.
11

12
**[Permissions](#permissions) required:** *Browse Projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project.
13
 */
14
export async function main(
15
  auth: Jira,
16
  projectIdsOrKeys: string | undefined,
17
  startAt: string | undefined,
18
  maxResults: string | undefined,
19
  orderBy:
20
    | "description"
21
    | "-description"
22
    | "+description"
23
    | "name"
24
    | "-name"
25
    | "+name"
26
    | undefined,
27
  query: string | undefined
28
) {
29
  const url = new URL(
30
    `https://${auth.domain}.atlassian.net/rest/api/2/component`
31
  );
32
  for (const [k, v] of [
33
    ["projectIdsOrKeys", projectIdsOrKeys],
34
    ["startAt", startAt],
35
    ["maxResults", maxResults],
36
    ["orderBy", orderBy],
37
    ["query", query],
38
  ]) {
39
    if (v !== undefined && v !== "") {
40
      url.searchParams.append(k, v);
41
    }
42
  }
43
  const response = await fetch(url, {
44
    method: "GET",
45
    headers: {
46
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
47
    },
48
    body: undefined,
49
  });
50
  if (!response.ok) {
51
    const text = await response.text();
52
    throw new Error(`${response.status} ${text}`);
53
  }
54
  return await response.json();
55
}
56