0

Create Organization

by
Published Nov 7, 2023

Create an organization. Names must be unique in the account. Users whose email domain is in `domain_names` can be mapped to it automatically. Set any other field through `fields`, e.g. `{ "organization_fields": { "tier": "gold" }, "group_id": 123 }`.

Script zendesk Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 5 days ago
1
//native
2

3
/**
4
 * Create Organization
5
 * Create an organization. Names must be unique in the account. Users whose email domain is in `domain_names` can be mapped to it automatically. Set any other field through `fields`, e.g. `{ "organization_fields": { "tier": "gold" }, "group_id": 123 }`.
6
 */
7
export async function main(
8
  auth: RT.Zendesk,
9
  name: string,
10
  domain_names: string[] | undefined,
11
  details: string | undefined,
12
  notes: string | undefined,
13
  external_id: string | undefined,
14
  tags: string[] | undefined,
15
  fields: { [key: string]: any } | undefined
16
) {
17
  const organization = {
18
    ...fields,
19
    name: name || undefined,
20
    domain_names: domain_names?.length ? domain_names : undefined,
21
    details: details || undefined,
22
    notes: notes || undefined,
23
    external_id: external_id || undefined,
24
    tags: tags?.length ? tags : undefined,
25
  }
26

27
  const response = await fetch(
28
    `https://${auth.subdomain}.zendesk.com/api/v2/organizations`,
29
    {
30
      method: "POST",
31
      headers: {
32
        Authorization: auth.token
33
          ? `Bearer ${auth.token}`
34
          : `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
35
        "Content-Type": "application/json",
36
        Accept: "application/json",
37
      },
38
      body: JSON.stringify({ organization }),
39
    }
40
  )
41

42
  if (!response.ok) {
43
    throw new Error(`${response.status} ${await response.text()}`)
44
  }
45

46
  return await response.json()
47
}
48

Other submissions
  • Submitted by hugo697 Typescript (fetch-only)
    Created 533 days ago
    1
    type Zendesk = {
    2
      username: string;
    3
      password: string;
    4
      subdomain: string;
    5
    };
    6
    /**
    7
     * Create Organization
    8
     * You must provide a unique `name` for each organization. Normally
    9
    the system doesn't allow records to be created with identical names.
    10
    However, a race condition can occur if you make two or more identical
    11
    POSTs very close to each other, causing the records to have identical
    12
    organization names.
    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(auth: Zendesk) {
    21
      const url = new URL(
    22
        `https://${auth.subdomain}.zendesk.com/api/v2/organizations`
    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