Environments

Environments allow you to maintain separate rollout rules in different contexts, from local development to QA, staging, and production. With the LaunchDarkly Environments API, you can programmatically create, delete, and update environments.

Create environment

Approval settings

The approvalSettings key is only returned when the Flag Approvals feature is enabled.

You cannot update approval settings when creating new environments. Update approval settings with the PATCH Environment API.

Create a new environment in a specified project with a given name, key, swatch color, and default TTL.

Request
Security:
ApiKey (readwrite)
path Parameters
projectKey
required
string <string>

The project key

Request Body schema: application/json
name
required
string

A human-friendly name for the new environment.

key
required
string

A project-unique key for the new environment.

color
required
string

A color to indicate this environment in the UI.

defaultTtl
integer

The default time (in minutes) that the PHP SDK can cache feature flag rules locally.

secureMode
boolean

Secure mode ensures that a user of the client-side SDK cannot impersonate another user.

defaultTrackEvents
boolean

Enables tracking detailed information for new flags by default.

confirmChanges
boolean

Require confirmation for all flag and segment changes via the UI in this environment.

requireComments
boolean

Require comments for all flag and segment changes via the UI in this environment.

tags
Array of strings

Tags to apply to the new environment.

Responses
201

Successful environment response

400

Invalid request

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

409

Status conflict

429

Rate limited

post/api/v2/projects/{projectKey}/environments
Request samples
application/json
{
  • "color": "DADBEE",
  • "key": "my-environment",
  • "name": "My Environment"
}
Response samples
application/json
{
  • "_links": {
    },
  • "_id": "57be1db38b75bf0772d11384",
  • "key": "my-environment",
  • "name": "My Environment",
  • "apiKey": "XYZ",
  • "mobileKey": "XYZ",
  • "color": "F5A623",
  • "defaultTtl": 5,
  • "secureMode": true,
  • "defaultTrackEvents": false,
  • "requireComments": true,
  • "confirmChanges": true,
  • "tags": [
    ],
  • "approvalSettings": {
    }
}

Reset environment SDK key

Reset an environment's SDK key with an optional expiry time for the old key.

Request
Security:
ApiKey (readwrite)
path Parameters
projectKey
required
string <string>

The project key

envKey
required
string <string>

The environment key

query Parameters
expiry
integer <int64>

The time at which you want the old SDK key to expire, in UNIX milliseconds. By default, the key expires immediately.

Responses
200

Successful environment response

400

Invalid request

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

post/api/v2/projects/{projectKey}/environments/{envKey}/apiKey
Request samples
curl -i -X POST \
  https://app.launchdarkly.com/api/v2/projects/:projectKey/environments/:envKey/apiKey \
  -H 'Authorization: YOUR_API_KEY_HERE'
Response samples
application/json
{
  • "_links": {
    },
  • "_id": "57be1db38b75bf0772d11384",
  • "key": "my-environment",
  • "name": "My Environment",
  • "apiKey": "XYZ",
  • "mobileKey": "XYZ",
  • "color": "F5A623",
  • "defaultTtl": 5,
  • "secureMode": true,
  • "defaultTrackEvents": false,
  • "requireComments": true,
  • "confirmChanges": true,
  • "tags": [
    ],
  • "approvalSettings": {
    }
}

Reset environment mobile SDK key

Reset an environment's mobile key. The optional expiry for the old key is deprecated for this endpoint, so the old key will always expire immediately.

Request
Security:
ApiKey (readwrite)
path Parameters
projectKey
required
string <string>

The project key

envKey
required
string <string>

The environment key

Responses
200

Successful environment response

400

Invalid request

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

post/api/v2/projects/{projectKey}/environments/{envKey}/mobileKey
Request samples
curl -i -X POST \
  https://app.launchdarkly.com/api/v2/projects/:projectKey/environments/:envKey/mobileKey \
  -H 'Authorization: YOUR_API_KEY_HERE'
