---
type: api
title: Get environments for service
description: **Spaces method and path for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana/operation/operation-getenvironmentsforservice
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana/operation/operation-getenvironmentsforservice
products:
  - Kibana
---

# Get environments for service

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

## Paths

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

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

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)
  The name of the service. If omitted, environments across all services are returned.

## 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 /api/apm/settings/agent-configuration/environments
```

#### curl

```curl
curl -X GET "https://{kibana_url}/api/apm/settings/agent-configuration/environments" \
  -H "elastic-api-version: string"
```

## Response Examples

#### Get environments for service response example1

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

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

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

