# Capabilities 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 capabilities of the team's devices

`GET /v1/teams/{teamId}/capabilities`

By `key`, then `id`, ascending.

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `capability.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 |
| `scopeId` | query | string | No | Only the devices in this scope and every scope under it |
| `type` | query | one of `"onoff"`, `"range"`, `"enum"`, `"trigger"`, `"sensor"` | No | Only capabilities of this type |
| `tag` | query | string | No | Only capabilities tagged this, or on a device tagged this |
| `key` | query | string | No | Only capabilities with this key |
| `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 [CapabilityPage](#capabilitypage) 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>/capabilities" \
  -H "Authorization: Bearer <your-api-token>"
```

## Rename or retag a capability

`PATCH /v1/teams/{teamId}/capabilities/{capabilityId}`

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

**Parameters**

| Name | In | Type | Required | Description |
| ---- | -- | ---- | -------- | ----------- |
| `teamId` | path | string | Yes | The team the request acts on |
| `capabilityId` | path | string | Yes | A capability ID: `cap_<zone>_…`; also accepts the legacy `cap_…` |
| `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:** [UpdateCapabilityRequest](#updatecapabilityrequest)

**Response:** `200` with [Capability](#capability) 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`, `412`, `413`, `415`, `429`, `500`, `503`

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

## List the capabilities a device declares

`GET /v1/teams/{teamId}/devices/{deviceId}/capabilities`

By `key`, then `id`, ascending.

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `capability.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 |
| `deviceId` | path | string | Yes | A device ID: `dvc_<zone>_…`; also accepts the legacy `dev_…` |
| `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 [CapabilityPage](#capabilitypage) 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>/devices/<device-id>/capabilities" \
  -H "Authorization: Bearer <your-api-token>"
```

## Types

### CapabilityPage

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

### Capability

Something a device declares it can do or report.

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `id` | string | Yes | A capability ID: `cap_<zone>_…`; also accepts the legacy `cap_…` |
| `deviceId` | string | Yes | A device ID: `dvc_<zone>_…`; also accepts the legacy `dev_…` |
| `key` | string | Yes |  |
| `type` | one of `"onoff"`, `"range"`, `"enum"`, `"trigger"`, `"sensor"` | Yes |  |
| `config` | object | Yes | The device's settings for the capability. A sensor's `metric` is 1 to 64 ASCII letters, digits, `_`, `.` or `-`. |
| `name` | string or null | Yes |  |
| `tags` | array of string | Yes |  |

### UpdateCapabilityRequest

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `name` | string or null | No | Display name of 1 to 64 characters; `null` clears it |
| `tags` | array of string | No | Replaces the capability's tags: at most 32, each 1 to 64 characters after trimming |
