Bulk update entity properties

Updates the values of multiple entity properties for an object, up to 50 updates per request. This operation is for use by Connect apps during app migration.

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 update entity properties
8
 * Updates the values of multiple entity properties for an object, up to 50 updates per request. This operation is for use by Connect apps during app migration.
9
 */
10
export async function main(
11
  auth: Jira,
12
  entityType:
13
    | "IssueProperty"
14
    | "CommentProperty"
15
    | "DashboardItemProperty"
16
    | "IssueTypeProperty"
17
    | "ProjectProperty"
18
    | "UserProperty"
19
    | "WorklogProperty"
20
    | "BoardProperty"
21
    | "SprintProperty",
22
  Atlassian_Transfer_Id: string,
23
  body: { entityId: number; key: string; value: string; [k: string]: unknown }[]
24
) {
25
  const url = new URL(
26
    `https://${auth.domain}.atlassian.net/rest/atlassian-connect/1/migration/properties/${entityType}`
27
  );
28

29
  const response = await fetch(url, {
30
    method: "PUT",
31
    headers: {
32
      "Atlassian-Transfer-Id": Atlassian_Transfer_Id,
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.text();
43
}
44