# Create an enrollment

`POST https://api.cademi.com.br/api/v3/users/{user_id}/enrollments`

Operation ID: `users.enrollments.create` · API v3

Grants the user access to a delivery. The `Idempotency-Key` header is required.

If the user already has an enrollment for the same delivery, the existing enrollment is reactivated and returned with `200 OK` instead of creating a new one.

The credentials must have access to every product included in the delivery. A delivery that does not exist or is archived is rejected with a validation error on `delivery_id`.

Required permissions: `enrollments.create`.

## Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `user_id` | path | string | yes |  |

## Request body

Content type: `application/json`, required.

| Field | Type | Required | Description |
|---|---|---|---|
| `delivery_id` | string | yes |  |
| `sale_id` | string or null | no |  |
| `subscription_id` | string or null | no |  |

## Responses

### 200

An enrollment for this delivery already existed and was reactivated. Returns the existing enrollment.

Body: `data`: Enrollment.

Fields of Enrollment:

| Field | Type | Required | Description |
|---|---|---|---|
| `created_at` | string (date-time) | no |  |
| `deleted` | boolean | yes |  |
| `delivery_id` | string | yes |  |
| `ends_at` | string or null (date-time) | no |  |
| `id` | string | yes |  |
| `object` | string, one of `enrollment` | yes |  |
| `origin` | object | yes |  |
| `product_ids` | array of string | yes |  |
| `revision` | string | yes |  |
| `status` | string, one of `active`, `suspended`, `revoked` | yes |  |
| `subscription_ends_at` | string or null (date-time) | no |  |
| `updated_at` | string (date-time) | no |  |
| `user_id` | string | yes |  |

### 201

Returns the newly created enrollment.

Body: `data`: Enrollment.

Fields of Enrollment:

| Field | Type | Required | Description |
|---|---|---|---|
| `created_at` | string (date-time) | no |  |
| `deleted` | boolean | yes |  |
| `delivery_id` | string | yes |  |
| `ends_at` | string or null (date-time) | no |  |
| `id` | string | yes |  |
| `object` | string, one of `enrollment` | yes |  |
| `origin` | object | yes |  |
| `product_ids` | array of string | yes |  |
| `revision` | string | yes |  |
| `status` | string, one of `active`, `suspended`, `revoked` | yes |  |
| `subscription_ends_at` | string or null (date-time) | no |  |
| `updated_at` | string (date-time) | no |  |
| `user_id` | string | yes |  |

### 401

The credential is missing, malformed, expired, or revoked.

Body: Error.

### 403

The current credentials do not have the permission required by this operation.

Body: Error.

### 404

The user was not found, or the delivery includes a product that is not accessible with the current credentials.

Body: Error.

### 422

The request body or query parameters failed validation.

Body: ValidationFailed.

Full schema: https://cademi.dev/openapi/v3.json
