---
type: api
title: Copy an agent policy
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-agent-policies-agentpolicyid-copy
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana/v9/operation/operation-post-fleet-agent-policies-agentpolicyid-copy
products:
  - Kibana
---

# Copy an agent policy

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

## Paths

- `POST` `/api/fleet/agent_policies/{agentPolicyId}/copy`
- `POST` `/s/{space_id}/api/fleet/agent_policies/{agentPolicyId}/copy`

- [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

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

## Description

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

Copy an agent policy by ID.<br/><br/>[Required authorization] Route required privileges: fleet-agent-policies-all.

## Query String Parameters

- `format` (enum)
  Format for the response: simplified or legacy
  Values: `simplified`, `legacy`

## Request Body

`application/json`

- `description` (string) — optional
- `name` (string · min: 1) — required

## Responses

#### `200`

Successful response

`application/json`

- `item` ({})
  - `advanced_settings` (object)
    - `agent_download_target_directory` (object)
    - `agent_download_timeout` (object)
    - `agent_features_disable_policy_change_acks_enabled` (object)
    - `agent_internal` (object)
    - `agent_limits_go_max_procs` (object)
    - `agent_logging_files_interval` (object)
    - `agent_logging_files_keepfiles` (object)
    - `agent_logging_files_rotateeverybytes` (object)
    - `agent_logging_level` (object)
    - `agent_logging_metrics_period` (object)
    - `agent_logging_to_files` (object)
    - `agent_monitoring_runtime_experimental` (object)
  - `agent_features` ([] object · max: 100)
    - `enabled` (boolean)
    - `name` (string)
  - `agentless` (object)
    - `cloud_connectors` (object)
      - `enabled` (boolean)
      - `target_csp` (enum)
        Values: `aws`, `azure`, `gcp`
    - `cluster_id` (string)
    - `resources` (object)
      - `requests` (object)
        - `cpu` (string)
        - `memory` (string)
  - `agents` (number)
  - `agents_per_version` ([] object · max: 1000)
    - `count` (number)
    - `version` (string)
  - `created_at` (string)
  - `data_output_id` (string) — nullable
  - `description` (string)
  - `download_source_id` (string) — nullable
  - `fips_agents` (number)
  - `fleet_server_host_id` (string) — nullable
  - `global_data_tags` ([] object · max: 100)
    User defined data tags that are added to all of the inputs. The values can be strings or numbers.
    - `name` (string)
    - `value` (number | string)
  - `has_agent_version_conditions` (boolean)
  - `has_fleet_server` (boolean)
  - `id` (string)
  - `inactivity_timeout` (number · min: 0 · default: 1209600)
  - `is_default` (boolean)
  - `is_default_fleet_server` (boolean)
  - `is_managed` (boolean)
  - `is_preconfigured` (boolean)
  - `is_protected` (boolean)
    Indicates whether the agent policy has tamper protection enabled. Defaults to `false`.
  - `is_verifier` (boolean)
  - `keep_monitoring_alive` (boolean) — nullable
    When set to true, monitoring will be enabled but logs/metrics collection will be disabled
  - `min_agent_version` (string) — nullable
  - `monitoring_diagnostics` (object)
    - `limit` (object)
      - `burst` (number)
      - `interval` (string)
    - `uploader` (object)
      - `init_dur` (string)
      - `max_dur` (string)
      - `max_retries` (number)
  - `monitoring_enabled` ([] enum  · max: 3)
    Values: `logs`, `metrics`, `traces`
  - `monitoring_http` (object)
    - `buffer` (object)
      - `enabled` (boolean · default: false)
    - `enabled` (boolean)
    - `host` (string)
    - `port` (number · min: 0 · max: 65353)
  - `monitoring_output_id` (string) — nullable
  - `monitoring_pprof_enabled` (boolean)
  - `name` (string · min: 1)
  - `namespace` (string · min: 1)
  - `overrides` (map string to object) — nullable
    Override settings that are defined in the agent policy. Input settings cannot be overridden. The override option should be used only in unusual circumstances and not as a routine procedure.
  - `package_agent_version_conditions` ([] object · max: 1000) — nullable
    - `name` (string)
    - `title` (string)
    - `version_condition` (string)
  - `package_policies` (union anyOf)
    - **[]string**
    - **[]Kibana_HTTP_APIs_package_policy_response**
      - `additional_datastreams_permissions` ([] string · max: 1000) — nullable
        Additional data stream permissions that will be added to the agent policy.
      - `agents` (number)
      - `cloud_connector_id` (string) — nullable
        ID of the cloud connector associated with this package policy.
      - `cloud_connector_name` (string · min: 1 · max: 255) — nullable
        Transient field for cloud connector name during creation.
      - `condition` (string · max: 10000) — nullable
        Agent condition expression to evaluate whether to apply this integration to its inputs.
      - `created_at` (string)
      - `created_by` (string)
      - `description` (string)
        Package policy description
      - `elasticsearch` (object)
        - `privileges` (object)
          - `cluster` ([] string · max: 100)
      - `enabled` (boolean)
      - `global_data_tags` ([] object · max: 100) — nullable
        - `name` (string)
          The name of the custom field. Cannot contain spaces.
        - `value` (number | string)
          The value of the custom field.
      - `id` (string)
      - `inputs` (union anyOf)
        Package policy inputs.
        - **[]object**
          - `compiled_input` (object)
          - `condition` (string · max: 10000) — nullable
            Agent condition expression to evaluate whether to apply this input.
          - `config` (map string to object)
            Package variable (see integration documentation for more information)
            Map values (object)
            - `frozen` (boolean)
            - `type` (string)
            - `value` (object)
          - `deprecated` ({})
            - `description` (string · max: 4096)
            - `replaced_by` (map string to string)
            - `since` (string · max: 50)
          - `enabled` (boolean)
          - `id` (string)
          - `keep_enabled` (boolean)
          - `migrate_from` (string)
          - `name` (string)
          - `policy_template` (string)
          - `streams` ([] object · max: 1000)
            - `compiled_stream` (object)
            - `condition` (string · max: 10000) — nullable
              Agent condition expression to evaluate whether to apply this stream.
            - `config` (map string to object)
              Package variable (see integration documentation for more information)
              Map values (object)
              - `frozen` (boolean)
              - `type` (string)
              - `value` (object)
            - `data_stream` (object)
              - `dataset` (string)
              - `elasticsearch` (object)
                - `dynamic_dataset` (boolean)
                - `dynamic_namespace` (boolean)
                - `privileges` (object)
                  - `indices` ([] string · max: 100)
              - `type` (string)
            - `deprecated` ({})
              - `description` (string · max: 4096)
              - `replaced_by` (map string to string)
              - `since` (string · max: 50)
            - `enabled` (boolean)
            - `id` (string)
            - `keep_enabled` (boolean)
            - `migrate_from` (string)
            - `release` (enum)
              Values: `ga`, `beta`, `experimental`
            - `var_group_selections` (map string to string)
              Variable group selections. Maps var_group name to the selected option name within that group.
            - `vars` (map string to object)
              Package variable (see integration documentation for more information)
              Map values (object)
              - `frozen` (boolean)
              - `type` (string)
              - `value` (object)
          - `type` (string)
          - `var_group_selections` (map string to string)
            Variable group selections. Maps var_group name to the selected option name within that group.
          - `vars` (map string to object)
            Package variable (see integration documentation for more information)
            Map values (object)
            - `frozen` (boolean)
            - `type` (string)
            - `value` (object)
        - **string to object**
          Package policy inputs. Refer to the integration documentation to know which inputs are available.
          - `<string>` (object)
            - `condition` (string · max: 10000) — nullable
              Agent condition expression to evaluate whether to apply this input.
            - `deprecated` ({})
              - `description` (string · max: 4096)
              - `replaced_by` (map string to string)
              - `since` (string · max: 50)
            - `enabled` (boolean)
              Enable or disable that input. Defaults to `true` (enabled).
            - `streams` (map string to object)
              Input streams. Refer to the integration documentation to know which streams are available.
              Map values (object)
              - `condition` (string · max: 10000) — nullable
                Agent condition expression to evaluate whether to apply this stream.
              - `deprecated` ({})
                - `description` (string · max: 4096)
                - `replaced_by` (map string to string)
                - `since` (string · max: 50)
              - `enabled` (boolean)
                Enable or disable that stream. Defaults to `true` (enabled).
              - `var_group_selections` (map string to string)
                Variable group selections. Maps var_group name to the selected option name within that group.
              - `vars` (map string to anyOf)
                Input/stream level variable. Refer to the integration documentation for more information.
            - `vars` (map string to anyOf)
              Input/stream level variable. Refer to the integration documentation for more information.
      - `is_managed` (boolean)
      - `name` (string)
        Unique name for the package policy.
      - `namespace` (string · max: 100)
        The package policy namespace. Leave blank to inherit the agent policy's namespace.
      - `output_id` (string) — nullable
      - `overrides` (object) — nullable
        Override settings that are defined in the package policy. The override option should be used only in unusual circumstances and not as a routine procedure.
        - `inputs` (map string to object)
      - `package` ({})
        - `experimental_data_stream_features` ([] object · max: 100)
          - `data_stream` (string · max: 1024)
          - `features` (object)
            - `doc_value_only_numeric` (boolean)
            - `doc_value_only_other` (boolean)
            - `synthetic_source` (boolean)
            - `tsdb` (boolean)
        - `fips_compatible` (boolean)
        - `name` (string · max: 255)
          Package name
        - `requires_root` (boolean)
        - `title` (string · max: 255)
        - `version` (string · max: 50)
          Package version
      - `package_agent_version_condition` (string)
      - `policy_id` (string) — nullable — deprecated
        ID of the agent policy which the package policy will be added to.
      - `policy_ids` ([] string · max: 1000)
      - `revision` (number)
        Package policy revision.
      - `secret_references` ([] object · max: 1000)
        - `id` (string)
      - `spaceIds` ([] string · max: 100)
      - `supports_agentless` (boolean) — nullable
        Indicates whether the package policy belongs to an agentless agent policy.
      - `supports_cloud_connector` (boolean) — nullable
        Indicates whether the package policy supports cloud connectors.
      - `updated_at` (string)
      - `updated_by` (string)
      - `var_group_selections` (map string to string)
        Variable group selections. Maps var_group name to the selected option name within that group.
      - `vars` (union anyOf)
        Package level variable.
        - **string to object**
          Package variable (see integration documentation for more information)
          - `<string>` (object)
            - `frozen` (boolean)
            - `type` (string)
            - `value` (object)
        - **string to anyOf**
          Input/stream level variable. Refer to the integration documentation for more information.
      - `version` (string)
        Package policy ES version.
  - `required_versions` ([] object · max: 100) — nullable
    - `percentage` (number · min: 0 · max: 100)
      Target percentage of agents to auto upgrade
    - `version` (string)
      Target version for automatic agent upgrade
  - `revision` (number)
  - `schema_version` (string)
  - `space_ids` ([] string · max: 100)
  - `status` (enum)
    Values: `active`, `inactive`
  - `supports_agentless` (boolean) — nullable
    Indicates whether the agent policy supports agentless integrations.
  - `unenroll_timeout` (number · min: 0)
  - `unprivileged_agents` (number)
  - `updated_at` (string)
  - `updated_by` (string)
  - `version` (string)
#### `400`

Bad Request

`application/json`

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

#### Console

```console
POST /api/fleet/agent_policies/{agentPolicyId}/copy
{
  "description": "A copy of the original agent policy",
  "name": "Copy of my agent policy"
}
```

#### curl

```curl
curl -X POST "https://{kibana_url}/api/fleet/agent_policies/{agentPolicyId}/copy" \
  -H "kbn-xsrf: true" \
  -H "Content-Type: application/json" \
  -d '{
  "description": "A copy of the original agent policy",
  "name": "Copy of my agent policy"
}'
```

## Response Examples

#### Post copy agent policy

The copied agent policy

```json
{
  "item": {
    "description": "A copy of the original agent policy",
    "id": "agent-policy-id-copy-1",
    "is_managed": false,
    "is_protected": false,
    "name": "Copy of my agent policy",
    "namespace": "default",
    "revision": 1,
    "status": "active",
    "updated_at": "2024-01-15T11:00:00.000Z",
    "updated_by": "user1"
  }
}
```

#### Generic error response

Example of a generic error response

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

