Create Or Update Organization

Creates an organization if it doesn't already exist, or updates an existing organization. Using this method means one less call to check if an organization exists before creating it. You need to specify the id or external id when updating an organization to avoid a duplicate error response. Name is not available as a matching criteria. #### Allowed For * Agents, with restrictions on certain actions

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
 * Create Or Update Organization
8
 * Creates an organization if it doesn't already exist, or updates
9
an existing organization. Using this method means one less call
10
to check if an organization exists before creating it. You need
11
to specify the id or external id when updating
12
an organization to avoid a duplicate error response. Name is
13
not available as a matching criteria.
14

15
#### Allowed For
16

17
* Agents, with restrictions on certain actions
18

19
 */
20
export async function main(auth: Zendesk) {
21
  const url = new URL(
22
    `https://${auth.subdomain}.zendesk.com/api/v2/organizations/create_or_update`
23
  );
24

25
  const response = await fetch(url, {
26
    method: "POST",
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.json();
37
}
38