List Custom Ticket Statuses

Lists all undeleted custom ticket statuses for the account. No pagination is provided. #### Allowed For * End Users

Script zendesk Verified

by hugo697 ยท 11/7/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 377 days ago
1
type Zendesk = {
2
  username: string;
3
  password: string;
4
  subdomain: string;
5
};
6
/**
7
 * List Custom Ticket Statuses
8
 * Lists all undeleted custom ticket statuses for the account. No pagination is provided.
9

10
#### Allowed For
11

12
* End Users
13

14
 */
15
export async function main(
16
  auth: Zendesk,
17
  status_categories: string | undefined,
18
  active: string | undefined,
19
  _default: string | undefined
20
) {
21
  const url = new URL(
22
    `https://${auth.subdomain}.zendesk.com/api/v2/custom_statuses`
23
  );
24
  for (const [k, v] of [
25
    ["status_categories", status_categories],
26
    ["active", active],
27
    ["default", _default],
28
  ]) {
29
    if (v !== undefined && v !== "") {
30
      url.searchParams.append(k, v);
31
    }
32
  }
33
  const response = await fetch(url, {
34
    method: "GET",
35
    headers: {
36
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
37
    },
38
    body: undefined,
39
  });
40
  if (!response.ok) {
41
    const text = await response.text();
42
    throw new Error(`${response.status} ${text}`);
43
  }
44
  return await response.json();
45
}
46