Edits history of script submission #23057 for ' Get User (gworkspace)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Get User
     * Retrieve a user by primary email, alias or unique ID. Use projection `full` to include custom schema fields. Works with admin.directory.user or admin.directory.user.readonly.
     */
    export async function main(
      auth: RT.Gworkspace,
      user_key: string,
      projection: "basic" | "full" = "basic",
    ) {
      const url = new URL(
        `https://admin.googleapis.com/admin/directory/v1/users/${encodeURIComponent(user_key)}`,
      )
      url.searchParams.append("projection", projection)
    
      const response = await fetch(url, {
        headers: {
          Authorization: `Bearer ${auth.token}`,
          Accept: "application/json",
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 1 hour ago