Set worklog property

Sets the value of a worklog property.

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
 * Set worklog property
8
 * Sets the value of a worklog property.
9
 */
10
export async function main(
11
  auth: Jira,
12
  issueIdOrKey: string,
13
  worklogId: string,
14
  propertyKey: string,
15
  body: { [k: string]: unknown }
16
) {
17
  const url = new URL(
18
    `https://${auth.domain}.atlassian.net/rest/api/2/issue/${issueIdOrKey}/worklog/${worklogId}/properties/${propertyKey}`
19
  );
20

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