# Teams

Team management and collaboration

Source: https://keyenv.dev/docs/api/teams/

Team management and collaboration

## List teams

```http
GET /api/v1/teams
```

Returns all teams the current user is a member of

**Operation ID:** `listTeams` &middot; **Authentication:** `Authorization: Bearer <token>`

### Responses

| Status | Description | Body |
| --- | --- | --- |
| `200` | List of teams | `object` |
| `401` | Authentication required | `Error` |

### Response body (`200`)

| Field | Type | Description |
| --- | --- | --- |
| `teams` | `object[]` |  |

### Example

```bash
curl -X GET "https://api.keyenv.dev/api/v1/teams" \
  -H "Authorization: Bearer $KEYENV_TOKEN"
```

## Create team

```http
POST /api/v1/teams
```

Creates a new team with the current user as owner

**Operation ID:** `createTeam` &middot; **Authentication:** `Authorization: Bearer <token>`

### Request body

`application/json` (required)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | `string` | yes |  |

### Responses

| Status | Description | Body |
| --- | --- | --- |
| `201` | Team created | `Team` |
| `400` | Invalid request | `Error` |
| `401` | Authentication required | `Error` |

### Response body (`201`)

| Field | Type | Description |
| --- | --- | --- |
| `id` | `string (uuid)` |  |
| `name` | `string` |  |
| `slug` | `string` |  |
| `plan` | `enum (free, team, enterprise)` |  |
| `is_personal` | `boolean` |  |
| `created_at` | `string (date-time)` |  |

### Example

```bash
curl -X POST "https://api.keyenv.dev/api/v1/teams" \
  -H "Authorization: Bearer $KEYENV_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name":"string"}'
```

## Get team

```http
GET /api/v1/teams/{teamId}
```

Returns team details including members

**Operation ID:** `getTeam` &middot; **Authentication:** `Authorization: Bearer <token>`

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `teamId` | `string (uuid)` | yes | Team UUID |

### Responses

| Status | Description | Body |
| --- | --- | --- |
| `200` | Team details | `object` |
| `401` | Authentication required | `Error` |
| `403` | Insufficient permissions | `Error` |
| `404` | Resource not found | `Error` |

### Example

```bash
curl -X GET "https://api.keyenv.dev/api/v1/teams/{teamId}" \
  -H "Authorization: Bearer $KEYENV_TOKEN"
```

## Invite team member

```http
POST /api/v1/teams/{teamId}/members
```

Invites a user to join the team by email

**Operation ID:** `inviteTeamMember` &middot; **Authentication:** `Authorization: Bearer <token>`

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `teamId` | `string (uuid)` | yes | Team UUID |

### Request body

`application/json` (required)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `email` | `string (email)` | yes |  |
| `role` | `enum (admin, developer, viewer)` | yes |  |

### Responses

| Status | Description | Body |
| --- | --- | --- |
| `201` | Member invited | `TeamMember` |
| `400` | Invalid request | `Error` |
| `401` | Authentication required | `Error` |
| `403` | Insufficient permissions | `Error` |

### Response body (`201`)

| Field | Type | Description |
| --- | --- | --- |
| `user_id` | `string (uuid)` |  |
| `email` | `string (email)` |  |
| `name` | `string` |  |
| `avatar_url` | `string (uri)` |  |
| `role` | `enum (owner, admin, developer, viewer)` |  |
| `joined_at` | `string (date-time)` |  |

### Example

```bash
curl -X POST "https://api.keyenv.dev/api/v1/teams/{teamId}/members" \
  -H "Authorization: Bearer $KEYENV_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"email":"string","role":"admin"}'
```

## Update member role

```http
PATCH /api/v1/teams/{teamId}/members/{userId}
```

Updates a team member's role

**Operation ID:** `updateMemberRole` &middot; **Authentication:** `Authorization: Bearer <token>`

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `teamId` | `string (uuid)` | yes | Team UUID |
| `userId` | `string (uuid)` | yes | User UUID |

### Request body

`application/json` (required)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `role` | `enum (admin, developer, viewer)` | yes |  |

### Responses

| Status | Description | Body |
| --- | --- | --- |
| `200` | Role updated | `TeamMember` |
| `400` | Invalid request | `Error` |
| `401` | Authentication required | `Error` |
| `403` | Insufficient permissions | `Error` |

### Response body (`200`)

| Field | Type | Description |
| --- | --- | --- |
| `user_id` | `string (uuid)` |  |
| `email` | `string (email)` |  |
| `name` | `string` |  |
| `avatar_url` | `string (uri)` |  |
| `role` | `enum (owner, admin, developer, viewer)` |  |
| `joined_at` | `string (date-time)` |  |

### Example

```bash
curl -X PATCH "https://api.keyenv.dev/api/v1/teams/{teamId}/members/{userId}" \
  -H "Authorization: Bearer $KEYENV_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"role":"admin"}'
```

## Remove team member

```http
DELETE /api/v1/teams/{teamId}/members/{userId}
```

Removes a member from the team

**Operation ID:** `removeTeamMember` &middot; **Authentication:** `Authorization: Bearer <token>`

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `teamId` | `string (uuid)` | yes | Team UUID |
| `userId` | `string (uuid)` | yes | User UUID |

### Responses

| Status | Description | Body |
| --- | --- | --- |
| `204` | Member removed |  |
| `401` | Authentication required | `Error` |
| `403` | Insufficient permissions | `Error` |
| `404` | Resource not found | `Error` |

### Example

```bash
curl -X DELETE "https://api.keyenv.dev/api/v1/teams/{teamId}/members/{userId}" \
  -H "Authorization: Bearer $KEYENV_TOKEN"
```
