Update component

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

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