---
type: api
title: Create enrollment API key
description: **Spaces method and path for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4641/api/doc/kibana/v8/operation/operation-create-enrollment-api-keys
resource: https://www.elastic.co/elastic/docs-builder/docs/4641/api/doc/kibana/v8/operation/operation-create-enrollment-api-keys
products:
  - Kibana
---

# Create enrollment API key

Authentication: required

- Server: `https://{kibana_url}`

## Paths

- `POST` `/api/fleet/enrollment_api_keys`
- `POST` `/s/{space_id}/api/fleet/enrollment_api_keys`

#### Path parameters

- `space_id` (string) — optional
  An identifier for the space. If `space_id` is not provided in the URL, the default space is used. Refer to [Spaces](https://www.elastic.co/docs/deploy-manage/manage-spaces) for more information.

## Header parameters

- `kbn-xsrf` (string) — required
  Kibana's anti Cross-Site Request Forgery token. Can be any string value.

## Request body

`application/json`

- `name` (string) — optional
  The name of the enrollment API key. Must be unique.
- `policy_id` (string) — required
  The ID of the agent policy the Elastic Agent will be enrolled in.

## Responses

#### `200`

OK

`application/json`

- `action` (enum)
  Values: `created`
- `item` (object)
  - `active` (boolean)
    When false, the enrollment API key is revoked and cannot be used for enrolling Elastic Agents.
  - `api_key` (string)
    The enrollment API key (token) used for enrolling Elastic Agents.
  - `api_key_id` (string)
    The ID of the API key in the Security API.
  - `created_at` (string)
  - `id` (string)
  - `name` (string)
    The name of the enrollment API key.
  - `policy_id` (string)
    The ID of the agent policy the Elastic Agent will be enrolled in.
#### `400`

Generic Error

`application/json`

- `error` (string)
- `message` (string)
- `statusCode` (number)
## Code examples

#### Console

```console
POST kbn:/api/fleet/enrollment_api_keys
{
  "policy_id": "string"
}
```

#### curl

```curl
curl -X POST "${KIBANA_URL}/api/fleet/enrollment_api_keys" \
  -H "kbn-xsrf: true" \
  -H "Authorization: ApiKey ${API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
    "policy_id": "string"
  }'
```

## Response examples

#### 200

`application/json`

Generated from the API spec. Values are representative. Unions use the first variant; deeply nested or large bodies may omit fields.

```json
{
  "action": "created",
  "item": {
    "active": false,
    "api_key": "string",
    "api_key_id": "string",
    "created_at": "string",
    "id": "string",
    "name": "string",
    "policy_id": "string"
  }
}
```

#### 400

`application/json`

Generated from the API spec. Values are representative. Unions use the first variant; deeply nested or large bodies may omit fields.

```json
{
  "error": "string",
  "message": "string",
  "statusCode": 0
}
```

