0
Delete Multiple Suspended Tickets
One script reply has been approved by the moderators Verified

Accepts up to 100 ids (the auto-generated id, not the ticket id.)

Allowed For

Created by hugo697 581 days ago Viewed 22417 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 581 days ago
1
type Zendesk = {
2
  username: string;
3
  password: string;
4
  subdomain: string;
5
};
6
/**
7
 * Delete Multiple Suspended Tickets
8
 * Accepts up to 100 ids (the auto-generated id, not the ticket id.)
9

10
#### Allowed For
11

12
* Admins and [agents in custom roles with permission](https://support.zendesk.com/hc/en-us/articles/4408882153882#topic_cxn_hig_bd) to manage suspended tickets on Enterprise plans
13
* Unrestricted agents on all other plans
14

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