0

Get Article

by
Published today

Retrieve a Help Center article, in the given locale (e.g. `en-us`) or the Help Center's default one.

Script zendesk Verified

The script

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

3
/**
4
 * Get Article
5
 * Retrieve a Help Center article, in the given locale (e.g. `en-us`) or the Help Center's default one.
6
 */
7
export async function main(
8
  auth: RT.Zendesk,
9
  article_id: number,
10
  locale: string | undefined
11
) {
12
  const localePath = locale ? `/${locale.toLowerCase()}` : ""
13
  const response = await fetch(
14
    `https://${auth.subdomain}.zendesk.com/api/v2/help_center${localePath}/articles/${article_id}`,
15
    {
16
      headers: {
17
        Authorization: auth.token
18
          ? `Bearer ${auth.token}`
19
          : `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
20
        Accept: "application/json",
21
      },
22
    }
23
  )
24

25
  if (!response.ok) {
26
    throw new Error(`${response.status} ${await response.text()}`)
27
  }
28

29
  return await response.json()
30
}
31