# Credentials 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 a device's credentials

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

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

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `credential.read` permission, which the owner and manager 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 [CredentialPage](#credentialpage) 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>/credentials" \
  -H "Authorization: Bearer <your-api-token>"
```

## Mint a token credential for a device

`POST /v1/teams/{teamId}/devices/{deviceId}/credentials`

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `credential.manage` permission, which the owner and manager 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_…` |
| `Idempotency-Key` | header | string | No | A unique key for this request. A retry with the same key and body returns the first response instead of acting again; keys last 24 hours. |

**Request body:** [CreateDeviceCredentialRequest](#createdevicecredentialrequest)

**Response:** `201` with [CredentialSecret](#credentialsecret) in `data`.

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

```bash
curl -X POST "<your-api-url>/v1/teams/<team-id>/devices/<device-id>/credentials" \
  -H "Authorization: Bearer <your-api-token>" \
  -H "Content-Type: application/json" \
  -d '{"label":"<label>","expiresAt":"2026-10-26T09:30:00Z"}'
```

## Issue a client certificate for a device from its CSR

`POST /v1/teams/{teamId}/devices/{deviceId}/credentials/cert`

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `credential.manage` permission, which the owner and manager 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_…` |
| `Idempotency-Key` | header | string | No | A unique key for this request. A retry with the same key and body returns the first response instead of acting again; keys last 24 hours. |

**Request body:** [CreateDeviceCertificateRequest](#createdevicecertificaterequest)

**Response:** `201` with [IssuedCertificate](#issuedcertificate) in `data`.

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

```bash
curl -X POST "<your-api-url>/v1/teams/<team-id>/devices/<device-id>/credentials/cert" \
  -H "Authorization: Bearer <your-api-token>" \
  -H "Content-Type: application/json" \
  -d '{"csrPem":"<csr-pem>"}'
```

## Revoke a device's credential

`DELETE /v1/teams/{teamId}/devices/{deviceId}/credentials/{credentialId}`

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `credential.manage` permission, which the owner and manager 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_…` |
| `credentialId` | path | string | Yes | A credential ID: `crd_<zone>_…`; also accepts the legacy `cred_…` |

**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>/devices/<device-id>/credentials/<credential-id>" \
  -H "Authorization: Bearer <your-api-token>"
```

## Rotate a device's token credential

`POST /v1/teams/{teamId}/devices/{deviceId}/credentials/{credentialId}/rotate`

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `credential.manage` permission, which the owner and manager 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_…` |
| `credentialId` | path | string | Yes | A credential ID: `crd_<zone>_…`; also accepts the legacy `cred_…` |
| `revoke` | query | string | No | `true` revokes the old credential now; otherwise it stays active until it expires |
| `Idempotency-Key` | header | string | No | A unique key for this request. A retry with the same key and body returns the first response instead of acting again; keys last 24 hours. |

**Request body:** [RotateDeviceCredentialRequest](#rotatedevicecredentialrequest)

**Response:** `201` with [CredentialSecret](#credentialsecret) in `data`.

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

```bash
curl -X POST "<your-api-url>/v1/teams/<team-id>/devices/<device-id>/credentials/<credential-id>/rotate" \
  -H "Authorization: Bearer <your-api-token>" \
  -H "Content-Type: application/json" \
  -d '{"expiresAt":"2026-10-26T09:30:00Z"}'
```

## Types

### CredentialPage

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

### Credential

A device's credential. The secret or key material is never returned after it is issued.

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `id` | string | Yes | A credential ID: `crd_<zone>_…`; also accepts the legacy `cred_…` |
| `deviceId` | string | Yes | A device ID: `dvc_<zone>_…`; also accepts the legacy `dev_…` |
| `authorityId` | string or null | Yes | The authority that issued a cert credential |
| `kind` | one of `"token"`, `"cert"` | Yes |  |
| `certFingerprint` | string or null | Yes | SHA-256 of a cert credential's certificate |
| `certSubject` | string or null | Yes |  |
| `label` | string | Yes |  |
| `status` | one of `"active"`, `"revoked"` | Yes |  |
| `expiresAt` | string (date-time) or null | Yes |  |
| `lastUsedAt` | string (date-time) or null | Yes |  |
| `rotatedFrom` | string or null | Yes | The credential this one replaced on rotation |
| `createdAt` | string (date-time) | Yes | UTC time, RFC 3339 |
| `updatedAt` | string (date-time) | Yes | UTC time, RFC 3339 |

### CreateDeviceCredentialRequest

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `label` | string | No | Up to 64 characters |
| `expiresAt` | string (date-time) | No | A time in the future, within 30 days. Default 30 days from now. |

### CredentialSecret

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `credential` | [Credential](#credential) | Yes |  |
| `secret` | string | Yes | The bearer token (the MQTT password), shown only once |
| `broker` | [GatewayEndpoint](#gatewayendpoint) | No | The gateway the device connects to now; returned when a device renews |
| `apiUrl` | string | No | The base URL of the device's zone API, where the device sends its renewals and certificate requests; returned when a device renews |

### GatewayEndpoint

Where a device connects: a zone's MQTT gateway.

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `host` | string | Yes |  |
| `port` | integer (int64) | Yes |  |

### CreateDeviceCertificateRequest

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `csrPem` | string | Yes | The device's PEM certificate signing request |
| `label` | string | No | Up to 64 characters |
| `expiresInDays` | integer | No | Certificate lifetime in days, at most 30 for a development device. Default 30. |

### IssuedCertificate

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `credential` | [Credential](#credential) | Yes |  |
| `certificatePem` | string | Yes | The signed device certificate, shown only once |
| `caCertificatePem` | string | Yes | The issuing CA's certificate |
| `broker` | [GatewayEndpoint](#gatewayendpoint) | Yes |  |
| `apiUrl` | string | Yes | The base URL of the device's zone API, where the device sends its renewals and certificate requests |

### RotateDeviceCredentialRequest

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `expiresAt` | string (date-time) | No | A time in the future, within 30 days. Default 30 days from now. |
