---
type: api
title: Download an agent policy
description: **Spaces method and path for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana-serverless/operation/operation-get-fleet-agent-policies-agentpolicyid-download
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana-serverless/operation/operation-get-fleet-agent-policies-agentpolicyid-download
products:
  - Kibana
---

# Download an agent policy

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

## Paths

- `GET` `/api/fleet/agent_policies/{agentPolicyId}/download`
- `GET` `/s/{space_id}/api/fleet/agent_policies/{agentPolicyId}/download`

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

#### Path Parameters

- `agentPolicyId` (string)
  The ID of the agent policy

## Description

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

Download an agent policy by ID.<br/><br/>[Required authorization] Route required privileges: fleet-agent-policies-read OR fleet-setup.

## Query String Parameters

- `download` (boolean)
  If true, returns the policy as a downloadable file
- `standalone` (boolean)
  If true, returns the policy formatted for standalone agents
- `kubernetes` (boolean)
  If true, returns the policy formatted for Kubernetes deployment
- `revision` (number)
  If provided, returns the policy at the specified revision. Cannot be used with standalone or kubernetes flags.

## Responses

#### `200`

Successful response — returns the agent policy as a YAML file download

`application/json`

Type: `string`

#### `400`

Bad Request

`application/json`

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

Not Found

`application/json`

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

#### Console

```console
GET /api/fleet/agent_policies/{agentPolicyId}/download
```

#### curl

```curl
curl -X GET "https://{kibana_url}/api/fleet/agent_policies/{agentPolicyId}/download"
```

## Response Examples

#### Get download agent policy

The agent policy download response

```json
{
  "item": "id: agent-policy-id-1\\nrevision: 1\\noutputs:\\n  default:\\n    type: elasticsearch\\n    hosts:\\n      - https://elasticsearch.example.com:9200\\n"
}
```

#### Generic error response

Example of a generic error response

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

#### Not found

No agent policy was found with the given ID

```json
{
  "error": "Not Found",
  "message": "Agent policy not found",
  "statusCode": 404
}
```

