Bulk Delete Organizations

Accepts a comma-separated list of up to 100 organization ids or external ids. #### Response This endpoint returns a `job_status` JSON object and queues a background job to do the work. Use the Show Job Status endpoint to check for the job's completion. Only a certain number of jobs can be queued or running at the same time. See Job limit for more information. #### Allowed For * Admins * Agents assigned to a custom role with permissions to manage organizations (Enterprise only)

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 Organizations
8
 * Accepts a comma-separated list of up to 100 organization ids or external ids.
9

10
#### Response
11

12
This endpoint returns a `job_status` JSON object and queues a background job to do the work. Use the Show Job Status endpoint to check for the job's completion. Only a certain number of jobs can be queued or running at the same time. See Job limit for more information.
13

14
#### Allowed For
15

16
* Admins
17
* Agents assigned to a custom role with permissions to manage organizations (Enterprise only)
18

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