0

Delete Ticket

by
Published Nov 7, 2023

Delete a ticket. It moves to Deleted tickets and can be restored for 30 days before it is purged.

Script zendesk Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 5 days ago
1
//native
2

3
/**
4
 * Delete Ticket
5
 * Delete a ticket. It moves to Deleted tickets and can be restored for 30 days before it is purged.
6
 */
7
export async function main(auth: RT.Zendesk, ticket_id: number) {
8
  const response = await fetch(
9
    `https://${auth.subdomain}.zendesk.com/api/v2/tickets/${ticket_id}`,
10
    {
11
      method: "DELETE",
12
      headers: {
13
        Authorization: auth.token
14
          ? `Bearer ${auth.token}`
15
          : `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
16
        Accept: "application/json",
17
      },
18
    }
19
  )
20

21
  if (!response.ok) {
22
    throw new Error(`${response.status} ${await response.text()}`)
23
  }
24

25
  return { success: true }
26
}
27

Other submissions
  • Submitted by hugo697 Typescript (fetch-only)
    Created 533 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