Edits history of script submission #23819 for ' Get User (zendesk)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Get User
     * Retrieve a user (end user, agent or admin) by id.
     */
    export async function main(auth: RT.Zendesk, user_id: number) {
      const response = await fetch(
        `https://${auth.subdomain}.zendesk.com/api/v2/users/${user_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