> ## 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.

# Create Team

> Create a new team within your organization

# Create Team

Create a new team within your organization for better collaboration and member management.

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST 'https://api.weir.ai/org/create/team' \
    -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
    -H 'Content-Type: application/json' \
    -H 'x-source: console' \
    -d '{
      "name": "Development Team"
    }'
  ```
</RequestExample>

<ResponseExample>
  ```json Success Response theme={null}
  {
    "data": {
      "teamId": "team_123456789",
      "name": "Development Team",
      "createdAt": "2024-01-15T10:30:00Z",
      "memberCount": 1,
      "status": "active"
    },
    "message": "Team created 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>

## Request Body

<ParamField body="name" type="string" required>
  The name of the team to create. Must be unique within the organization.
</ParamField>

## Response Fields

<ResponseField name="data" type="object" required>
  Team data object containing the created team information.

  <Expandable title="Team Properties">
    <ResponseField name="data.teamId" type="string" required>
      Unique identifier for the newly created team.
    </ResponseField>

    <ResponseField name="data.name" type="string" required>
      The name of the created team.
    </ResponseField>

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

    <ResponseField name="data.memberCount" type="integer" required>
      Number of members in the team. Initially 1 (the creator).
    </ResponseField>

    <ResponseField name="data.status" type="string" required>
      Current status of the team. Always "active" for newly created teams.
    </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 team creation.
</ResponseField>

## Error Responses

<AccordionGroup>
  <Accordion title="400 Bad Request" icon="exclamation-triangle">
    ```json theme={null}
    {
      "error": {
        "code": "VALIDATION_ERROR",
        "message": "Invalid request parameters",
        "details": {
          "name": "Team name is required and must be between 2-50 characters"
        }
      },
      "status": "error"
    }
    ```

    **Causes**:

    * Missing team name
    * Team name too short or too long
    * Invalid characters in team name
  </Accordion>

  <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 create teams in this organization"
      },
      "status": "error"
    }
    ```

    **Causes**:

    * User lacks team creation permissions
    * User is not an organization admin
  </Accordion>

  <Accordion title="409 Conflict" icon="exclamation">
    ```json theme={null}
    {
      "error": {
        "code": "TEAM_NAME_EXISTS",
        "message": "Team name already exists",
        "details": "A team with this name already exists in your organization"
      },
      "status": "error"
    }
    ```

    **Causes**:

    * Team name already exists in the organization
    * Duplicate team creation attempt
  </Accordion>
</AccordionGroup>

## Usage Examples

<CodeGroup>
  ```javascript JavaScript theme={null}
  const createTeam = async (teamName, accessToken) => {
    try {
      const response = await fetch('https://api.weir.ai/org/create/team', {
        method: 'POST',
        headers: {
          'Authorization': `Bearer ${accessToken}`,
          'Content-Type': 'application/json',
          'x-source': 'console'
        },
        body: JSON.stringify({ name: teamName })
      });
      
      if (!response.ok) {
        throw new Error(`HTTP error! status: ${response.status}`);
      }
      
      const data = await response.json();
      return data.data;
    } catch (error) {
      console.error('Create team error:', error);
      throw error;
    }
  };

  // Usage
  const team = await createTeam('Development Team', 'your_access_token');
  console.log('Created team:', team);
  ```

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

  def create_team(team_name, access_token):
      try:
          response = requests.post(
              'https://api.weir.ai/org/create/team',
              headers={
                  'Authorization': f'Bearer {access_token}',
                  'Content-Type': 'application/json',
                  'x-source': 'console'
              },
              json={'name': team_name}
          )
          response.raise_for_status()
          
          data = response.json()
          return data['data']
      except requests.exceptions.RequestException as e:
          print(f'Create team error: {e}')
          raise

  # Usage
  team = create_team('Development Team', 'your_access_token')
  print(f'Created team: {team}')
  ```

  ```php PHP theme={null}
  function createTeam($teamName, $accessToken) {
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, 'https://api.weir.ai/org/create/team');
      curl_setopt($ch, CURLOPT_POST, true);
      curl_setopt($ch, CURLOPT_HTTPHEADER, [
          'Authorization: Bearer ' . $accessToken,
          'Content-Type: application/json',
          'x-source: console'
      ]);
      curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['name' => $teamName]));
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      
      $response = curl_exec($ch);
      $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
      curl_close($ch);
      
      if ($httpCode !== 201) {
          throw new Exception("HTTP error: $httpCode");
      }
      
      $data = json_decode($response, true);
      return $data['data'];
  }

  // Usage
  $team = createTeam('Development Team', 'your_access_token');
  echo "Created team: " . json_encode($team);
  ```
</CodeGroup>

## Team Management Workflow

<Steps>
  <Step title="Create Team" icon="plus">
    Use this endpoint to create a new team with a unique name.
  </Step>

  <Step title="Invite Members" icon="user-plus">
    Use the invite team member endpoint to add users to the team.
  </Step>

  <Step title="Manage Roles" icon="users-cog">
    Update team member roles as needed for proper access control.
  </Step>

  <Step title="Monitor Team" icon="eye">
    Use the get teams endpoint to monitor team activity and membership.
  </Step>
</Steps>

## Best Practices

<AccordionGroup>
  <Accordion title="Team Naming" icon="tag">
    * Use descriptive and clear team names
    * Follow consistent naming conventions
    * Avoid special characters and spaces
    * Keep names under 50 characters
  </Accordion>

  <Accordion title="Permission Management" icon="shield">
    * Ensure users have proper permissions before team creation
    * Implement role-based access control
    * Monitor team creation activities
  </Accordion>

  <Accordion title="Error Handling" icon="exclamation-triangle">
    * Handle duplicate team name errors gracefully
    * Provide clear error messages to users
    * Implement retry logic for transient failures
  </Accordion>
</AccordionGroup>

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Get Teams" icon="list" href="/v1.0.1/api-reference/console-apis/teams/get-teams">
    Retrieve all teams in your organization.
  </Card>

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

  <Card title="Get Team Members" icon="users" href="/v1.0.1/api-reference/console-apis/teams/get-members">
    View all members of a specific 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**: Create teams with clear, descriptive names that reflect their purpose or department. This makes team management and member assignment much easier.
</Tip>
