Delete Ticket

#### Allowed For * Admins * Agents with permission to delete tickets Agent delete permissions are set in Support.

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
 * Delete Ticket
8
 * #### Allowed For
9

10
* Admins
11
* Agents with permission to delete tickets
12

13
Agent delete permissions are set in Support.
14
 */
15
export async function main(auth: Zendesk, ticket_id: string) {
16
  const url = new URL(
17
    `https://${auth.subdomain}.zendesk.com/api/v2/tickets/${ticket_id}`
18
  );
19

20
  const response = await fetch(url, {
21
    method: "DELETE",
22
    headers: {
23
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
24
    },
25
    body: undefined,
26
  });
27
  if (!response.ok) {
28
    const text = await response.text();
29
    throw new Error(`${response.status} ${text}`);
30
  }
31
  return await response.text();
32
}
33