---
type: api
title: Create or update agent configuration
description: **Spaces method and path for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana/operation/operation-createupdateagentconfiguration
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana/operation/operation-createupdateagentconfiguration
products:
  - Kibana
---

# Create or update agent configuration

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

## Paths

- `PUT` `/api/apm/settings/agent-configuration`
- `PUT` `/s/{space_id}/api/apm/settings/agent-configuration`

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

## Description

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

Create or update an agent configuration. You must have `all` privileges for the APM and User Experience feature in Kibana. When updating an existing configuration, the `?overwrite=true` query parameter is required. If the configuration already exists and `overwrite` is not set to `true`, the API returns a 400 error. When successful and Fleet is enabled, APM package policies are synchronized accordingly.

## Query String Parameters

- `overwrite` (boolean)
  If the config exists ?overwrite=true is required

## Request Body

`application/json`

- `agent_name` (string) — optional
  The agent name is used by the UI to determine which settings to display.
- `service` ({}) — required
  Service
  - `environment` (string) — optional
    The environment of the service.
  - `name` (string) — optional
    The name of the service.
- `settings` (object) — required
  Agent configuration settings

## Responses

#### `200`

Successful response

`application/json`

Type: `object`

#### `400`

Bad Request response

`application/json`

- `error` (string)
  Error type
- `message` (string)
  Error message
- `statusCode` (number)
  Error status code
#### `401`

Unauthorized response

`application/json`

- `error` (string)
  Error type
- `message` (string)
  Error message
- `statusCode` (number)
  Error status code
#### `403`

Forbidden response

`application/json`

- `error` (string)
  Error type
- `message` (string)
  Error message
- `statusCode` (number)
  Error status code
#### `404`

Not found response

`application/json`

- `error` (string)
  Error type
- `message` (string)
  Error message
- `statusCode` (number)
  Error status code
## Code Examples

#### Console

```console
PUT /api/apm/settings/agent-configuration
{
  "agent_name": "nodejs",
  "service": {
    "environment": "production",
    "name": "frontend"
  },
  "settings": {
    "capture_body": "off",
    "transaction_max_spans": "500",
    "transaction_sample_rate": "0.4"
  }
}
```

#### curl

```curl
curl -X PUT "https://{kibana_url}/api/apm/settings/agent-configuration" \
  -H "elastic-api-version: string" \
  -H "kbn-xsrf: true" \
  -H "Content-Type: application/json" \
  -d '{
  "agent_name": "nodejs",
  "service": {
    "environment": "production",
    "name": "frontend"
  },
  "settings": {
    "capture_body": "off",
    "transaction_max_spans": "500",
    "transaction_sample_rate": "0.4"
  }
}'
```

## Response Examples

#### Create update agent configuration response example1

An example of a successful response from `PUT /api/apm/settings/agent-configuration`. The response body is intentionally empty.

```json
{}
```

#### Bad request

An example of a 400 Bad Request response, returned when the request payload or query parameters fail validation.

```json
{
  "error": "Bad Request",
  "message": "[request body]: expected value of type [string] but got [undefined]",
  "statusCode": 400
}
```

#### Unauthorized

An example of a 401 Unauthorized response, returned when the request is missing valid authentication credentials.

```json
{
  "error": "Unauthorized",
  "message": "[security_exception]: missing authentication credentials for REST request",
  "statusCode": 401
}
```

#### Forbidden

An example of a 403 Forbidden response, returned when the authenticated user lacks the required APM and User Experience privileges.

```json
{
  "error": "Forbidden",
  "message": "Insufficient privileges to perform this action. The APM and User Experience feature requires \u0060all\u0060 privileges.",
  "statusCode": 403
}
```

#### Not found

An example of a 404 Not Found response, returned when the requested resource does not exist or the feature is not available on the current deployment.

```json
{
  "error": "Not Found",
  "message": "Not Found",
  "statusCode": 404
}
```

