Get project versions paginated

Returns a [paginated](#pagination) list of all versions in a project. See the [Get project versions](#api-rest-api-2-project-projectIdOrKey-versions-get) resource if you want to get a full list of versions without pagination. 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 ยท 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
 * Get project versions paginated
8
 * Returns a [paginated](#pagination) list of all versions in a project. See the [Get project versions](#api-rest-api-2-project-projectIdOrKey-versions-get) resource if you want to get a full list of versions without pagination.
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
  projectIdOrKey: string,
17
  startAt: string | undefined,
18
  maxResults: string | undefined,
19
  orderBy:
20
    | "description"
21
    | "-description"
22
    | "+description"
23
    | "name"
24
    | "-name"
25
    | "+name"
26
    | "releaseDate"
27
    | "-releaseDate"
28
    | "+releaseDate"
29
    | "sequence"
30
    | "-sequence"
31
    | "+sequence"
32
    | "startDate"
33
    | "-startDate"
34
    | "+startDate"
35
    | undefined,
36
  query: string | undefined,
37
  status: string | undefined,
38
  expand: string | undefined
39
) {
40
  const url = new URL(
41
    `https://${auth.domain}.atlassian.net/rest/api/2/project/${projectIdOrKey}/version`
42
  );
43
  for (const [k, v] of [
44
    ["startAt", startAt],
45
    ["maxResults", maxResults],
46
    ["orderBy", orderBy],
47
    ["query", query],
48
    ["status", status],
49
    ["expand", expand],
50
  ]) {
51
    if (v !== undefined && v !== "") {
52
      url.searchParams.append(k, v);
53
    }
54
  }
55
  const response = await fetch(url, {
56
    method: "GET",
57
    headers: {
58
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
59
    },
60
    body: undefined,
61
  });
62
  if (!response.ok) {
63
    const text = await response.text();
64
    throw new Error(`${response.status} ${text}`);
65
  }
66
  return await response.json();
67
}
68