Get worklogs

Returns worklog details for a list of worklog IDs. The returned list of worklogs is limited to 1000 items. **[Permissions](#permissions) required:** Permission to access Jira, however, worklogs are only returned where either of the following is true: * the worklog is set as *Viewable by All Users*. * the user is a member of a project role or group with permission to view the worklog.

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 worklogs
8
 * Returns worklog details for a list of worklog IDs.
9

10
The returned list of worklogs is limited to 1000 items.
11

12
**[Permissions](#permissions) required:** Permission to access Jira, however, worklogs are only returned where either of the following is true:
13

14
 *  the worklog is set as *Viewable by All Users*.
15
 *  the user is a member of a project role or group with permission to view the worklog.
16
 */
17
export async function main(
18
  auth: Jira,
19
  expand: string | undefined,
20
  body: { ids: number[] }
21
) {
22
  const url = new URL(
23
    `https://${auth.domain}.atlassian.net/rest/api/2/worklog/list`
24
  );
25
  for (const [k, v] of [["expand", expand]]) {
26
    if (v !== undefined && v !== "") {
27
      url.searchParams.append(k, v);
28
    }
29
  }
30
  const response = await fetch(url, {
31
    method: "POST",
32
    headers: {
33
      "Content-Type": "application/json",
34
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
35
    },
36
    body: JSON.stringify(body),
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.json();
43
}
44