Create component

Creates a component. Use components to provide containers for issues within a project. Use components to provide containers for issues within a project. This operation can be accessed anonymously. **[Permissions](#permissions) required:** *Administer projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project in which the component is created or *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).

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 component
8
 * Creates a component. Use components to provide containers for issues within a project. Use components to provide containers for issues within a project.
9

10
This operation can be accessed anonymously.
11

12
**[Permissions](#permissions) required:** *Administer projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project in which the component is created or *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
13
 */
14
export async function main(
15
  auth: Jira,
16
  body: {
17
    ari?: string;
18
    assignee?: {
19
      accountId?: string;
20
      accountType?: "atlassian" | "app" | "customer" | "unknown";
21
      active?: boolean;
22
      applicationRoles?: {
23
        callback?: {};
24
        items?: {
25
          defaultGroups?: string[];
26
          defaultGroupsDetails?: {
27
            groupId?: string;
28
            name?: string;
29
            self?: string;
30
          }[];
31
          defined?: boolean;
32
          groupDetails?: { groupId?: string; name?: string; self?: string }[];
33
          groups?: string[];
34
          hasUnlimitedSeats?: boolean;
35
          key?: string;
36
          name?: string;
37
          numberOfSeats?: number;
38
          platform?: boolean;
39
          remainingSeats?: number;
40
          selectedByDefault?: boolean;
41
          userCount?: number;
42
          userCountDescription?: string;
43
        }[];
44
        "max-results"?: number;
45
        pagingCallback?: {};
46
        size?: number;
47
      };
48
      avatarUrls?: {
49
        "16x16"?: string;
50
        "24x24"?: string;
51
        "32x32"?: string;
52
        "48x48"?: string;
53
      };
54
      displayName?: string;
55
      emailAddress?: string;
56
      expand?: string;
57
      groups?: {
58
        callback?: {};
59
        items?: { groupId?: string; name?: string; self?: string }[];
60
        "max-results"?: number;
61
        pagingCallback?: {};
62
        size?: number;
63
      };
64
      key?: string;
65
      locale?: string;
66
      name?: string;
67
      self?: string;
68
      timeZone?: string;
69
    };
70
    assigneeType?:
71
      | "PROJECT_DEFAULT"
72
      | "COMPONENT_LEAD"
73
      | "PROJECT_LEAD"
74
      | "UNASSIGNED";
75
    description?: string;
76
    id?: string;
77
    isAssigneeTypeValid?: boolean;
78
    lead?: {
79
      accountId?: string;
80
      accountType?: "atlassian" | "app" | "customer" | "unknown";
81
      active?: boolean;
82
      applicationRoles?: {
83
        callback?: {};
84
        items?: {
85
          defaultGroups?: string[];
86
          defaultGroupsDetails?: {
87
            groupId?: string;
88
            name?: string;
89
            self?: string;
90
          }[];
91
          defined?: boolean;
92
          groupDetails?: { groupId?: string; name?: string; self?: string }[];
93
          groups?: string[];
94
          hasUnlimitedSeats?: boolean;
95
          key?: string;
96
          name?: string;
97
          numberOfSeats?: number;
98
          platform?: boolean;
99
          remainingSeats?: number;
100
          selectedByDefault?: boolean;
101
          userCount?: number;
102
          userCountDescription?: string;
103
        }[];
104
        "max-results"?: number;
105
        pagingCallback?: {};
106
        size?: number;
107
      };
108
      avatarUrls?: {
109
        "16x16"?: string;
110
        "24x24"?: string;
111
        "32x32"?: string;
112
        "48x48"?: string;
113
      };
114
      displayName?: string;
115
      emailAddress?: string;
116
      expand?: string;
117
      groups?: {
118
        callback?: {};
119
        items?: { groupId?: string; name?: string; self?: string }[];
120
        "max-results"?: number;
121
        pagingCallback?: {};
122
        size?: number;
123
      };
124
      key?: string;
125
      locale?: string;
126
      name?: string;
127
      self?: string;
128
      timeZone?: string;
129
    };
130
    leadAccountId?: string;
131
    leadUserName?: string;
132
    metadata?: { [k: string]: string };
133
    name?: string;
134
    project?: string;
135
    projectId?: number;
136
    realAssignee?: {
137
      accountId?: string;
138
      accountType?: "atlassian" | "app" | "customer" | "unknown";
139
      active?: boolean;
140
      applicationRoles?: {
141
        callback?: {};
142
        items?: {
143
          defaultGroups?: string[];
144
          defaultGroupsDetails?: {
145
            groupId?: string;
146
            name?: string;
147
            self?: string;
148
          }[];
149
          defined?: boolean;
150
          groupDetails?: { groupId?: string; name?: string; self?: string }[];
151
          groups?: string[];
152
          hasUnlimitedSeats?: boolean;
153
          key?: string;
154
          name?: string;
155
          numberOfSeats?: number;
156
          platform?: boolean;
157
          remainingSeats?: number;
158
          selectedByDefault?: boolean;
159
          userCount?: number;
160
          userCountDescription?: string;
161
        }[];
162
        "max-results"?: number;
163
        pagingCallback?: {};
164
        size?: number;
165
      };
166
      avatarUrls?: {
167
        "16x16"?: string;
168
        "24x24"?: string;
169
        "32x32"?: string;
170
        "48x48"?: string;
171
      };
172
      displayName?: string;
173
      emailAddress?: string;
174
      expand?: string;
175
      groups?: {
176
        callback?: {};
177
        items?: { groupId?: string; name?: string; self?: string }[];
178
        "max-results"?: number;
179
        pagingCallback?: {};
180
        size?: number;
181
      };
182
      key?: string;
183
      locale?: string;
184
      name?: string;
185
      self?: string;
186
      timeZone?: string;
187
    };
188
    realAssigneeType?:
189
      | "PROJECT_DEFAULT"
190
      | "COMPONENT_LEAD"
191
      | "PROJECT_LEAD"
192
      | "UNASSIGNED";
193
    self?: string;
194
  }
195
) {
196
  const url = new URL(
197
    `https://${auth.domain}.atlassian.net/rest/api/2/component`
198
  );
199

200
  const response = await fetch(url, {
201
    method: "POST",
202
    headers: {
203
      "Content-Type": "application/json",
204
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
205
    },
206
    body: JSON.stringify(body),
207
  });
208
  if (!response.ok) {
209
    const text = await response.text();
210
    throw new Error(`${response.status} ${text}`);
211
  }
212
  return await response.json();
213
}
214