# API tokens 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 API tokens in this team: everyone's for an owner, otherwise the caller's own

`GET /v1/teams/{teamId}/api-tokens`

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

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

**Parameters**

| Name | In | Type | Required | Description |
| ---- | -- | ---- | -------- | ----------- |
| `teamId` | path | string | Yes | The team the request acts on |
| `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 [ApiTokenPage](#apitokenpage) in `data`.

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

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

## Revoke an API token: any in the team for an owner, otherwise the caller's own

`DELETE /v1/teams/{teamId}/api-tokens/{tokenId}`

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

**Parameters**

| Name | In | Type | Required | Description |
| ---- | -- | ---- | -------- | ----------- |
| `teamId` | path | string | Yes | The team the request acts on |
| `tokenId` | path | string | Yes | An API token ID: `tok_…` |

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

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

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

## Types

### ApiTokenPage

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

### ApiToken

An API token's metadata. The secret is never listed.

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `id` | string | Yes | An API token ID: `tok_…` |
| `accountId` | string | Yes | An account ID: `acc_…` |
| `teamId` | string | Yes | A team ID: `tem_…`; also accepts the legacy `tm_…` |
| `name` | string | Yes |  |
| `status` | one of `"active"`, `"revoked"` | Yes |  |
| `role` | [MemberRole](#memberrole) or null | Yes | The token's role ceiling; null means the creator's current role |
| `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"` | No | What the token can do now: its creator's current role lowered to its ceiling. Listed tokens only. |
| `expiresAt` | string (date-time) or null | Yes |  |
| `lastUsedAt` | string (date-time) or null | Yes |  |
| `createdAt` | string (date-time) | Yes | UTC time, RFC 3339 |
| `updatedAt` | string (date-time) | Yes | UTC time, RFC 3339 |

### MemberRole

A member's role in a team.

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