# Teams endpoints

Every path starts at your [API URL](https://docs.qualithm.com/api.md#find-your-api-url). Every response is JSON, and an error has the [error body](https://docs.qualithm.com/api.md#errors).

## List the caller's teams; an API token sees only its own

`GET /v1/teams`

Newest first, by `createdAt` then `id`.

Needs an [API token](https://docs.qualithm.com/api.md#authenticate).

**Parameters**

| Name | In | Type | Required | Description |
| ---- | -- | ---- | -------- | ----------- |
| `limit` | query | integer | No | Items per page, 1 to 100. Default 50. |
| `cursor` | query | string | No | A previous page's `nextCursor`, to read the page after it |

**Response:** `200` with [TeamPage](#teampage) in `data`.

**[Errors](https://docs.qualithm.com/api.md#errors):** `400`, `401`, `429`, `500`, `503`

```bash
curl "<your-api-url>/v1/teams" \
  -H "Authorization: Bearer <your-api-token>"
```

## Get one of the caller's teams, with their role and permissions in it

`GET /v1/teams/{teamId}`

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `team.read` permission, which the owner, manager and viewer roles hold.

**Parameters**

| Name | In | Type | Required | Description |
| ---- | -- | ---- | -------- | ----------- |
| `teamId` | path | string | Yes | A team ID: `tem_…`; also accepts the legacy `tm_…` |

**Response:** `200` with [Team](#team) in `data`.

**Response headers:**

- `ETag`: The resource's version; send it back as If-Match to edit only that version

**[Errors](https://docs.qualithm.com/api.md#errors):** `400`, `401`, `403`, `404`, `429`, `500`, `503`

```bash
curl "<your-api-url>/v1/teams/<team-id>" \
  -H "Authorization: Bearer <your-api-token>"
```

## Rename the team

`PATCH /v1/teams/{teamId}`

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `team.update` permission, which the owner role holds.

**Parameters**

| Name | In | Type | Required | Description |
| ---- | -- | ---- | -------- | ----------- |
| `teamId` | path | string | Yes | A team ID: `tem_…`; also accepts the legacy `tm_…` |
| `If-Match` | header | string | No | The ETag you last read. The request is refused with 412 when the resource has changed since; omit it to apply the change regardless. |

**Request body:** [UpdateTeamRequest](#updateteamrequest)

**Response:** `204` with no body.

**Response headers:**

- `ETag`: The resource's version; send it back as If-Match to edit only that version

**[Errors](https://docs.qualithm.com/api.md#errors):** `400`, `401`, `403`, `404`, `412`, `413`, `415`, `429`, `500`, `503`

```bash
curl -X PATCH "<your-api-url>/v1/teams/<team-id>" \
  -H "Authorization: Bearer <your-api-token>" \
  -H "Content-Type: application/json" \
  -d '{"name":"<name>"}'
```

## Delete the team with its scopes, devices and memberships

`DELETE /v1/teams/{teamId}`

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `team.delete` permission, which the owner role holds.

**Parameters**

| Name | In | Type | Required | Description |
| ---- | -- | ---- | -------- | ----------- |
| `teamId` | path | string | Yes | A team ID: `tem_…`; also accepts the legacy `tm_…` |
| `If-Match` | header | string | No | The ETag you last read. The request is refused with 412 when the resource has changed since; omit it to apply the change regardless. |

**Response:** `204` with no body.

**[Errors](https://docs.qualithm.com/api.md#errors):** `400`, `401`, `403`, `404`, `412`, `429`, `500`, `503`

```bash
curl -X DELETE "<your-api-url>/v1/teams/<team-id>" \
  -H "Authorization: Bearer <your-api-token>"
```

## Types

### TeamPage

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `items` | array of [Team](#team) | Yes |  |
| `nextCursor` | string or null | Yes | Pass as `cursor` to read the next page; `null` on the last page |

### Team

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `id` | string | Yes | A team ID: `tem_…`; also accepts the legacy `tm_…` |
| `name` | string | Yes |  |
| `createdAt` | string (date-time) | Yes | UTC time, RFC 3339 |
| `updatedAt` | string (date-time) | Yes | UTC time, RFC 3339 |
| `memberId` | string | Yes | The caller's membership in this team |
| `memberRole` | [MemberRole](#memberrole) | Yes |  |
| `permissions` | array of one of `"team.read"`, `"team.update"`, `"team.delete"`, `"member.invite"`, `"member.update"`, `"member.remove"`, `"billing.read"`, `"billing.manage"`, `"usage.read"`, `"audit.read"`, `"token.read"`, `"token.create"`, `"token.revoke"`, `"token.revoke_any"`, `"scope.read"`, `"scope.write"`, `"device.read"`, `"device.write"`, `"device.command"`, `"credential.read"`, `"credential.manage"`, `"enrollment.read"`, `"enrollment.manage"`, `"authority.read"`, `"authority.manage"`, `"telemetry.read"`, `"capability.read"`, `"capability.update"`, `"dashboard.read"`, `"dashboard.write"`, `"automation.read"`, `"automation.write"`, `"automation.run"`, `"support.read"`, `"support.write"` | Yes | What the caller can do in this team: their role, lowered to a token's ceiling |

### MemberRole

A member's role in a team.

one of `"owner"`, `"manager"`, `"viewer"`.

### UpdateTeamRequest

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `name` | string | Yes | The new name |
