Get changelogs
One script reply has been approved by the moderators Verified

Returns a paginated list of all changelogs for an issue sorted by date, starting from the oldest.

This operation can be accessed anonymously.

Permissions required:

Created by hugo697 879 days ago Picked 2 times
Submitted by hugo697 Typescript (fetch-only)
Verified 327 days ago
1
type Jira = {
2
  username: string;
3
  password: string;
4
  domain: string;
5
};
6
/**
7
 * Get changelogs
8
 * Returns a [paginated](#pagination) list of all changelogs for an issue sorted by date, starting from the oldest.
9

10
This operation can be accessed anonymously.
11

12
**[Permissions](#permissions) required:**
13

14
 *  *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project that the issue is in.
15
 *  If [issue-level security](https://confluence.atlassian.com/x/J4lKLg) is configured, issue-level security permission to view the issue.
16
 */
17
export async function main(
18
  auth: Jira,
19
  issueIdOrKey: string,
20
  startAt: string | undefined,
21
  maxResults: string | undefined
22
) {
23
  const url = new URL(
24
    `https://${auth.domain}.atlassian.net/rest/api/2/issue/${issueIdOrKey}/changelog`
25
  );
26
  for (const [k, v] of [
27
    ["startAt", startAt],
28
    ["maxResults", maxResults],
29
  ]) {
30
    if (v !== undefined && v !== "") {
31
      url.searchParams.append(k, v);
32
    }
33
  }
34
  const response = await fetch(url, {
35
    method: "GET",
36
    headers: {
37
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
38
    },
39
    body: undefined,
40
  });
41
  if (!response.ok) {
42
    const text = await response.text();
43
    throw new Error(`${response.status} ${text}`);
44
  }
45
  return await response.json();
46
}
47