0

Get Organization

by
Published Nov 7, 2023

Retrieve an organization by id.

Script zendesk Verified

The script

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

3
/**
4
 * Get Organization
5
 * Retrieve an organization by id.
6
 */
7
export async function main(auth: RT.Zendesk, organization_id: number) {
8
  const response = await fetch(
9
    `https://${auth.subdomain}.zendesk.com/api/v2/organizations/${organization_id}`,
10
    {
11
      headers: {
12
        Authorization: auth.token
13
          ? `Bearer ${auth.token}`
14
          : `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
15
        Accept: "application/json",
16
      },
17
    }
18
  )
19

20
  if (!response.ok) {
21
    throw new Error(`${response.status} ${await response.text()}`)
22
  }
23

24
  return await response.json()
25
}
26

Other submissions
  • Submitted by hugo697 Typescript (fetch-only)
    Created 528 days ago
    1
    type Zendesk = {
    2
      username: string;
    3
      password: string;
    4
      subdomain: string;
    5
    };
    6
    /**
    7
     * Show Organization
    8
     * #### Allowed For
    9
    
    
    10
    * Admins
    11
    * Agents
    12
    
    
    13
     */
    14
    export async function main(auth: Zendesk, organization_id: string) {
    15
      const url = new URL(
    16
        `https://${auth.subdomain}.zendesk.com/api/v2/organizations/${organization_id}`
    17
      );
    18
    
    
    19
      const response = await fetch(url, {
    20
        method: "GET",
    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.json();
    31
    }
    32