Get fields in trash paginated

Returns a [paginated](#pagination) list of fields in the trash. The list may be restricted to fields whose field name or description partially match a string. Only custom fields can be queried, `type` must be set to `custom`. **[Permissions](#permissions) required:** *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
 * Get fields in trash paginated
8
 * Returns a [paginated](#pagination) list of fields in the trash. The list may be restricted to fields whose field name or description partially match a string.
9

10
Only custom fields can be queried, `type` must be set to `custom`.
11

12
**[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
13
 */
14
export async function main(
15
  auth: Jira,
16
  startAt: string | undefined,
17
  maxResults: string | undefined,
18
  id: string | undefined,
19
  query: string | undefined,
20
  expand:
21
    | "name"
22
    | "-name"
23
    | "+name"
24
    | "trashDate"
25
    | "-trashDate"
26
    | "+trashDate"
27
    | "plannedDeletionDate"
28
    | "-plannedDeletionDate"
29
    | "+plannedDeletionDate"
30
    | "projectsCount"
31
    | "-projectsCount"
32
    | "+projectsCount"
33
    | undefined,
34
  orderBy: string | undefined
35
) {
36
  const url = new URL(
37
    `https://${auth.domain}.atlassian.net/rest/api/2/field/search/trashed`
38
  );
39
  for (const [k, v] of [
40
    ["startAt", startAt],
41
    ["maxResults", maxResults],
42
    ["id", id],
43
    ["query", query],
44
    ["expand", expand],
45
    ["orderBy", orderBy],
46
  ]) {
47
    if (v !== undefined && v !== "") {
48
      url.searchParams.append(k, v);
49
    }
50
  }
51
  const response = await fetch(url, {
52
    method: "GET",
53
    headers: {
54
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
55
    },
56
    body: undefined,
57
  });
58
  if (!response.ok) {
59
    const text = await response.text();
60
    throw new Error(`${response.status} ${text}`);
61
  }
62
  return await response.json();
63
}
64