Bulk Delete Triggers

Deletes the triggers corresponding to the provided comma-separated list of IDs. #### Allowed For * Agents #### Request Parameters The DELETE request takes one parameter, an `ids` object that lists the triggers to delete. | Name | Description | ---- | ----------- | ids | The IDs of the triggers to delete #### Example request ```js { "ids": "25,23,27,22" } ```

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
 * Bulk Delete Triggers
8
 * Deletes the triggers corresponding to the provided comma-separated list of IDs.
9

10
#### Allowed For
11

12
* Agents
13

14
#### Request Parameters
15

16
The DELETE request takes one parameter, an `ids` object that lists the
17
triggers to delete.
18

19
| Name | Description
20
| ---- | -----------
21
| ids  | The IDs of the triggers to delete
22

23
#### Example request
24

25
```js
26
{
27
  "ids": "25,23,27,22"
28
}
29
```
30

31
 */
32
export async function main(auth: Zendesk, ids: string | undefined) {
33
  const url = new URL(
34
    `https://${auth.subdomain}.zendesk.com/api/v2/triggers/destroy_many`
35
  );
36
  for (const [k, v] of [["ids", ids]]) {
37
    if (v !== undefined && v !== "") {
38
      url.searchParams.append(k, v);
39
    }
40
  }
41
  const response = await fetch(url, {
42
    method: "DELETE",
43
    headers: {
44
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
45
    },
46
    body: undefined,
47
  });
48
  if (!response.ok) {
49
    const text = await response.text();
50
    throw new Error(`${response.status} ${text}`);
51
  }
52
  return await response.text();
53
}
54