> ## Documentation Index
> Fetch the complete documentation index at: https://doc-dev.weir.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Get Teams

> Retrieve all teams in your organization with pagination support

# Get Teams

Retrieve a paginated list of all teams in your organization with their basic information.

<RequestExample>
  ```bash cURL theme={null}
  curl -X GET 'https://api.weir.ai/org/teams?page=1&limit=10' \
    -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
    -H 'x-source: console'
  ```
</RequestExample>

<ResponseExample>
  ```json Success Response theme={null}
  {
    "data": {
      "teams": [
        {
          "teamId": "team_123456789",
          "name": "Development Team",
          "memberCount": 5,
          "createdAt": "2024-01-15T10:30:00Z",
          "status": "active"
        },
        {
          "teamId": "team_987654321",
          "name": "Marketing Team",
          "memberCount": 3,
          "createdAt": "2024-01-20T14:15:00Z",
          "status": "active"
        }
      ],
      "pagination": {
        "page": 1,
        "limit": 10,
        "total": 2,
        "totalPages": 1
      }
    },
    "message": "Teams retrieved successfully",
    "status": "success"
  }
  ```
</ResponseExample>

## Authentication

This endpoint requires Console API authentication with bearer token and `x-source: console` header.

<ParamField header="Authorization" type="string" required>
  Bearer token for authentication. Format: `Bearer YOUR_ACCESS_TOKEN`
</ParamField>

<ParamField header="x-source" type="string" required>
  Source identifier. Must be set to `console` for all Console API requests.
</ParamField>

## Query Parameters

<ParamField query="page" type="integer" default="1">
  Page number for pagination. Must be a positive integer.
</ParamField>

<ParamField query="limit" type="integer" default="10">
  Number of teams per page. Range: 1-100.
</ParamField>

## Response Fields

<ResponseField name="data" type="object" required>
  Teams data object containing the list of teams and pagination information.

  <Expandable title="Teams Data Properties">
    <ResponseField name="data.teams" type="array" required>
      Array of team objects.

      <Expandable title="Team Object Properties">
        <ResponseField name="data.teams[].teamId" type="string" required>
          Unique identifier for the team.
        </ResponseField>

        <ResponseField name="data.teams[].name" type="string" required>
          Name of the team.
        </ResponseField>

        <ResponseField name="data.teams[].memberCount" type="integer" required>
          Number of members in the team.
        </ResponseField>

        <ResponseField name="data.teams[].createdAt" type="timestamp" required>
          ISO 8601 formatted timestamp of when the team was created.
        </ResponseField>

        <ResponseField name="data.teams[].status" type="string" required>
          Current status of the team (e.g., "active", "inactive").
        </ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="data.pagination" type="object" required>
      Pagination information object.

      <Expandable title="Pagination Properties">
        <ResponseField name="data.pagination.page" type="integer" required>
          Current page number.
        </ResponseField>

        <ResponseField name="data.pagination.limit" type="integer" required>
          Number of items per page.
        </ResponseField>

        <ResponseField name="data.pagination.total" type="integer" required>
          Total number of teams in the organization.
        </ResponseField>

        <ResponseField name="data.pagination.totalPages" type="integer" required>
          Total number of pages available.
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="message" type="string" required>
  Human-readable message describing the result of the operation.
</ResponseField>

<ResponseField name="status" type="string" required>
  Operation status. Always "success" for successful requests.
</ResponseField>

## Error Responses

<AccordionGroup>
  <Accordion title="401 Unauthorized" icon="ban">
    ```json theme={null}
    {
      "error": {
        "code": "UNAUTHORIZED",
        "message": "Invalid or expired token",
        "details": "The provided access token is invalid or has expired"
      },
      "status": "error"
    }
    ```

    **Causes**:

    * Missing or invalid access token
    * Expired access token
    * Missing x-source header
  </Accordion>

  <Accordion title="403 Forbidden" icon="lock">
    ```json theme={null}
    {
      "error": {
        "code": "FORBIDDEN",
        "message": "Insufficient permissions",
        "details": "You do not have permission to view teams in this organization"
      },
      "status": "error"
    }
    ```

    **Causes**:

    * User lacks team viewing permissions
    * User is not a member of the organization
  </Accordion>

  <Accordion title="400 Bad Request" icon="exclamation-triangle">
    ```json theme={null}
    {
      "error": {
        "code": "VALIDATION_ERROR",
        "message": "Invalid pagination parameters",
        "details": {
          "page": "Page must be a positive integer",
          "limit": "Limit must be between 1 and 100"
        }
      },
      "status": "error"
    }
    ```

    **Causes**:

    * Invalid page number (negative or zero)
    * Invalid limit value (outside 1-100 range)
  </Accordion>
</AccordionGroup>

## Usage Examples

