Edits history of script submission #23844 for ' Get Article (zendesk)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Get Article
     * Retrieve a Help Center article, in the given locale (e.g. `en-us`) or the Help Center's default one.
     */
    export async function main(
      auth: RT.Zendesk,
      article_id: number,
      locale: string | undefined
    ) {
      const localePath = locale ? `/${locale.toLowerCase()}` : ""
      const response = await fetch(
        `https://${auth.subdomain}.zendesk.com/api/v2/help_center${localePath}/articles/${article_id}`,
        {
          headers: {
            Authorization: auth.token
              ? `Bearer ${auth.token}`
              : `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
            Accept: "application/json",
          },
        }
      )
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 2 hours ago