0

List Locales

by
Published Nov 7, 2023

List the locales enabled on the account (e.g. `en-us`, `fr`), for the Help Center and dynamic content `locale` parameters.

Script zendesk Verified

The script

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

3
/**
4
 * List Locales
5
 * List the locales enabled on the account (e.g. `en-us`, `fr`), for the Help Center and dynamic content `locale` parameters.
6
 */
7
export async function main(auth: RT.Zendesk) {
8
  const response = await fetch(
9
    `https://${auth.subdomain}.zendesk.com/api/v2/locales`,
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 533 days ago
    1
    type Zendesk = {
    2
      username: string;
    3
      password: string;
    4
      subdomain: string;
    5
    };
    6
    /**
    7
     * List Locales
    8
     * Lists the translation locales available for the account.
    9
    
    
    10
    **Note**: You can alter the list by passing an updated `locale_ids` array to the Update Account Settings endpoint.
    11
    
    
    12
    #### Allowed For
    13
    
    
    14
    * Anyone
    15
    
    
    16
     */
    17
    export async function main(auth: Zendesk) {
    18
      const url = new URL(`https://${auth.subdomain}.zendesk.com/api/v2/locales`);
    19
    
    
    20
      const response = await fetch(url, {
    21
        method: "GET",
    22
        headers: {
    23
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
    24
        },
    25
        body: undefined,
    26
      });
    27
      if (!response.ok) {
    28
        const text = await response.text();
    29
        throw new Error(`${response.status} ${text}`);
    30
      }
    31
      return await response.json();
    32
    }
    33