0

Update Organization

by
Published Nov 7, 2023

Update an organization by id; only the fields you fill are changed. `domain_names` and `tags` replace the existing lists. Set any other field through `fields`, e.g. `{ "organization_fields": { "tier": "gold" } }`.

Script zendesk Verified

The script

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

3
/**
4
 * Update Organization
5
 * Update an organization by id; only the fields you fill are changed. `domain_names` and `tags` replace the existing lists. Set any other field through `fields`, e.g. `{ "organization_fields": { "tier": "gold" } }`.
6
 */
7
export async function main(
8
  auth: RT.Zendesk,
9
  organization_id: number,
10
  name: string | undefined,
11
  domain_names: string[] | undefined,
12
  details: string | undefined,
13
  notes: string | undefined,
14
  external_id: string | undefined,
15
  tags: string[] | undefined,
16
  fields: { [key: string]: any } | undefined
17
) {
18
  const organization = {
19
    ...fields,
20
    name: name || undefined,
21
    domain_names: domain_names?.length ? domain_names : undefined,
22
    details: details || undefined,
23
    notes: notes || undefined,
24
    external_id: external_id || undefined,
25
    tags: tags?.length ? tags : undefined,
26
  }
27

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

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

47
  return await response.json()
48
}
49

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
     * Update Organization
    8
     * #### Allowed For
    9
    
    
    10
    * Admins
    11
    * Agents
    12
    
    
    13
    Agents with no permissions restrictions can only update "notes" on organizations.
    14
    
    
    15
    **Note:** Updating an organization's `domain_names` property overwrites all existing `domain_names` values. To prevent this, submit a complete list of `domain_names` for the organization in your request.
    16
    
    
    17
    #### Example Request
    18
    
    
    19
    ```js
    20
    {
    21
      "organization": {
    22
        "notes": "Something interesting"
    23
      }
    24
    }
    25
    ```
    26
    
    
    27
     */
    28
    export async function main(auth: Zendesk, organization_id: string) {
    29
      const url = new URL(
    30
        `https://${auth.subdomain}.zendesk.com/api/v2/organizations/${organization_id}`
    31
      );
    32
    
    
    33
      const response = await fetch(url, {
    34
        method: "PUT",
    35
        headers: {
    36
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
    37
        },
    38
        body: undefined,
    39
      });
    40
      if (!response.ok) {
    41
        const text = await response.text();
    42
        throw new Error(`${response.status} ${text}`);
    43
      }
    44
      return await response.json();
    45
    }
    46