Metrics

Metrics track flag behavior over time when an experiment is running. The data generated from experiments gives you more insight into the impact of a particular flag.

Using the Metrics API, you can create, delete, and manage metrics.

List metrics

Get a list of all metrics for the specified project.

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

The project key

Responses
200

Metrics response JSON

401

Invalid access token

404

Invalid resource identifier

get/api/v2/metrics/{projectKey}
Request samples
curl -i -X GET \
  https://app.launchdarkly.com/api/v2/metrics/:projectKey \
  -H 'Authorization: YOUR_API_KEY_HERE'
Response samples
application/json
{
  • "items": [
    ],
  • "_links": {
    }
}

Create metric

Create a new metric in the specified project. Note that the expected POST body differs depending on the specified kind property.

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

The project key

Request Body schema: application/json
key
required
string
name
string
description
string
kind
required
string
Enum: "pageview" "click" "custom"
selector
string

Required for click metrics

Array of objects (UrlPost)

Required for click and pageview metrics

isActive
boolean
isNumeric
boolean
unit
string
eventKey
string

Required for custom metrics

successCriteria
integer (SuccessCriteria)
tags
Array of strings
Responses
201

Successful metric response

400

Invalid request

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

409

Status conflict

429

Rate limited

post/api/v2/metrics/{projectKey}
Request samples
application/json
{
  • "key": "my-metric",
  • "kind": "pageview",
  • "urls": [
    ]
}
Response samples
application/json
{
  • "_id": "5902deadbeef667524a01290",
  • "key": "my-metric",
  • "name": "my-metric",
  • "kind": "pageview",
  • "_attachedFlagCount": 0,
  • "_links": {
    },
  • "_site": {
    },
  • "_access": {
    },
  • "tags": [ ],
  • "_creationDate": 0,
  • "lastModified": {
    },
  • "maintainerId": "569fdeadbeef1644facecafe",
  • "_maintainer": {
    },
  • "description": "string",
  • "isNumeric": true,
  • "successCriteria": 0,
  • "unit": "string",
  • "eventKey": "string",
  • "isActive": true,
  • "_attachedFeatures": [
    ],
  • "_version": 0,
  • "selector": "string",
  • "urls": [
    ]
}

Get metric

Get information for a single metric from the specific project.

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

The project key

key
required
string <string>

The metric key

Responses
200

Metric response JSON

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

get/api/v2/metrics/{projectKey}/{key}
Request samples
curl -i -X GET \
  https://app.launchdarkly.com/api/v2/metrics/:projectKey/:key \
  -H 'Authorization: YOUR_API_KEY_HERE'
Response samples
application/json
{
  • "_id": "5902deadbeef667524a01290",
  • "key": "my-metric",
  • "name": "my-metric",
  • "kind": "pageview",
  • "_attachedFlagCount": 0,
  • "_links": {
    },
  • "_site": {
    },
  • "_access": {
    },
  • "tags": [ ],
  • "_creationDate": 0,
  • "lastModified": {
    },
  • "maintainerId": "569fdeadbeef1644facecafe",
  • "_maintainer": {
    },
  • "description": "string",
  • "isNumeric": true,
  • "successCriteria": 0,
  • "unit": "string",
  • "eventKey": "string",
  • "isActive": true,
  • "_attachedFeatures": [
    ],
  • "_version": 0,
  • "selector": "string",
  • "urls": [
    ]
}

Update metric

Patch a environment by key.

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

The project key

key
required
string <string>

The metric 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

Metric response JSON

400

Invalid request

401

Invalid access token

404

Invalid resource identifier

409

Status conflict

429

Rate limited

patch/api/v2/metrics/{projectKey}/{key}
Request samples
application/json
[
  • {
    }
]
Response samples
application/json
{
  • "_id": "5902deadbeef667524a01290",
  • "key": "my-metric",
  • "name": "my-metric",
  • "kind": "pageview",
  • "_attachedFlagCount": 0,
  • "_links": {
    },
  • "_site": {
    },
  • "_access": {
    },
  • "tags": [ ],
  • "_creationDate": 0,
  • "lastModified": {
    },
  • "maintainerId": "569fdeadbeef1644facecafe",
  • "_maintainer": {
    },
  • "description": "string",
  • "isNumeric": true,
  • "successCriteria": 0,
  • "unit": "string",
  • "eventKey": "string",
  • "isActive": true,
  • "_attachedFeatures": [
    ],
  • "_version": 0,
  • "selector": "string",
  • "urls": [
    ]
}

Delete metric

Delete a metric by key.

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

The project key

key
required
string <string>

The metric key

Responses
204

Action succeeded

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

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