---
type: api
title: Create an agent action
description: **Spaces method and path for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana/v9/operation/operation-post-fleet-agents-agentid-actions
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana/v9/operation/operation-post-fleet-agents-agentid-actions
products:
  - Kibana
---

# Create an agent action

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

## Paths

- `POST` `/api/fleet/agents/{agentId}/actions`
- `POST` `/s/{space_id}/api/fleet/agents/{agentId}/actions`

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/kibana/v9/authentication#apikeyauth)
- [Basic auth](/elastic/docs-builder/docs/4371/api/doc/kibana/v9/authentication#basicauth)

#### Path Parameters

- `agentId` (string)
  The agent ID

## Description

Refer to [Spaces](https://www.elastic.co/docs/deploy-manage/manage-spaces) for more information.

Create a new action for a specific agent.<br/><br/>[Required authorization] Route required privileges: fleet-agents-all.

## Request Body

`application/json`

- `action` (union anyOf) — required
  - **{ ack_data }**
    - `ack_data` (object) — required
    - `data` (object) — required
    - `type` (enum) — required
      Values: `UNENROLL`, `UPGRADE`, `POLICY_REASSIGN`
  - **type: SETTINGS**
    - `data` (object) — required
      - `log_level` (enum  · default: null) — optional — nullable
        Values: `debug`, `info`, `warning`, `error`, `null`
    - `type` (enum) — required
      Values: `SETTINGS`

## Responses

#### `200`

Successful response

`application/json`

- `item` (object)
  - `ack_data` (object)
  - `agents` ([] string · max: 10000)
  - `created_at` (string)
  - `data` (object)
  - `expiration` (string)
  - `id` (string)
  - `minimum_execution_duration` (number)
  - `namespaces` ([] string · max: 100)
  - `rollout_duration_seconds` (number)
  - `sent_at` (string)
  - `source_uri` (string)
  - `start_time` (string)
  - `total` (number)
  - `type` (string)
#### `400`

Bad Request

`application/json`

- `attributes` (object)
- `error` (string)
- `errorType` (string)
- `message` (string)
- `statusCode` (number)
## Code Examples

#### Console

```console
POST /api/fleet/agents/{agentId}/actions
{
  "action": {
    "type": "UNENROLL"
  }
}
```

#### curl

```curl
curl -X POST "https://{kibana_url}/api/fleet/agents/{agentId}/actions" \
  -H "kbn-xsrf: true" \
  -H "Content-Type: application/json" \
  -d '{
  "action": {
    "type": "UNENROLL"
  }
}'
```

## Response Examples

#### Post agent action

Created agent action

```json
{
  "item": {
    "agents": [
      "agent-id-1"
    ],
    "created_at": "2024-01-01T00:00:00.000Z",
    "id": "action-id-1",
    "type": "UNENROLL"
  }
}
```

#### Generic error response

Example of a generic error response

```json
{
  "error": "Bad Request",
  "message": "An error message describing what went wrong",
  "statusCode": 400
}
```