<CodeGroup>
  ```javascript JavaScript theme={null}
  const getTeams = async (accessToken, page = 1, limit = 10) => {
    try {
      const response = await fetch(`https://api.weir.ai/org/teams?page=${page}&limit=${limit}`, {
        method: 'GET',
        headers: {
          'Authorization': `Bearer ${accessToken}`,
          'x-source': 'console'
        }
      });
      
      if (!response.ok) {
        throw new Error(`HTTP error! status: ${response.status}`);
      }
      
      const data = await response.json();
      return data.data;
    } catch (error) {
      console.error('Get teams error:', error);
      throw error;
    }
  };

  // Usage
  const teamsData = await getTeams('your_access_token', 1, 20);
  console.log('Teams:', teamsData.teams);
  console.log('Total teams:', teamsData.pagination.total);
  ```

  ```python Python theme={null}
  import requests

  def get_teams(access_token, page=1, limit=10):
      try:
          response = requests.get(
              f'https://api.weir.ai/org/teams?page={page}&limit={limit}',
              headers={
                  'Authorization': f'Bearer {access_token}',
                  'x-source': 'console'
              }
          )
          response.raise_for_status()
          
          data = response.json()
          return data['data']
      except requests.exceptions.RequestException as e:
          print(f'Get teams error: {e}')
          raise

  # Usage
  teams_data = get_teams('your_access_token', page=1, limit=20)
  print(f'Teams: {teams_data["teams"]}')
  print(f'Total teams: {teams_data["pagination"]["total"]}')
  ```

  ```php PHP theme={null}
  function getTeams($accessToken, $page = 1, $limit = 10) {
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, "https://api.weir.ai/org/teams?page=$page&limit=$limit");
      curl_setopt($ch, CURLOPT_HTTPHEADER, [
          'Authorization: Bearer ' . $accessToken,
          'x-source: console'
      ]);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      
      $response = curl_exec($ch);
      $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
      curl_close($ch);
      
      if ($httpCode !== 200) {
          throw new Exception("HTTP error: $httpCode");
      }
      
      $data = json_decode($response, true);
      return $data['data'];
  }

  // Usage
  $teamsData = getTeams('your_access_token', 1, 20);
  echo "Teams: " . json_encode($teamsData['teams']);
  echo "Total teams: " . $teamsData['pagination']['total'];
  ```
</CodeGroup>

## Pagination Examples

<AccordionGroup>
  <Accordion title="Basic Pagination" icon="list">
    ```javascript theme={null}
    // Get first page with default limit
    const firstPage = await getTeams(accessToken);

    // Get second page with 20 items per page
    const secondPage = await getTeams(accessToken, 2, 20);
    ```
  </Accordion>

  <Accordion title="Complete Pagination" icon="arrows-alt-h">
    ```javascript theme={null}
    async function getAllTeams(accessToken) {
      const allTeams = [];
      let page = 1;
      let hasMore = true;
      
      while (hasMore) {
        const data = await getTeams(accessToken, page, 50);
        allTeams.push(...data.teams);
        
        hasMore = page < data.pagination.totalPages;
        page++;
      }
      
      return allTeams;
    }
    ```
  </Accordion>

  <Accordion title="Search and Filter" icon="search">
    ```javascript theme={null}
    // Client-side filtering example
    const teamsData = await getTeams(accessToken);
    const activeTeams = teamsData.teams.filter(team => team.status === 'active');
    const largeTeams = teamsData.teams.filter(team => team.memberCount > 5);
    ```
  </Accordion>
</AccordionGroup>

## Best Practices

<AccordionGroup>
  <Accordion title="Pagination" icon="list">
    * Use appropriate page sizes (10-50 items per page)
    * Implement proper pagination controls in your UI
    * Cache results when possible to reduce API calls
    * Handle empty results gracefully
  </Accordion>

  <Accordion title="Performance" icon="rocket">
    * Use reasonable page limits to avoid large responses
    * Implement client-side caching for frequently accessed data
    * Consider implementing search and filtering on the client side
  </Accordion>

  <Accordion title="Error Handling" icon="exclamation-triangle">
    * Handle pagination parameter validation errors
    * Implement retry logic for transient failures
    * Provide fallback UI for empty team lists
  </Accordion>
</AccordionGroup>

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Create Team" icon="plus" href="/v1.0.1/api-reference/console-apis/teams/create-team">
    Create a new team in your organization.
  </Card>

  <Card title="Get Team Members" icon="users" href="/v1.0.1/api-reference/console-apis/teams/get-members">
    View members of a specific team.
  </Card>

  <Card title="Invite Team Member" icon="user-plus" href="/v1.0.1/api-reference/console-apis/teams/invite-member">
    Add new members to a team.
  </Card>

  <Card title="Delete Team" icon="trash" href="/v1.0.1/api-reference/console-apis/teams/delete-team">
    Remove a team from your organization.
  </Card>
</CardGroup>

<Tip>
  **Pro Tip**: Use pagination to efficiently load teams in your UI. Start with a reasonable page size (10-20) and implement "Load More" functionality for better user experience.
</Tip>
