Update version

Updates a project version. This operation can be accessed anonymously. **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg) or *Administer Projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project that contains the version.

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
 * Update version
8
 * Updates a project version.
9

10
This operation can be accessed anonymously.
11

12
**[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg) or *Administer Projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project that contains the version.
13
 */
14
export async function main(
15
  auth: Jira,
16
  id: string,
17
  body: {
18
    approvers?: {
19
      accountId?: string;
20
      declineReason?: string;
21
      description?: string;
22
      status?: string;
23
      [k: string]: unknown;
24
    }[];
25
    archived?: boolean;
26
    description?: string;
27
    driver?: string;
28
    expand?: string;
29
    id?: string;
30
    issuesStatusForFixVersion?: {
31
      done?: number;
32
      inProgress?: number;
33
      toDo?: number;
34
      unmapped?: number;
35
      [k: string]: unknown;
36
    };
37
    moveUnfixedIssuesTo?: string;
38
    name?: string;
39
    operations?: {
40
      href?: string;
41
      iconClass?: string;
42
      id?: string;
43
      label?: string;
44
      styleClass?: string;
45
      title?: string;
46
      weight?: number;
47
    }[];
48
    overdue?: boolean;
49
    project?: string;
50
    projectId?: number;
51
    releaseDate?: string;
52
    released?: boolean;
53
    self?: string;
54
    startDate?: string;
55
    userReleaseDate?: string;
56
    userStartDate?: string;
57
  }
58
) {
59
  const url = new URL(
60
    `https://${auth.domain}.atlassian.net/rest/api/2/version/${id}`
61
  );
62

63
  const response = await fetch(url, {
64
    method: "PUT",
65
    headers: {
66
      "Content-Type": "application/json",
67
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
68
    },
69
    body: JSON.stringify(body),
70
  });
71
  if (!response.ok) {
72
    const text = await response.text();
73
    throw new Error(`${response.status} ${text}`);
74
  }
75
  return await response.json();
76
}
77