people

package
v2.0.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2026 License: MPL-2.0 Imports: 9 Imported by: 1

README

People

The People module provides functionality to interact with the Webex People API, allowing you to retrieve information about users in your Webex organization.

Overview

The People API in Webex provides access to user details and profiles. This module allows you to:

  1. Retrieve your own user information
  2. Get details about other users by ID
  3. Search for users by email or display name
  4. Efficiently retrieve multiple users at once with batch requests

The People module includes a sophisticated batching system that optimizes multiple user lookups by grouping them into fewer API calls, which can help with rate limits and overall performance.

Installation

This module is part of the Webex Go SDK. To use it, import the SDK and the people package:

import (
    "github.com/WebexCommunity/webex-go-sdk/v2"
    "github.com/WebexCommunity/webex-go-sdk/v2/people"
)

Usage

Initializing the Client
client, err := webex.NewClient(accessToken, nil)
if err != nil {
    log.Fatalf("Error creating client: %v", err)
}

// Access the people client
peopleClient := client.People()
Getting Your Own User Information

To retrieve information about the currently authenticated user:

me, err := client.People().Get("me")
// Or use the specialized method
me, err := client.People().GetMe()

if err != nil {
    log.Fatalf("Error getting current user: %v", err)
}

fmt.Printf("Current user: %s (%s)\n", me.DisplayName, me.Emails[0])
Getting a Person by ID

To retrieve information about a specific user by their ID:

person, err := client.People().Get("PERSON_ID")
if err != nil {
    log.Fatalf("Error getting person: %v", err)
}

fmt.Printf("Person: %s (%s)\n", person.DisplayName, person.Emails[0])
Searching for People

To search for people by email:

options := &people.ListOptions{
    Email: "user@example.com", // Can be a partial match
}
page, err := client.People().List(options)
if err != nil {
    log.Fatalf("Error listing people: %v", err)
}

for _, person := range page.Items {
    fmt.Printf("Found: %s (%s)\n", person.DisplayName, person.Emails[0])
}

To search for people by display name:

options := &people.ListOptions{
    DisplayName: "John", // Can be a partial match
}
page, err := client.People().List(options)
Batch Retrieval of Multiple People

To efficiently retrieve multiple people at once:

options := &people.ListOptions{
    IDs: []string{"PERSON_ID_1", "PERSON_ID_2", "PERSON_ID_3"},
}
page, err := client.People().List(options)
if err != nil {
    log.Fatalf("Error listing people: %v", err)
}

for _, person := range page.Items {
    fmt.Printf("Person: %s (%s)\n", person.DisplayName, person.Emails[0])
}

The module automatically batches these requests for optimal performance.

Data Structures

Person Structure

The Person structure contains the following fields:

Field Type Description
ID string Unique identifier for the person
Emails []string Array of email addresses associated with the person
DisplayName string Full name of the person
NickName string Nickname or preferred name of the person
FirstName string First name of the person
LastName string Last name of the person
Avatar string URL of the person's avatar image
OrgID string Organization ID the person belongs to
Roles []string Array of roles assigned to the person
Licenses []string Array of licenses assigned to the person
Created time.Time Timestamp when the person was created
Status string Current status of the person (active, inactive, etc.)
Type string Type of account (usually "person")
ListOptions

When listing or searching for people, you can use the following filter options:

Option Type Description
Email string Filter by email address (partial match supported)
DisplayName string Filter by display name (partial match supported)
IDs []string Get multiple people by their IDs (batch operation)
Max int Maximum number of results to return
ShowAllTypes bool Include non-person types in results
Configuration Options

The People module supports the following configuration options:

Option Description Default
BatcherWait Time to wait before processing a batch request 100 milliseconds
MaxBatchCalls Maximum number of batch calls to make at once 10
MaxBatchWait Maximum time to wait before processing a batch request 1500 milliseconds
ShowAllTypes Include non-person types (e.g., SX10, webhook_integration, etc.) false

You can customize these settings when creating the client:

config := &people.Config{
    BatcherWait:   200 * time.Millisecond,
    MaxBatchCalls: 20,
    ShowAllTypes:  true,
}

client, err := webex.NewClient(accessToken, nil)
peopleClient := people.New(client, config)

Complete Example

Here's a complete example that demonstrates the major features of the People module:

package main

import (
    "fmt"
    "log"
    "os"

    "github.com/WebexCommunity/webex-go-sdk/v2"
    "github.com/WebexCommunity/webex-go-sdk/v2/people"
)