Response samples
application/json
{
  • "_links": {
    },
  • "_id": "57be1db38b75bf0772d11384",
  • "key": "my-environment",
  • "name": "My Environment",
  • "apiKey": "XYZ",
  • "mobileKey": "XYZ",
  • "color": "F5A623",
  • "defaultTtl": 5,
  • "secureMode": true,
  • "defaultTrackEvents": false,
  • "requireComments": true,
  • "confirmChanges": true,
  • "tags": [
    ],
  • "approvalSettings": {
    }
}

Get environment

Approval settings

The approvalSettings key is only returned when the Flag Approvals feature is enabled.

Get an environment given a project and key.

Request
Security:
ApiKey (readwrite)
path Parameters
projectKey
required
string <string>

The project key

environmentKey
required
string <string>

The environment key

Responses
200

Environment response JSON

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

get/api/v2/projects/{projectKey}/environments/{environmentKey}
Request samples
curl -i -X GET \
  https://app.launchdarkly.com/api/v2/projects/:projectKey/environments/:environmentKey \
  -H 'Authorization: YOUR_API_KEY_HERE'
Response samples
application/json
{
  • "_links": {
    },
  • "_id": "57be1db38b75bf0772d11384",
  • "key": "my-environment",
  • "name": "My Environment",
  • "apiKey": "XYZ",
  • "mobileKey": "XYZ",
  • "color": "F5A623",
  • "defaultTtl": 5,
  • "secureMode": true,
  • "defaultTrackEvents": false,
  • "requireComments": true,
  • "confirmChanges": true,
  • "tags": [
    ],
  • "approvalSettings": {
    }
}

Update environment

Approval settings

The approvalSettings key is only returned when the Flag Approvals feature is enabled.

Only the canReviewOwnRequest, canApplyDeclinedChanges, minNumApprovals, required and requiredApprovalTagsfields are editable.

If you try to patch the environment by setting both required and requiredApprovalTags, it fails and an error appears. Users can specify either required approvals for all flags in an environment or those with specific tags, but not both. Only customers on an Enterprise plan can require approval for flag updates by either mechanism.

Request
Security:
ApiKey (readwrite)
path Parameters
projectKey
required
string <string>

The project key

environmentKey
required
string <string>

The environment key

Request Body schema: application/json
Array
op
required
string

The type of operation to perform

path
required
string

A JSON Pointer string specifying the part of the document to operate on

value
required
any

A JSON value used in "add", "replace", and "test" operations

Responses
200

Environment response JSON

400

Invalid request

401

Invalid access token

404

Invalid resource identifier

409

Status conflict

429

Rate limited

patch/api/v2/projects/{projectKey}/environments/{environmentKey}
Request samples
application/json
[
  • {
    }
]
Response samples
application/json
{
  • "_links": {
    },
  • "_id": "57be1db38b75bf0772d11384",
  • "key": "my-environment",
  • "name": "My Environment",
  • "apiKey": "XYZ",
  • "mobileKey": "XYZ",
  • "color": "F5A623",
  • "defaultTtl": 5,
  • "secureMode": true,
  • "defaultTrackEvents": false,
  • "requireComments": true,
  • "confirmChanges": true,
  • "tags": [
    ],
  • "approvalSettings": {
    }
}

Delete environment

Delete a environment by key.

Request
Security:
ApiKey (readwrite)
path Parameters
projectKey
required
string <string>

The project key

environmentKey
required
string <string>

The environment key

Responses
204

Action succeeded

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

delete/api/v2/projects/{projectKey}/environments/{environmentKey}
Request samples
curl -i -X DELETE \
  https://app.launchdarkly.com/api/v2/projects/:projectKey/environments/:environmentKey \
  -H 'Authorization: YOUR_API_KEY_HERE'
Response samples
application/json
{
  • "code": "unauthorized",
  • "message": "invalid key"
}