Bulk Delete Automations

Deletes the automations corresponding to the provided comma-separated list of IDs.

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 Automations
8
 * Deletes the automations corresponding to the provided comma-separated list of IDs.
9
 */
10
export async function main(auth: Zendesk, ids: string | undefined) {
11
  const url = new URL(
12
    `https://${auth.subdomain}.zendesk.com/api/v2/automations/destroy_many`
13
  );
14
  for (const [k, v] of [["ids", ids]]) {
15
    if (v !== undefined && v !== "") {
16
      url.searchParams.append(k, v);
17
    }
18
  }
19
  const response = await fetch(url, {
20
    method: "DELETE",
21
    headers: {
22
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
23
    },
24
    body: undefined,
25
  });
26
  if (!response.ok) {
27
    const text = await response.text();
28
    throw new Error(`${response.status} ${text}`);
29
  }
30
  return await response.text();
31
}
32