---
type: api
title: Unenroll an agent
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-agentid-unenroll
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana-serverless/operation/operation-post-fleet-agents-agentid-unenroll
products:
  - Kibana
---

# Unenroll an agent

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

## Paths

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

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

#### Path Parameters

- `agentId` (string)
  The agent ID

## Description

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

Unenroll a specific agent, optionally revoking its enrollment API key.<br/><br/>[Required authorization] Route required privileges: fleet-agents-all.

## Request Body

`application/json`

- `force` (boolean) — optional
- `revoke` (boolean) — optional

## Responses

#### `200`

Successful response

#### `400`

Bad Request

## Code Examples

#### Console

```console
POST /api/fleet/agents/{agentId}/unenroll
{
  "revoke": false
}
```

#### curl

```curl
curl -X POST "https://{kibana_url}/api/fleet/agents/{agentId}/unenroll" \
  -H "kbn-xsrf: true" \
  -H "Content-Type: application/json" \
  -d '{
  "revoke": false
}'
```

## Response Examples

#### Post unenroll agent

Agent successfully unenrolled

```json
{}
```

#### Generic error response

Example of a generic error response

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

