Update metric
For the complete documentation index, see llms.txt. For the full documentation snapshot, see llms-full.txt.
Patch a metric by key. Updating a metric uses a JSON patch representation of the desired changes. To learn more, read Updates.
curl --request PATCH \
--url https://app.launchdarkly.com/api/v2/metrics/{projectKey}/{metricKey} \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
[
{
"op": "replace",
"path": "/name",
"value": "my-updated-metric"
}
]
'import requests
url = "https://app.launchdarkly.com/api/v2/metrics/{projectKey}/{metricKey}"
payload = [
{
"op": "replace",
"path": "/name",
"value": "my-updated-metric"
}
]
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PATCH',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify([{op: 'replace', path: '/name', value: 'my-updated-metric'}])
};
fetch('https://app.launchdarkly.com/api/v2/metrics/{projectKey}/{metricKey}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://app.launchdarkly.com/api/v2/metrics/{projectKey}/{metricKey}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
[
'op' => 'replace',
'path' => '/name',
'value' => 'my-updated-metric'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://app.launchdarkly.com/api/v2/metrics/{projectKey}/{metricKey}"
payload := strings.NewReader("[\n {\n \"op\": \"replace\",\n \"path\": \"/name\",\n \"value\": \"my-updated-metric\"\n }\n]")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.patch("https://app.launchdarkly.com/api/v2/metrics/{projectKey}/{metricKey}")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("[\n {\n \"op\": \"replace\",\n \"path\": \"/name\",\n \"value\": \"my-updated-metric\"\n }\n]")
.asString();require 'uri'
require 'net/http'
url = URI("https://app.launchdarkly.com/api/v2/metrics/{projectKey}/{metricKey}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "[\n {\n \"op\": \"replace\",\n \"path\": \"/name\",\n \"value\": \"my-updated-metric\"\n }\n]"
response = http.request(request)
puts response.read_body{
"_id": "5902deadbeef667524a01290",
"_versionId": "version-id-123abc",
"key": "metric-key-123abc",
"name": "My metric",
"kind": "custom",
"_links": {
"parent": {
"href": "/api/v2/metrics/my-project",
"type": "application/json"
},
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"tags": [],
"_creationDate": "1628192791148",
"dataSource": {
"key": "<string>",
"environmentKey": "<string>",
"_name": "<string>",
"_integrationKey": "<string>"
},
"experimentCount": 0,
"metricGroupCount": 0,
"activeExperimentCount": 2,
"activeGuardedRolloutCount": 1,
"_version": 1,
"_attachedFlagCount": 0,
"_site": "{\"href\":\"/experiments/metrics/my-metric/edit\",\"type\":\"text/html\"}",
"_access": {
"denied": [
{
"action": "<string>",
"reason": {
"effect": "allow",
"resources": [
"proj/*:env/*;qa_*:/flag/*"
],
"notResources": [
"<string>"
],
"actions": [
"*"
],
"notActions": [
"<string>"
],
"role_name": "<string>"
}
}
],
"allowed": [
{
"action": "<string>",
"reason": {
"effect": "allow",
"resources": [
"proj/*:env/*;qa_*:/flag/*"
],
"notResources": [
"<string>"
],
"actions": [
"*"
],
"notActions": [
"<string>"
],
"role_name": "<string>"
}
}
]
},
"lastModified": {
"date": "2021-08-05T19:46:31.148082Z"
},
"maintainerId": "569fdeadbeef1644facecafe",
"_maintainer": "{\"_links\":{\"self\":{\"href\":\"/api/v2/members/569fdeadbeef1644facecafe\",\"type\":\"application/json\"}},\"_id\":\"569fdeadbeef1644facecafe\",\"firstName\":\"Ariel\",\"lastName\":\"Flores\",\"role\":\"owner\",\"email\":\"ariel@acme.com\"}",
"description": "<string>",
"category": "Error monitoring",
"isNumeric": true,
"successCriteria": "HigherThanBaseline",
"unit": "<string>",
"eventKey": "Order placed",
"randomizationUnits": [
"user"
],
"filters": "{\"type\":\"group\",\"op\":\"and\",\"values\":[{\"type\":\"contextAttribute\",\"op\":\"in\",\"contextKind\":\"user\",\"attribute\":\"country\",\"values\":[\"JP\"],\"negate\":false},{\"type\":\"eventProperty\",\"op\":\"in\",\"attribute\":\"category\",\"values\":[\"magic-wands\"],\"negate\":false}]}",
"unitAggregationType": "average",
"analysisType": "mean",
"percentileValue": 95,
"eventDefault": {
"disabled": true,
"value": 0
},
"lastSeen": 123,
"archived": true,
"archivedAt": "1609459200000",
"selector": "<string>",
"urls": "[{\"kind\":\"exact\",\"url\":\"https://www.example.com/page1\"}]",
"windowStartOffset": 123,
"windowEndOffset": 123,
"traceQuery": "service.name = \"checkout\"",
"traceValueLocation": "duration",
"experiments": [
{
"key": "experiment-key-123abc",
"name": "Example experiment",
"environmentId": "1234a56b7c89d012345e678f",
"environmentKey": "production",
"creationDate": "1654104600000",
"_links": {
"parent": {
"href": "/api/v2/projects/my-project/environments/my-environment",
"type": "application/json"
},
"self": {
"href": "/api/v2/projects/my-project/environments/my-environment/experiments/example-experiment",
"type": "application/json"
}
},
"archivedDate": "1654104600000"
}
],
"metricGroups": [
{
"key": "metric-group-key-123abc",
"name": "My metric group",
"kind": "funnel",
"_links": {
"parent": {
"href": "/api/v2/projects/my-project",
"type": "application/json"
},
"self": {
"href": "/api/v2/projects/my-project/metric-groups/my-metric-group",
"type": "application/json"
}
}
}
],
"lastUsedInExperiment": {
"key": "experiment-key-123abc",
"name": "Example experiment",
"environmentId": "1234a56b7c89d012345e678f",
"environmentKey": "production",
"creationDate": "1654104600000",
"_links": {
"parent": {
"href": "/api/v2/projects/my-project/environments/my-environment",
"type": "application/json"
},
"self": {
"href": "/api/v2/projects/my-project/environments/my-environment/experiments/example-experiment",
"type": "application/json"
}
},
"archivedDate": "1654104600000"
},
"lastUsedInGuardedRollout": {
"_id": "885ccadf-181b-4a9a-8414-7ad6f7ba2db0",
"flagKey": "my-flag",
"flagName": "My Flag",
"environmentKey": "production",
"environmentName": "Production",
"status": "monitoring",
"creationDate": "1654104600000",
"_links": {
"self": {
"href": "/api/v2/projects/my-project/flags/my-flag/environments/production/measured-rollouts/885ccadf-181b-4a9a-8414-7ad6f7ba2db0",
"type": "application/json"
}
},
"flagPurpose": "migration"
},
"isActive": true,
"_attachedFeatures": [
{
"name": "Example flag",
"key": "flag-key-123abc",
"_links": {},
"_site": {
"href": "<string>",
"type": "<string>"
}
}
]
}{
"code": "invalid_request",
"message": "Invalid request body"
}{
"code": "unauthorized",
"message": "Invalid access token"
}{
"code": "not_found",
"message": "Invalid resource identifier"
}{
"code": "optimistic_locking_error",
"message": "Conflict. Optimistic lock error. Try again later."
}{
"code": "rate_limited",
"message": "You've exceeded the API rate limit. Try again later."
}Authorizations
Path Parameters
The project key
The metric key
Body
Response
Metric response
The ID of this metric
"5902deadbeef667524a01290"
The version ID of the metric
"version-id-123abc"
A unique key to reference the metric
"metric-key-123abc"
A human-friendly name for the metric
"My metric"
The kind of event the metric tracks
pageview, click, custom, trace "custom"
The location and content type of related resources
Show child attributes
Show child attributes
{
"parent": {
"href": "/api/v2/metrics/my-project",
"type": "application/json"
},
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
}
Tags for the metric
[]
Timestamp of when the metric was created
"1628192791148"
Show child attributes
Show child attributes
The number of experiments using this metric
0
The number of metric groups using this metric
0
The number of active experiments using this metric
2
The number of active guarded rollouts using this metric
1
Version of the metric
1
The number of feature flags currently attached to this metric
0
Details on how to access the metric in the LaunchDarkly UI
Show child attributes
Show child attributes
"{\"href\":\"/experiments/metrics/my-metric/edit\",\"type\":\"text/html\"}"
Details on the allowed and denied actions for this metric
Show child attributes
Show child attributes
Show child attributes
Show child attributes
The ID of the member who maintains this metric
"569fdeadbeef1644facecafe"
Details on the member who maintains this metric
Show child attributes
Show child attributes
"{\"_links\":{\"self\":{\"href\":\"/api/v2/members/569fdeadbeef1644facecafe\",\"type\":\"application/json\"}},\"_id\":\"569fdeadbeef1644facecafe\",\"firstName\":\"Ariel\",\"lastName\":\"Flores\",\"role\":\"owner\",\"email\":\"ariel@acme.com\"}"
Description of the metric
The category of the metric
"Error monitoring"
For custom and trace metrics, whether to track numeric changes in value against a baseline (true) or to track a conversion when an end user takes an action (false).
true
For custom and trace metrics, the success criteria
HigherThanBaseline, LowerThanBaseline For numeric custom and trace metrics, the unit of measure
For custom metrics, the event key to use in your code
"Order placed"
An array of randomization units allowed for this metric
["user"]
The filters narrowing down the audience based on context attributes or event properties.
Show child attributes
Show child attributes
"{\"type\":\"group\",\"op\":\"and\",\"values\":[{\"type\":\"contextAttribute\",\"op\":\"in\",\"contextKind\":\"user\",\"attribute\":\"country\",\"values\":[\"JP\"],\"negate\":false},{\"type\":\"eventProperty\",\"op\":\"in\",\"attribute\":\"category\",\"values\":[\"magic-wands\"],\"negate\":false}]}"
The method by which multiple unit event values are aggregated
average, sum "average"
The method for analyzing metric events
mean, percentile "mean"
The percentile for the analysis method. An integer denoting the target percentile between 0 and 100. Required when analysisType is percentile.
95
Show child attributes
Show child attributes
Timestamp of most recent data for this metric, at one-hour fidelity
Whether the metric version is archived
Timestamp when the metric version was archived
"1609459200000"
For click metrics, the CSS selectors
For click and pageview metrics, the target URLs
Show child attributes
Show child attributes
"[{\"kind\":\"exact\",\"url\":\"https://www.example.com/page1\"}]"
Not yet implemented - The start of the measurement window, in milliseconds relative to the unit's first exposure to a flag variation
Not yet implemented - The end of the measurement window, in milliseconds relative to the unit's first exposure to a flag variation
For trace metrics, the trace query to use for the metric.
"service.name = \"checkout\""
For trace metrics, the location in the trace to use for numeric values.
"duration"
Experiments that use this metric, including those using a metric group that contains this metric
Show child attributes
Show child attributes
Metric groups that use this metric
Show child attributes
Show child attributes
The most recent experiment that used this metric
Show child attributes
Show child attributes
The most recent guarded rollout that used this metric
Show child attributes
Show child attributes
Whether the metric is active
true
Details on the flags attached to this metric
Show child attributes
Show child attributes
curl --request PATCH \
--url https://app.launchdarkly.com/api/v2/metrics/{projectKey}/{metricKey} \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
[
{
"op": "replace",
"path": "/name",
"value": "my-updated-metric"
}
]
'import requests
url = "https://app.launchdarkly.com/api/v2/metrics/{projectKey}/{metricKey}"
payload = [
{
"op": "replace",
"path": "/name",
"value": "my-updated-metric"
}
]
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PATCH',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify([{op: 'replace', path: '/name', value: 'my-updated-metric'}])
};
fetch('https://app.launchdarkly.com/api/v2/metrics/{projectKey}/{metricKey}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://app.launchdarkly.com/api/v2/metrics/{projectKey}/{metricKey}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
[
'op' => 'replace',
'path' => '/name',
'value' => 'my-updated-metric'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://app.launchdarkly.com/api/v2/metrics/{projectKey}/{metricKey}"
payload := strings.NewReader("[\n {\n \"op\": \"replace\",\n \"path\": \"/name\",\n \"value\": \"my-updated-metric\"\n }\n]")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.patch("https://app.launchdarkly.com/api/v2/metrics/{projectKey}/{metricKey}")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("[\n {\n \"op\": \"replace\",\n \"path\": \"/name\",\n \"value\": \"my-updated-metric\"\n }\n]")
.asString();require 'uri'
require 'net/http'
url = URI("https://app.launchdarkly.com/api/v2/metrics/{projectKey}/{metricKey}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "[\n {\n \"op\": \"replace\",\n \"path\": \"/name\",\n \"value\": \"my-updated-metric\"\n }\n]"
response = http.request(request)
puts response.read_body{
"_id": "5902deadbeef667524a01290",
"_versionId": "version-id-123abc",
"key": "metric-key-123abc",
"name": "My metric",
"kind": "custom",
"_links": {
"parent": {
"href": "/api/v2/metrics/my-project",
"type": "application/json"
},
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"tags": [],
"_creationDate": "1628192791148",
"dataSource": {
"key": "<string>",
"environmentKey": "<string>",
"_name": "<string>",
"_integrationKey": "<string>"
},
"experimentCount": 0,
"metricGroupCount": 0,
"activeExperimentCount": 2,
"activeGuardedRolloutCount": 1,
"_version": 1,
"_attachedFlagCount": 0,
"_site": "{\"href\":\"/experiments/metrics/my-metric/edit\",\"type\":\"text/html\"}",
"_access": {
"denied": [
{
"action": "<string>",
"reason": {
"effect": "allow",
"resources": [
"proj/*:env/*;qa_*:/flag/*"
],
"notResources": [
"<string>"
],
"actions": [
"*"
],
"notActions": [
"<string>"
],
"role_name": "<string>"
}
}
],
"allowed": [
{
"action": "<string>",
"reason": {
"effect": "allow",
"resources": [
"proj/*:env/*;qa_*:/flag/*"
],
"notResources": [
"<string>"
],
"actions": [
"*"
],
"notActions": [
"<string>"
],
"role_name": "<string>"
}
}
]
},
"lastModified": {
"date": "2021-08-05T19:46:31.148082Z"
},
"maintainerId": "569fdeadbeef1644facecafe",
"_maintainer": "{\"_links\":{\"self\":{\"href\":\"/api/v2/members/569fdeadbeef1644facecafe\",\"type\":\"application/json\"}},\"_id\":\"569fdeadbeef1644facecafe\",\"firstName\":\"Ariel\",\"lastName\":\"Flores\",\"role\":\"owner\",\"email\":\"ariel@acme.com\"}",
"description": "<string>",
"category": "Error monitoring",
"isNumeric": true,
"successCriteria": "HigherThanBaseline",
"unit": "<string>",
"eventKey": "Order placed",
"randomizationUnits": [
"user"
],
"filters": "{\"type\":\"group\",\"op\":\"and\",\"values\":[{\"type\":\"contextAttribute\",\"op\":\"in\",\"contextKind\":\"user\",\"attribute\":\"country\",\"values\":[\"JP\"],\"negate\":false},{\"type\":\"eventProperty\",\"op\":\"in\",\"attribute\":\"category\",\"values\":[\"magic-wands\"],\"negate\":false}]}",
"unitAggregationType": "average",
"analysisType": "mean",
"percentileValue": 95,
"eventDefault": {
"disabled": true,
"value": 0
},
"lastSeen": 123,
"archived": true,
"archivedAt": "1609459200000",
"selector": "<string>",
"urls": "[{\"kind\":\"exact\",\"url\":\"https://www.example.com/page1\"}]",
"windowStartOffset": 123,
"windowEndOffset": 123,
"traceQuery": "service.name = \"checkout\"",
"traceValueLocation": "duration",
"experiments": [
{
"key": "experiment-key-123abc",
"name": "Example experiment",
"environmentId": "1234a56b7c89d012345e678f",
"environmentKey": "production",
"creationDate": "1654104600000",
"_links": {
"parent": {
"href": "/api/v2/projects/my-project/environments/my-environment",
"type": "application/json"
},
"self": {
"href": "/api/v2/projects/my-project/environments/my-environment/experiments/example-experiment",
"type": "application/json"
}
},
"archivedDate": "1654104600000"
}
],
"metricGroups": [
{
"key": "metric-group-key-123abc",
"name": "My metric group",
"kind": "funnel",
"_links": {
"parent": {
"href": "/api/v2/projects/my-project",
"type": "application/json"
},
"self": {
"href": "/api/v2/projects/my-project/metric-groups/my-metric-group",
"type": "application/json"
}
}
}
],
"lastUsedInExperiment": {
"key": "experiment-key-123abc",
"name": "Example experiment",
"environmentId": "1234a56b7c89d012345e678f",
"environmentKey": "production",
"creationDate": "1654104600000",
"_links": {
"parent": {
"href": "/api/v2/projects/my-project/environments/my-environment",
"type": "application/json"
},
"self": {
"href": "/api/v2/projects/my-project/environments/my-environment/experiments/example-experiment",
"type": "application/json"
}
},
"archivedDate": "1654104600000"
},
"lastUsedInGuardedRollout": {
"_id": "885ccadf-181b-4a9a-8414-7ad6f7ba2db0",
"flagKey": "my-flag",
"flagName": "My Flag",
"environmentKey": "production",
"environmentName": "Production",
"status": "monitoring",
"creationDate": "1654104600000",
"_links": {
"self": {
"href": "/api/v2/projects/my-project/flags/my-flag/environments/production/measured-rollouts/885ccadf-181b-4a9a-8414-7ad6f7ba2db0",
"type": "application/json"
}
},
"flagPurpose": "migration"
},
"isActive": true,
"_attachedFeatures": [
{
"name": "Example flag",
"key": "flag-key-123abc",
"_links": {},
"_site": {
"href": "<string>",
"type": "<string>"
}
}
]
}{
"code": "invalid_request",
"message": "Invalid request body"
}{
"code": "unauthorized",
"message": "Invalid access token"
}{
"code": "not_found",
"message": "Invalid resource identifier"
}{
"code": "optimistic_locking_error",
"message": "Conflict. Optimistic lock error. Try again later."
}{
"code": "rate_limited",
"message": "You've exceeded the API rate limit. Try again later."
}