# Enrollments 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 team's claim codes

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

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

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `enrollment.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 |
| `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 [EnrollmentPage](#enrollmentpage) 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>/enrollments" \
  -H "Authorization: Bearer <your-api-token>"
```

## Create a claim code that lets a device add itself to a scope

`POST /v1/teams/{teamId}/enrollments`

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `enrollment.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 |
| `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:** [CreateEnrollmentRequest](#createenrollmentrequest)

**Response:** `201` with [EnrollmentCode](#enrollmentcode) 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>/enrollments" \
  -H "Authorization: Bearer <your-api-token>" \
  -H "Content-Type: application/json" \
  -d '{"scopeId":"<scope-id>"}'
```

## Revoke a pending claim code

`DELETE /v1/teams/{teamId}/enrollments/{enrollmentId}`

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `enrollment.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 |
| `enrollmentId` | path | string | Yes | A claim code ID: `enr_<zone>_…`; also accepts the legacy `enr_…` |

**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>/enrollments/<enrollment-id>" \
  -H "Authorization: Bearer <your-api-token>"
```

## Types

### EnrollmentPage

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

### Enrollment

A one-time claim code a device exchanges for its first credential.

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `id` | string | Yes | A claim code ID: `enr_<zone>_…`; also accepts the legacy `enr_…` |
| `teamId` | string | Yes | A team ID: `tem_…`; also accepts the legacy `tm_…` |
| `scopeId` | string | Yes | A scope ID: `scp_<zone>_…`; also accepts the legacy `spc_…` |
| `label` | string | Yes |  |
| `status` | one of `"pending"`, `"claimed"`, `"revoked"` | Yes |  |
| `claimedDeviceId` | string or null | Yes |  |
| `claimedAt` | string (date-time) or null | Yes |  |
| `expiresAt` | string (date-time) | Yes | UTC time, RFC 3339 |
| `lastFailure` | one of `"device_already_claimed"` or null | Yes | Why the latest rejected claim of this code failed, when the team can act on it: `device_already_claimed` means a device presented the code after it was claimed. The claim response stays the generic `401`. |
| `lastFailureScope` | object or null | Yes | The scope the already-claimed device belongs to |
| `lastFailureAt` | string (date-time) or null | Yes | When the latest failure happened |
| `createdAt` | string (date-time) | Yes | UTC time, RFC 3339 |
| `updatedAt` | string (date-time) | Yes | UTC time, RFC 3339 |

### CreateEnrollmentRequest

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `scopeId` | string | Yes | The scope the device joins |
| `label` | string | No | Up to 64 characters |
| `expiresInMinutes` | integer | No | How long the code can be claimed. Default 1440 (24 hours). |

### EnrollmentCode

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `enrollment` | [Enrollment](#enrollment) | Yes |  |
| `code` | string | Yes | The claim code, shown only once |
| `provisioningUrl` | string | Yes | Where the device claims its code: the setup file's provisioningUrl |
