---
type: api
title: Bulk unenroll agents
description: **Spaces method and path for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana-serverless/operation/operation-post-fleet-agents-bulk-unenroll
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana-serverless/operation/operation-post-fleet-agents-bulk-unenroll
products:
  - Kibana
---

# Bulk unenroll agents

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

## Paths

- `POST` `/api/fleet/agents/bulk_unenroll`
- `POST` `/s/{space_id}/api/fleet/agents/bulk_unenroll`

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

## Description

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

Unenroll multiple agents, optionally revoking their enrollment API keys.<br/><br/>[Required authorization] Route required privileges: fleet-agents-all.

## Request Body

`application/json`

- `agents` (union [] string | string) — required
- `batchSize` (number) — optional
- `dryRun` (boolean) — optional
- `force` (boolean) — optional
  Unenrolls hosted agents too
- `includeInactive` (boolean) — optional
  When passing agents by KQL query, unenrolls inactive agents too
- `revoke` (boolean) — optional
  Revokes API keys of agents

## Responses

#### `200`

Successful response

`application/json`

Any of:
- **{ actionId }**
  - `actionId` (string)
- **{ count }**
  - `count` (number)
#### `400`

Bad Request

`application/json`

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

#### Console

```console
POST /api/fleet/agents/bulk_unenroll
{
  "agents": [
    "agent-id-1",
    "agent-id-2"
  ],
  "revoke": false
}
```

#### curl

```curl
curl -X POST "https://{kibana_url}/api/fleet/agents/bulk_unenroll" \
  -H "kbn-xsrf: true" \
  -H "Content-Type: application/json" \
  -d '{
  "agents": [
    "agent-id-1",
    "agent-id-2"
  ],
  "revoke": false
}'
```

## Response Examples

#### Post bulk unenroll agents

Bulk unenroll action result

```json
{
  "actionId": "action-id-1"
}
```

#### Generic error response

Example of a generic error response

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

