teams

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: 6 Imported by: 1

README

Teams

The Teams module provides functionality for interacting with the Webex Teams API. This module allows you to manage Webex Teams, including creating, retrieving, updating, and deleting teams.

Overview

Webex Teams are virtual spaces that help organize your collaboration. This module allows you to:

  1. Create new teams
  2. Retrieve team details
  3. List all teams you belong to
  4. Update existing teams
  5. Delete teams

Installation

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

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

Usage

Initializing the Client
// Create a new Webex client with your access token
client, err := webex.NewClient("your-access-token", nil)
if err != nil {
    log.Fatalf("Failed to create client: %v", err)
}

// Access the Teams API
teamsClient := client.Teams()
Creating a Team

To create a new Webex team:

newTeam := &teams.Team{
    Name:        "My New Team",
    Description: "This is a team created using the Go SDK",
}

createdTeam, err := client.Teams().Create(newTeam)
if err != nil {
    log.Printf("Failed to create team: %v", err)
} else {
    fmt.Printf("Created team with ID: %s\n", createdTeam.ID)
    fmt.Printf("Team Name: %s\n", createdTeam.Name)
}

The Name field is required for creating a team. The Description field is optional.

Getting a Team

Retrieve details of a specific team:

team, err := client.Teams().Get("team-id")
if err != nil {
    log.Printf("Failed to get team details: %v", err)
} else {
    fmt.Printf("Team Name: %s\n", team.Name)
    fmt.Printf("Team Description: %s\n", team.Description)
    fmt.Printf("Creator ID: %s\n", team.CreatorID)
}
Listing Teams

List all teams that you belong to:

teams, err := client.Teams().List(&teams.ListOptions{
    Max: 100,  // Optional: maximum number of results to return
})
if err != nil {
    log.Printf("Failed to list teams: %v", err)
} else {
    fmt.Printf("Found %d teams\n", len(teams.Items))
    for i, team := range teams.Items {
        fmt.Printf("%d. %s (%s)\n", i+1, team.Name, team.ID)
    }
}
Updating a Team

Update an existing team's properties:

updatedTeam := &teams.Team{
    Name:        "Updated Team Name",
    Description: "This is an updated description",
}

result, err := client.Teams().Update("team-id", updatedTeam)
if err != nil {
    log.Printf("Failed to update team: %v", err)
} else {
    fmt.Printf("Updated team name to: %s\n", result.Name)
    fmt.Printf("Updated team description to: %s\n", result.Description)
}

The Name field is required when updating a team. The Description field is optional.

Deleting a Team

Delete a team:

err = client.Teams().Delete("team-id")
if err != nil {
    log.Printf("Failed to delete team: %v", err)
} else {
    fmt.Println("Successfully deleted team")
}

Data Structures

Team Structure

The Team structure represents a Webex team with the following fields:

type Team struct {
    ID          string     // Unique identifier of the team
    Name        string     // Name of the team
    Description string     // Description of the team
    CreatorID   string     // ID of the person who created the team
    Created     *time.Time // Time when the team was created
}
ListOptions

When listing teams, you can specify the maximum number of results to return:

type ListOptions struct {
    Max int // Optional: Maximum number of results to return
}

Complete Example

Here's a complete example demonstrating the major operations with teams:

package main

import (
    "fmt"
    "log"
    "os"

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

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

    // Create a new Webex client
    client, err := webex.NewClient(accessToken, nil)
    if err != nil {
        log.Fatalf("Failed to create client: %v", err)
    }

    // List teams
    fmt.Println("Listing teams...")
    teamsPage, err := client.Teams().List(&teams.ListOptions{
        Max: 100,
    })
    if err != nil {
        log.Fatalf("Failed to list teams: %v", err)
    }
    fmt.Printf("Found %d teams\n", len(teamsPage.Items))
    for i, team := range teamsPage.Items {
        fmt.Printf("%d. %s (%s)\n", i+1, team.Name, team.ID)
        if team.Description != "" {
            fmt.Printf("   Description: %s\n", team.Description)
        }
    }

    // Create a team
    fmt.Println("\nCreating a new team...")
    newTeam := &teams.Team{
        Name:        "API Test Team",
        Description: "Team created via Go SDK example",
    }
    createdTeam, err := client.Teams().Create(newTeam)
    if err != nil {
        log.Printf("Failed to create team: %v\n", err)
        return
    }
    fmt.Printf("Created team with ID: %s\n", createdTeam.ID)
    fmt.Printf("Team Name: %s\n", createdTeam.Name)
    
    // Get team details
    fmt.Println("\nFetching team details...")
    teamDetails, err := client.Teams().Get(createdTeam.ID)
    if err != nil {
        log.Printf("Failed to get team details: %v\n", err)
        return
    }
    fmt.Printf("Team Details: %s\n", teamDetails.Name)
    
    // Update the team
    fmt.Println("\nUpdating team...")
    updatedTeamData := &teams.Team{
        Name:        "Updated API Test Team",
        Description: "Updated team description via Go SDK example",
    }
    updatedTeam, err := client.Teams().Update(teamDetails.ID, updatedTeamData)
    if err != nil {
        log.Printf("Failed to update team: %v\n", err)
        return
    }
    fmt.Printf("Updated team name to: %s\n", updatedTeam.Name)
    
    // Delete the team
    fmt.Println("\nDeleting team...")
    err = client.Teams().Delete(updatedTeam.ID)
    if err != nil {
        log.Printf("Failed to delete team: %v\n", err)
        return
    }
    fmt.Printf("Successfully deleted team\n")
}

Error Handling

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

team, err := client.Teams().Get("TEAM_ID")
if err != nil {
    switch {
    case webexsdk.IsNotFound(err):
        log.Println("Team 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

This section is empty.

Types

type Client

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

Client is the teams API client

func New

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

New creates a new Teams plugin

func (*Client) Create

func (c *Client) Create(team *Team) (*Team, error)

Create creates a new team

func (*Client) Delete

func (c *Client) Delete(teamID string) error

Delete deletes a team

func (*Client) Get

func (c *Client) Get(teamID string) (*Team, error)

Get returns details for a team

func (*Client) List

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

List returns a list of teams

func (*Client) Update

func (c *Client) Update(teamID string, team *Team) (*Team, error)

Update updates an existing team

type Config

type Config struct {
}

Config holds the configuration for the Teams plugin

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default configuration for the Teams plugin

type ListOptions

type ListOptions struct {
	Max int `url:"max,omitempty"`
}

ListOptions contains the options for listing teams

type Team

type Team struct {
	ID          string                  `json:"id,omitempty"`
	Name        string                  `json:"name,omitempty"`
	Description string                  `json:"description,omitempty"`
	CreatorID   string                  `json:"creatorId,omitempty"`
	Created     *time.Time              `json:"created,omitempty"`
	Errors      webexsdk.ResourceErrors `json:"errors,omitempty"`
}

Team represents a Webex team

type TeamsPage

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

TeamsPage represents a paginated list of teams

Jump to

Keyboard shortcuts

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