Bulk set issue property

Sets a property value on multiple issues.

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
 * Bulk set issue property
8
 * Sets a property value on multiple issues.
9
 */
10
export async function main(
11
  auth: Jira,
12
  propertyKey: string,
13
  body: {
14
    expression?: string;
15
    filter?: {
16
      currentValue?: { [k: string]: unknown };
17
      entityIds?: number[];
18
      hasProperty?: boolean;
19
    };
20
    value?: { [k: string]: unknown };
21
  }
22
) {
23
  const url = new URL(
24
    `https://${auth.domain}.atlassian.net/rest/api/2/issue/properties/${propertyKey}`
25
  );
26

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