0

Get field configuration schemes for projects

by
Published Nov 2, 2023

Returns a [paginated](#pagination) list of field configuration schemes and, for each scheme, a list of the projects that use it. The list is sorted by field configuration scheme ID. The first item contains the list of project IDs assigned to the default field configuration scheme. Only field configuration schemes used in classic projects are returned. **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).

Script jira Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 416 days ago
1
type Jira = {
2
  username: string;
3
  password: string;
4
  domain: string;
5
};
6
/**
7
 * Get field configuration schemes for projects
8
 * Returns a [paginated](#pagination) list of field configuration schemes and, for each scheme, a list of the projects that use it.
9

10
The list is sorted by field configuration scheme ID. The first item contains the list of project IDs assigned to the default field configuration scheme.
11

12
Only field configuration schemes used in classic projects are returned.
13

14
**[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
15
 */
16
export async function main(
17
  auth: Jira,
18
  startAt: string | undefined,
19
  maxResults: string | undefined,
20
  projectId: string | undefined
21
) {
22
  const url = new URL(
23
    `https://${auth.domain}.atlassian.net/rest/api/2/fieldconfigurationscheme/project`
24
  );
25
  for (const [k, v] of [
26
    ["startAt", startAt],
27
    ["maxResults", maxResults],
28
    ["projectId", projectId],
29
  ]) {
30
    if (v !== undefined && v !== "") {
31
      url.searchParams.append(k, v);
32
    }
33
  }
34
  const response = await fetch(url, {
35
    method: "GET",
36
    headers: {
37
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
38
    },
39
    body: undefined,
40
  });
41
  if (!response.ok) {
42
    const text = await response.text();
43
    throw new Error(`${response.status} ${text}`);
44
  }
45
  return await response.json();
46
}
47