Create version

Creates 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 the version is added to.

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
 * Create version
8
 * Creates 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 the version is added to.
13
 */
14
export async function main(
15
  auth: Jira,
16
  body: {
17
    approvers?: {
18
      accountId?: string;
19
      declineReason?: string;
20
      description?: string;
21
      status?: string;
22
      [k: string]: unknown;
23
    }[];
24
    archived?: boolean;
25
    description?: string;
26
    driver?: string;
27
    expand?: string;
28
    id?: string;
29
    issuesStatusForFixVersion?: {
30
      done?: number;
31
      inProgress?: number;
32
      toDo?: number;
33
      unmapped?: number;
34
      [k: string]: unknown;
35
    };
36
    moveUnfixedIssuesTo?: string;
37
    name?: string;
38
    operations?: {
39
      href?: string;
40
      iconClass?: string;
41
      id?: string;
42
      label?: string;
43
      styleClass?: string;
44
      title?: string;
45
      weight?: number;
46
    }[];
47
    overdue?: boolean;
48
    project?: string;
49
    projectId?: number;
50
    releaseDate?: string;
51
    released?: boolean;
52
    self?: string;
53
    startDate?: string;
54
    userReleaseDate?: string;
55
    userStartDate?: string;
56
  }
57
) {
58
  const url = new URL(
59
    `https://${auth.domain}.atlassian.net/rest/api/2/version`
60
  );
61

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