---
type: api
title: "Get environments for service"
description: "Retrieve the available environments for a given service, to be used in agent configuration. You must have read privileges for the APM and User Experience feature in Kibana. If serviceName is omitted, environments across all services are returned."
url: https://www.elastic.co/elastic/docs-builder/docs/5066/api/kibana-serverless/operation/operation-getenvironmentsforservice
resource: https://www.elastic.co/elastic/docs-builder/docs/5066/api/kibana-serverless/operation/operation-getenvironmentsforservice
products:
  - Kibana
---

# Get environments for service

Authentication: required

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

## Paths

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

#### Path parameters

- `space_id` (string) — optional
  An identifier for the space. If `space_id` is not provided in the URL, the default space is used. Refer to [Spaces](https://www.elastic.co/docs/deploy-manage/manage-spaces) for more information.

## Description

Retrieve the available environments for a given service, to be used in agent configuration. You must have `read` privileges for the APM and User Experience feature in Kibana. If `serviceName` is omitted, environments across all services are returned.

## Query string parameters

- `serviceName` (string) — optional
  The name of the service. If omitted, environments across all services are returned.
  Example: `opbeans-node`

## Header parameters

- `elastic-api-version` (enum · default: 2023-10-31) — required
  The version of the API to use
  Values: `2023-10-31`

## Responses

#### `200`

Successful response

`application/json`

- `environments` (object[])
  Service environment list
  - `alreadyConfigured` (boolean)
    Already configured
  - `name` (string)
    Service environment name
#### `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
#### `404`

Not found response

`application/json`

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

#### Console

```console
GET kbn:/api/apm/settings/agent-configuration/environments
```

#### curl

```curl
curl -X GET "${KIBANA_URL}/api/apm/settings/agent-configuration/environments" \
  -H "elastic-api-version: 2023-10-31" \
  -H "Authorization: ApiKey ${API_KEY}"
```

## Response examples

#### Get environments for service response example1

`application/json`

An example of a successful response from `GET /api/apm/settings/agent-configuration/environments`.

```json
{
  "environments": [
    {
      "alreadyConfigured": true,
      "name": "production"
    },
    {
      "alreadyConfigured": false,
      "name": "development"
    },
    {
      "alreadyConfigured": false,
      "name": "ALL_OPTION_VALUE"
    }
  ]
}
```

#### Bad request

`application/json`

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

`application/json`

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
}
```

#### Not found

`application/json`

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
}
```

