Update field configuration items

Updates fields in a field configuration.

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 field configuration items
8
 * Updates fields in a field configuration.
9
 */
10
export async function main(
11
  auth: Jira,
12
  id: string,
13
  body: {
14
    fieldConfigurationItems: {
15
      description?: string;
16
      id: string;
17
      isHidden?: boolean;
18
      isRequired?: boolean;
19
      renderer?: string;
20
    }[];
21
  }
22
) {
23
  const url = new URL(
24
    `https://${auth.domain}.atlassian.net/rest/api/2/fieldconfiguration/${id}/fields`
25
  );
26

27
  const response = await fetch(url, {
28
    method: "PUT",
29
    headers: {
30
      "Content-Type": "application/json",
31
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
32
    },
33
    body: JSON.stringify(body),
34
  });
35
  if (!response.ok) {
36
    const text = await response.text();
37
    throw new Error(`${response.status} ${text}`);
38
  }
39
  return await response.json();
40
}
41