Create Custom Ticket Status

Takes a `custom_status` object that specifies the custom ticket status properties to create. #### Allowed For * Admins

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
 * Create Custom Ticket Status
8
 * Takes a `custom_status` object that specifies the custom ticket status properties to create.
9

10
#### Allowed For
11

12
* Admins
13

14
 */
15
export async function main(
16
  auth: Zendesk,
17
  body: {
18
    custom_status?: {
19
      active?: string;
20
      agent_label?: string;
21
      description?: string;
22
      end_user_description?: string;
23
      end_user_label?: string;
24
      status_category?: string;
25
      [k: string]: unknown;
26
    };
27
    [k: string]: unknown;
28
  }
29
) {
30
  const url = new URL(
31
    `https://${auth.subdomain}.zendesk.com/api/v2/custom_statuses`
32
  );
33

34
  const response = await fetch(url, {
35
    method: "POST",
36
    headers: {
37
      "Content-Type": "application/json",
38
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
39
    },
40
    body: JSON.stringify(body),
41
  });
42
  if (!response.ok) {
43
    const text = await response.text();
44
    throw new Error(`${response.status} ${text}`);
45
  }
46
  return await response.json();
47
}
48