func main() {
    // Get access token from environment
    accessToken := os.Getenv("WEBEX_ACCESS_TOKEN")
    if accessToken == "" {
        log.Fatal("WEBEX_ACCESS_TOKEN environment variable is required")
    }

    // Create client
    client, err := webex.NewClient(accessToken, nil)
    if err != nil {
        log.Fatalf("Error creating client: %v", err)
    }

    // Get current user information
    me, err := client.People().GetMe()
    if err != nil {
        log.Fatalf("Error getting current user: %v", err)
    }
    
    fmt.Printf("Current user: %s (%s)\n", me.DisplayName, me.Emails[0])
    fmt.Printf("  ID: %s\n", me.ID)
    fmt.Printf("  Name: %s %s\n", me.FirstName, me.LastName)
    fmt.Printf("  Organization: %s\n", me.OrgID)
    
    if len(me.Roles) > 0 {
        fmt.Printf("  Roles: %v\n", me.Roles)
    }
    
    // Search for people with similar email domain
    emailDomain := me.Emails[0][me.Emails[0].IndexByte('@'):]
    fmt.Printf("\nSearching for people with email domain %s...\n", emailDomain)
    
    options := &people.ListOptions{
        Email: emailDomain,
        Max:   10,
    }
    
    page, err := client.People().List(options)
    if err != nil {
        log.Fatalf("Error listing people: %v", err)
    }
    
    fmt.Printf("Found %d people:\n", len(page.Items))
    
    // Collect IDs for batch retrieval demonstration
    var ids []string
    for i, person := range page.Items {
        fmt.Printf("%d. %s (%s)\n", i+1, person.DisplayName, person.Emails[0])
        ids = append(ids, person.ID)
    }
    
    // Demonstrate batch retrieval
    if len(ids) > 1 {
        fmt.Printf("\nRetrieving %d people at once using batch API...\n", len(ids))
        
        batchOptions := &people.ListOptions{
            IDs: ids,
        }
        
        batchPage, err := client.People().List(batchOptions)
        if err != nil {
            log.Fatalf("Error retrieving batch of people: %v", err)
        }
        
        fmt.Printf("Successfully retrieved %d people in a single batch request\n", 
            len(batchPage.Items))
    }
}

Error Handling

All methods return structured errors from the webexsdk package. Use the convenience functions to check error types:

person, err := client.People().Get("PERSON_ID")
if err != nil {
    switch {
    case webexsdk.IsNotFound(err):
        log.Println("Person not found")
    case webexsdk.IsAuthError(err):
        log.Println("Invalid or expired access token")
    case webexsdk.IsRateLimited(err):
        log.Println("Rate limited — SDK retries automatically")
    default:
        log.Printf("Error: %v", err)
    }
}

See webexsdk/Readme.md for the full error type reference.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeBase64

func DecodeBase64(s string) (string, error)

DecodeBase64 decodes a base64 string

func EncodeBase64

func EncodeBase64(s string) string

EncodeBase64 encodes a string to base64

func InferPersonIDFromUUID

func InferPersonIDFromUUID(id string) string

InferPersonIDFromUUID converts a UUID to a Hydra ID without a network call

Types

type BatchResponse

type BatchResponse struct {
	Items       []Person `json:"items"`
	NotFoundIDs []string `json:"notFoundIds,omitempty"`
}

BatchResponse represents the response from a batch people request

type Batcher

type Batcher struct {
	// contains filtered or unexported fields
}

Batcher manages batched requests for people

func NewBatcher

func NewBatcher(client *webexsdk.Client, config *Config) *Batcher

NewBatcher creates a new people batcher

func (*Batcher) BatchRequest

func (b *Batcher) BatchRequest(ids []string) ([]Person, error)

BatchRequest processes a batch of requests immediately

func (*Batcher) Request

func (b *Batcher) Request(id string) (*Person, error)

Request adds a request to the batch and returns the result

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the people API client

func New

func New(webexClient *webexsdk.Client, config *Config) *Client

New creates a new People plugin

func (*Client) Get

func (c *Client) Get(personID string) (*Person, error)

Get returns a single person by ID

func (*Client) GetMe

func (c *Client) GetMe() (*Person, error)

GetMe returns the current authenticated user

func (*Client) List

func (c *Client) List(options *ListOptions) (*PeoplePage, error)

List returns a list of people

type Config

type Config struct {
	// BatcherWait is the time to wait before processing a batch request
	BatcherWait time.Duration

	// MaxBatchCalls is the maximum number of batch calls to make at once
	MaxBatchCalls int

	// MaxBatchWait is the maximum time to wait before processing a batch request
	MaxBatchWait time.Duration

	// ShowAllTypes is a flag that requires the API to send every type field,
	// even if the type is not "person" (e.g.: SX10, webhook_integration, etc.)
	ShowAllTypes bool
}

Config holds the configuration for the People plugin

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default configuration for the People plugin

type ListOptions

type ListOptions struct {
	Email        string   `url:"email,omitempty"`
	DisplayName  string   `url:"displayName,omitempty"`
	IDs          []string `url:"-"` // Handled separately in the List method
	Max          int      `url:"max,omitempty"`
	ShowAllTypes bool     `url:"showAllTypes,omitempty"`
}

ListOptions contains the options for listing people

type PeoplePage

type PeoplePage struct {
	Items []Person `json:"items"`
	*webexsdk.Page
}

PeoplePage represents a paginated list of people

type Person

type Person struct {
	ID          string                  `json:"id"`
	Emails      []string                `json:"emails"`
	DisplayName string                  `json:"displayName"`
	NickName    string                  `json:"nickName,omitempty"`
	FirstName   string                  `json:"firstName,omitempty"`
	LastName    string                  `json:"lastName,omitempty"`
	Avatar      string                  `json:"avatar,omitempty"`
	OrgID       string                  `json:"orgId,omitempty"`
	Roles       []string                `json:"roles,omitempty"`
	Licenses    []string                `json:"licenses,omitempty"`
	Created     time.Time               `json:"created,omitempty"`
	Status      string                  `json:"status,omitempty"`
	Type        string                  `json:"type,omitempty"`
	Errors      webexsdk.ResourceErrors `json:"errors,omitempty"`
}

Person represents a Webex person

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL