curl --request POST \
--url https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/experiments \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "Example experiment",
"key": "experiment-key-123abc",
"iteration": {
"hypothesis": "Example hypothesis, the new button placement will increase conversion",
"metrics": [
{
"key": "metric-key-123abc",
"isGroup": true,
"primary": true,
"analysisUnit": "user"
}
],
"treatments": [
{
"name": "Treatment 1",
"baseline": true,
"allocationPercent": "10",
"parameters": [
{
"flagKey": "example-flag-for-experiment",
"variationId": "e432f62b-55f6-49dd-a02f-eb24acf39d05"
}
],
"assignmentVariantId": "treatment-1"
}
],
"flags": "{\"example-flag-key\": { \"ruleId\": \"e432f62b-55f6-49dd-a02f-eb24acf39d05\", \"flagConfigVersion\": 12, \"notInExperimentVariationId\": \"e432f62b-55f6-49dd-a02f-eb24acf39d05\" }}",
"canReshuffleTraffic": true,
"primarySingleMetricKey": "metric-key-123abc",
"primaryFunnelKey": "metric-group-key-123abc",
"randomizationUnit": "user",
"reallocationFrequencyMillis": 3600000,
"covariateId": "<string>",
"attributes": [
"country",
"device",
"os"
]
},
"description": "An example experiment, used in testing",
"maintainerId": "12ab3c45de678910fgh12345",
"holdoutId": "f3b74309-d581-44e1-8a2b-bb2933b4fe40",
"tags": [
"<string>"
],
"methodology": "frequentist",
"analysisConfig": {
"bayesianThreshold": "10",
"significanceThreshold": "5",
"testDirection": "<string>",
"multipleComparisonCorrectionMethod": "bonferroni",
"multipleComparisonCorrectionScope": "variations",
"sequentialTestingEnabled": true
},
"dataSource": "snowflake",
"type": "experiment"
}
'import requests
url = "https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/experiments"
payload = {
"name": "Example experiment",
"key": "experiment-key-123abc",
"iteration": {
"hypothesis": "Example hypothesis, the new button placement will increase conversion",
"metrics": [
{
"key": "metric-key-123abc",
"isGroup": True,
"primary": True,
"analysisUnit": "user"
}
],
"treatments": [
{
"name": "Treatment 1",
"baseline": True,
"allocationPercent": "10",
"parameters": [
{
"flagKey": "example-flag-for-experiment",
"variationId": "e432f62b-55f6-49dd-a02f-eb24acf39d05"
}
],
"assignmentVariantId": "treatment-1"
}
],
"flags": "{\"example-flag-key\": { \"ruleId\": \"e432f62b-55f6-49dd-a02f-eb24acf39d05\", \"flagConfigVersion\": 12, \"notInExperimentVariationId\": \"e432f62b-55f6-49dd-a02f-eb24acf39d05\" }}",
"canReshuffleTraffic": True,
"primarySingleMetricKey": "metric-key-123abc",
"primaryFunnelKey": "metric-group-key-123abc",
"randomizationUnit": "user",
"reallocationFrequencyMillis": 3600000,
"covariateId": "<string>",
"attributes": ["country", "device", "os"]
},
"description": "An example experiment, used in testing",
"maintainerId": "12ab3c45de678910fgh12345",
"holdoutId": "f3b74309-d581-44e1-8a2b-bb2933b4fe40",
"tags": ["<string>"],
"methodology": "frequentist",
"analysisConfig": {
"bayesianThreshold": "10",
"significanceThreshold": "5",
"testDirection": "<string>",
"multipleComparisonCorrectionMethod": "bonferroni",
"multipleComparisonCorrectionScope": "variations",
"sequentialTestingEnabled": True
},
"dataSource": "snowflake",
"type": "experiment"
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'Example experiment',
key: 'experiment-key-123abc',
iteration: {
hypothesis: 'Example hypothesis, the new button placement will increase conversion',
metrics: [{key: 'metric-key-123abc', isGroup: true, primary: true, analysisUnit: 'user'}],
treatments: [
{
name: 'Treatment 1',
baseline: true,
allocationPercent: '10',
parameters: [
{
flagKey: 'example-flag-for-experiment',
variationId: 'e432f62b-55f6-49dd-a02f-eb24acf39d05'
}
],
assignmentVariantId: 'treatment-1'
}
],
flags: '{"example-flag-key": { "ruleId": "e432f62b-55f6-49dd-a02f-eb24acf39d05", "flagConfigVersion": 12, "notInExperimentVariationId": "e432f62b-55f6-49dd-a02f-eb24acf39d05" }}',
canReshuffleTraffic: true,
primarySingleMetricKey: 'metric-key-123abc',
primaryFunnelKey: 'metric-group-key-123abc',
randomizationUnit: 'user',
reallocationFrequencyMillis: 3600000,
covariateId: '<string>',
attributes: ['country', 'device', 'os']
},
description: 'An example experiment, used in testing',
maintainerId: '12ab3c45de678910fgh12345',
holdoutId: 'f3b74309-d581-44e1-8a2b-bb2933b4fe40',
tags: ['<string>'],
methodology: 'frequentist',
analysisConfig: {
bayesianThreshold: '10',
significanceThreshold: '5',
testDirection: '<string>',
multipleComparisonCorrectionMethod: 'bonferroni',
multipleComparisonCorrectionScope: 'variations',
sequentialTestingEnabled: true
},
dataSource: 'snowflake',
type: 'experiment'
})
};
fetch('https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/experiments', 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/projects/{projectKey}/environments/{environmentKey}/experiments",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => 'Example experiment',
'key' => 'experiment-key-123abc',
'iteration' => [
'hypothesis' => 'Example hypothesis, the new button placement will increase conversion',
'metrics' => [
[
'key' => 'metric-key-123abc',
'isGroup' => true,
'primary' => true,
'analysisUnit' => 'user'
]
],
'treatments' => [
[
'name' => 'Treatment 1',
'baseline' => true,
'allocationPercent' => '10',
'parameters' => [
[
'flagKey' => 'example-flag-for-experiment',
'variationId' => 'e432f62b-55f6-49dd-a02f-eb24acf39d05'
]
],
'assignmentVariantId' => 'treatment-1'
]
],
'flags' => '{"example-flag-key": { "ruleId": "e432f62b-55f6-49dd-a02f-eb24acf39d05", "flagConfigVersion": 12, "notInExperimentVariationId": "e432f62b-55f6-49dd-a02f-eb24acf39d05" }}',
'canReshuffleTraffic' => true,
'primarySingleMetricKey' => 'metric-key-123abc',
'primaryFunnelKey' => 'metric-group-key-123abc',
'randomizationUnit' => 'user',
'reallocationFrequencyMillis' => 3600000,
'covariateId' => '<string>',
'attributes' => [
'country',
'device',
'os'
]
],
'description' => 'An example experiment, used in testing',
'maintainerId' => '12ab3c45de678910fgh12345',
'holdoutId' => 'f3b74309-d581-44e1-8a2b-bb2933b4fe40',
'tags' => [
'<string>'
],
'methodology' => 'frequentist',
'analysisConfig' => [
'bayesianThreshold' => '10',
'significanceThreshold' => '5',
'testDirection' => '<string>',
'multipleComparisonCorrectionMethod' => 'bonferroni',
'multipleComparisonCorrectionScope' => 'variations',
'sequentialTestingEnabled' => true
],
'dataSource' => 'snowflake',
'type' => 'experiment'
]),
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/projects/{projectKey}/environments/{environmentKey}/experiments"
payload := strings.NewReader("{\n \"name\": \"Example experiment\",\n \"key\": \"experiment-key-123abc\",\n \"iteration\": {\n \"hypothesis\": \"Example hypothesis, the new button placement will increase conversion\",\n \"metrics\": [\n {\n \"key\": \"metric-key-123abc\",\n \"isGroup\": true,\n \"primary\": true,\n \"analysisUnit\": \"user\"\n }\n ],\n \"treatments\": [\n {\n \"name\": \"Treatment 1\",\n \"baseline\": true,\n \"allocationPercent\": \"10\",\n \"parameters\": [\n {\n \"flagKey\": \"example-flag-for-experiment\",\n \"variationId\": \"e432f62b-55f6-49dd-a02f-eb24acf39d05\"\n }\n ],\n \"assignmentVariantId\": \"treatment-1\"\n }\n ],\n \"flags\": \"{\\\"example-flag-key\\\": { \\\"ruleId\\\": \\\"e432f62b-55f6-49dd-a02f-eb24acf39d05\\\", \\\"flagConfigVersion\\\": 12, \\\"notInExperimentVariationId\\\": \\\"e432f62b-55f6-49dd-a02f-eb24acf39d05\\\" }}\",\n \"canReshuffleTraffic\": true,\n \"primarySingleMetricKey\": \"metric-key-123abc\",\n \"primaryFunnelKey\": \"metric-group-key-123abc\",\n \"randomizationUnit\": \"user\",\n \"reallocationFrequencyMillis\": 3600000,\n \"covariateId\": \"<string>\",\n \"attributes\": [\n \"country\",\n \"device\",\n \"os\"\n ]\n },\n \"description\": \"An example experiment, used in testing\",\n \"maintainerId\": \"12ab3c45de678910fgh12345\",\n \"holdoutId\": \"f3b74309-d581-44e1-8a2b-bb2933b4fe40\",\n \"tags\": [\n \"<string>\"\n ],\n \"methodology\": \"frequentist\",\n \"analysisConfig\": {\n \"bayesianThreshold\": \"10\",\n \"significanceThreshold\": \"5\",\n \"testDirection\": \"<string>\",\n \"multipleComparisonCorrectionMethod\": \"bonferroni\",\n \"multipleComparisonCorrectionScope\": \"variations\",\n \"sequentialTestingEnabled\": true\n },\n \"dataSource\": \"snowflake\",\n \"type\": \"experiment\"\n}")
req, _ := http.NewRequest("POST", 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.post("https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/experiments")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Example experiment\",\n \"key\": \"experiment-key-123abc\",\n \"iteration\": {\n \"hypothesis\": \"Example hypothesis, the new button placement will increase conversion\",\n \"metrics\": [\n {\n \"key\": \"metric-key-123abc\",\n \"isGroup\": true,\n \"primary\": true,\n \"analysisUnit\": \"user\"\n }\n ],\n \"treatments\": [\n {\n \"name\": \"Treatment 1\",\n \"baseline\": true,\n \"allocationPercent\": \"10\",\n \"parameters\": [\n {\n \"flagKey\": \"example-flag-for-experiment\",\n \"variationId\": \"e432f62b-55f6-49dd-a02f-eb24acf39d05\"\n }\n ],\n \"assignmentVariantId\": \"treatment-1\"\n }\n ],\n \"flags\": \"{\\\"example-flag-key\\\": { \\\"ruleId\\\": \\\"e432f62b-55f6-49dd-a02f-eb24acf39d05\\\", \\\"flagConfigVersion\\\": 12, \\\"notInExperimentVariationId\\\": \\\"e432f62b-55f6-49dd-a02f-eb24acf39d05\\\" }}\",\n \"canReshuffleTraffic\": true,\n \"primarySingleMetricKey\": \"metric-key-123abc\",\n \"primaryFunnelKey\": \"metric-group-key-123abc\",\n \"randomizationUnit\": \"user\",\n \"reallocationFrequencyMillis\": 3600000,\n \"covariateId\": \"<string>\",\n \"attributes\": [\n \"country\",\n \"device\",\n \"os\"\n ]\n },\n \"description\": \"An example experiment, used in testing\",\n \"maintainerId\": \"12ab3c45de678910fgh12345\",\n \"holdoutId\": \"f3b74309-d581-44e1-8a2b-bb2933b4fe40\",\n \"tags\": [\n \"<string>\"\n ],\n \"methodology\": \"frequentist\",\n \"analysisConfig\": {\n \"bayesianThreshold\": \"10\",\n \"significanceThreshold\": \"5\",\n \"testDirection\": \"<string>\",\n \"multipleComparisonCorrectionMethod\": \"bonferroni\",\n \"multipleComparisonCorrectionScope\": \"variations\",\n \"sequentialTestingEnabled\": true\n },\n \"dataSource\": \"snowflake\",\n \"type\": \"experiment\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/experiments")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"Example experiment\",\n \"key\": \"experiment-key-123abc\",\n \"iteration\": {\n \"hypothesis\": \"Example hypothesis, the new button placement will increase conversion\",\n \"metrics\": [\n {\n \"key\": \"metric-key-123abc\",\n \"isGroup\": true,\n \"primary\": true,\n \"analysisUnit\": \"user\"\n }\n ],\n \"treatments\": [\n {\n \"name\": \"Treatment 1\",\n \"baseline\": true,\n \"allocationPercent\": \"10\",\n \"parameters\": [\n {\n \"flagKey\": \"example-flag-for-experiment\",\n \"variationId\": \"e432f62b-55f6-49dd-a02f-eb24acf39d05\"\n }\n ],\n \"assignmentVariantId\": \"treatment-1\"\n }\n ],\n \"flags\": \"{\\\"example-flag-key\\\": { \\\"ruleId\\\": \\\"e432f62b-55f6-49dd-a02f-eb24acf39d05\\\", \\\"flagConfigVersion\\\": 12, \\\"notInExperimentVariationId\\\": \\\"e432f62b-55f6-49dd-a02f-eb24acf39d05\\\" }}\",\n \"canReshuffleTraffic\": true,\n \"primarySingleMetricKey\": \"metric-key-123abc\",\n \"primaryFunnelKey\": \"metric-group-key-123abc\",\n \"randomizationUnit\": \"user\",\n \"reallocationFrequencyMillis\": 3600000,\n \"covariateId\": \"<string>\",\n \"attributes\": [\n \"country\",\n \"device\",\n \"os\"\n ]\n },\n \"description\": \"An example experiment, used in testing\",\n \"maintainerId\": \"12ab3c45de678910fgh12345\",\n \"holdoutId\": \"f3b74309-d581-44e1-8a2b-bb2933b4fe40\",\n \"tags\": [\n \"<string>\"\n ],\n \"methodology\": \"frequentist\",\n \"analysisConfig\": {\n \"bayesianThreshold\": \"10\",\n \"significanceThreshold\": \"5\",\n \"testDirection\": \"<string>\",\n \"multipleComparisonCorrectionMethod\": \"bonferroni\",\n \"multipleComparisonCorrectionScope\": \"variations\",\n \"sequentialTestingEnabled\": true\n },\n \"dataSource\": \"snowflake\",\n \"type\": \"experiment\"\n}"
response = http.request(request)
puts response.read_body{
"key": "experiment-key-123abc",
"name": "Example experiment",
"_maintainerId": "12ab3c45de678910fgh12345",
"_creationDate": "1654104600000",
"environmentKey": "<string>",
"_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/my-experiment",
"type": "application/json"
}
},
"_id": "12ab3c45de678910fgh12345",
"description": "An example experiment, used in testing",
"methodology": "bayesian",
"dataSource": "snowflake",
"assignmentSourceType": "snowflake",
"archivedDate": "1654104600000",
"tags": [
"experiment",
"feature"
],
"holdoutId": "f3b74309-d581-44e1-8a2b-bb2933b4fe40",
"currentIteration": {
"hypothesis": "The new button placement will increase conversion",
"status": "running",
"createdAt": "1654104600000",
"_id": "12ab3c45de678910fgh12345",
"startedAt": "1655314200000",
"endedAt": "1656610200000",
"winningTreatmentId": "122c9f3e-da26-4321-ba68-e0fc02eced58",
"winningReason": "We ran this iteration for two weeks and the winning variation was clear",
"canReshuffleTraffic": true,
"flags": {},
"reallocationFrequencyMillis": 3600000,
"version": 0,
"primaryMetric": {
"key": "metric-key-123abc",
"_versionId": "<string>",
"name": "My metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"isGroup": true,
"isNumeric": true,
"eventKey": "event-key-123abc",
"metrics": [
{
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>",
"nameInGroup": "Step 1",
"randomizationUnits": [
"user"
],
"analysisUnits": [
"user"
]
}
],
"analysisType": "mean",
"analysisUnit": "user"
},
"primarySingleMetric": {
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>"
},
"primaryFunnel": {
"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"
}
},
"metrics": [
{
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>",
"nameInGroup": "Step 1",
"randomizationUnits": [
"user"
],
"analysisUnits": [
"user"
]
}
]
},
"randomizationUnit": "user",
"attributes": [
"<string>"
],
"treatments": [
{
"name": "Treatment 1",
"allocationPercent": "10",
"_id": "122c9f3e-da26-4321-ba68-e0fc02eced58",
"baseline": true,
"parameters": [
{
"variationId": "<string>",
"flagKey": "<string>"
}
],
"assignmentVariantId": "treatment_a"
}
],
"secondaryMetrics": [
{
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>"
}
],
"metrics": [
{
"key": "metric-key-123abc",
"_versionId": "<string>",
"name": "My metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"isGroup": true,
"isNumeric": true,
"eventKey": "event-key-123abc",
"metrics": [
{
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>",
"nameInGroup": "Step 1",
"randomizationUnits": [
"user"
],
"analysisUnits": [
"user"
]
}
],
"analysisType": "mean",
"analysisUnit": "user"
}
],
"layerSnapshot": {
"key": "checkout-flow",
"name": "Checkout Flow",
"reservationPercent": 10,
"otherReservationPercent": 70
},
"covariateInfo": {
"id": "74a49a2b-4834-4246-917e-5d85231d8c2a",
"fileName": "covariate.csv",
"createdAt": "1654104600000"
},
"assignmentDataSource": {
"key": "my-assignment-data-source",
"name": "Snowflake production assignments",
"experimentId": "experiment-123",
"startTime": "1690000000000",
"endTime": "1690000000000"
}
},
"type": "experiment",
"_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>"
}
}
]
},
"draftIteration": {
"hypothesis": "The new button placement will increase conversion",
"status": "running",
"createdAt": "1654104600000",
"_id": "12ab3c45de678910fgh12345",
"startedAt": "1655314200000",
"endedAt": "1656610200000",
"winningTreatmentId": "122c9f3e-da26-4321-ba68-e0fc02eced58",
"winningReason": "We ran this iteration for two weeks and the winning variation was clear",
"canReshuffleTraffic": true,
"flags": {},
"reallocationFrequencyMillis": 3600000,
"version": 0,
"primaryMetric": {
"key": "metric-key-123abc",
"_versionId": "<string>",
"name": "My metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"isGroup": true,
"isNumeric": true,
"eventKey": "event-key-123abc",
"metrics": [
{
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>",
"nameInGroup": "Step 1",
"randomizationUnits": [
"user"
],
"analysisUnits": [
"user"
]
}
],
"analysisType": "mean",
"analysisUnit": "user"
},
"primarySingleMetric": {
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>"
},
"primaryFunnel": {
"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"
}
},
"metrics": [
{
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>",
"nameInGroup": "Step 1",
"randomizationUnits": [
"user"
],
"analysisUnits": [
"user"
]
}
]
},
"randomizationUnit": "user",
"attributes": [
"<string>"
],
"treatments": [
{
"name": "Treatment 1",
"allocationPercent": "10",
"_id": "122c9f3e-da26-4321-ba68-e0fc02eced58",
"baseline": true,
"parameters": [
{
"variationId": "<string>",
"flagKey": "<string>"
}
],
"assignmentVariantId": "treatment_a"
}
],
"secondaryMetrics": [
{
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>"
}
],
"metrics": [
{
"key": "metric-key-123abc",
"_versionId": "<string>",
"name": "My metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"isGroup": true,
"isNumeric": true,
"eventKey": "event-key-123abc",
"metrics": [
{
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>",
"nameInGroup": "Step 1",
"randomizationUnits": [
"user"
],
"analysisUnits": [
"user"
]
}
],
"analysisType": "mean",
"analysisUnit": "user"
}
],
"layerSnapshot": {
"key": "checkout-flow",
"name": "Checkout Flow",
"reservationPercent": 10,
"otherReservationPercent": 70
},
"covariateInfo": {
"id": "74a49a2b-4834-4246-917e-5d85231d8c2a",
"fileName": "covariate.csv",
"createdAt": "1654104600000"
},
"assignmentDataSource": {
"key": "my-assignment-data-source",
"name": "Snowflake production assignments",
"experimentId": "experiment-123",
"startTime": "1690000000000",
"endTime": "1690000000000"
}
},
"previousIterations": [
{
"hypothesis": "The new button placement will increase conversion",
"status": "running",
"createdAt": "1654104600000",
"_id": "12ab3c45de678910fgh12345",
"startedAt": "1655314200000",
"endedAt": "1656610200000",
"winningTreatmentId": "122c9f3e-da26-4321-ba68-e0fc02eced58",
"winningReason": "We ran this iteration for two weeks and the winning variation was clear",
"canReshuffleTraffic": true,
"flags": {},
"reallocationFrequencyMillis": 3600000,
"version": 0,
"primaryMetric": {
"key": "metric-key-123abc",
"_versionId": "<string>",
"name": "My metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"isGroup": true,
"isNumeric": true,
"eventKey": "event-key-123abc",
"metrics": [
{
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>",
"nameInGroup": "Step 1",
"randomizationUnits": [
"user"
],
"analysisUnits": [
"user"
]
}
],
"analysisType": "mean",
"analysisUnit": "user"
},
"primarySingleMetric": {
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>"
},
"primaryFunnel": {
"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"
}
},
"metrics": [
{
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>",
"nameInGroup": "Step 1",
"randomizationUnits": [
"user"
],
"analysisUnits": [
"user"
]
}
]
},
"randomizationUnit": "user",
"attributes": [
"<string>"
],
"treatments": [
{
"name": "Treatment 1",
"allocationPercent": "10",
"_id": "122c9f3e-da26-4321-ba68-e0fc02eced58",
"baseline": true,
"parameters": [
{
"variationId": "<string>",
"flagKey": "<string>"
}
],
"assignmentVariantId": "treatment_a"
}
],
"secondaryMetrics": [
{
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>"
}
],
"metrics": [
{
"key": "metric-key-123abc",
"_versionId": "<string>",
"name": "My metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"isGroup": true,
"isNumeric": true,
"eventKey": "event-key-123abc",
"metrics": [
{
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>",
"nameInGroup": "Step 1",
"randomizationUnits": [
"user"
],
"analysisUnits": [
"user"
]
}
],
"analysisType": "mean",
"analysisUnit": "user"
}
],
"layerSnapshot": {
"key": "checkout-flow",
"name": "Checkout Flow",
"reservationPercent": 10,
"otherReservationPercent": 70
},
"covariateInfo": {
"id": "74a49a2b-4834-4246-917e-5d85231d8c2a",
"fileName": "covariate.csv",
"createdAt": "1654104600000"
},
"assignmentDataSource": {
"key": "my-assignment-data-source",
"name": "Snowflake production assignments",
"experimentId": "experiment-123",
"startTime": "1690000000000",
"endTime": "1690000000000"
}
}
],
"analysisConfig": {
"bayesianThreshold": "<string>",
"significanceThreshold": "<string>",
"testDirection": "<string>",
"multipleComparisonCorrectionMethod": "bonferroni",
"multipleComparisonCorrectionScope": "variations",
"sequentialTestingEnabled": true
},
"mutableFieldsByStatus": {
"not_started": {},
"running": {},
"stopped": {}
}
}{
"code": "invalid_request",
"message": "Invalid request body"
}{
"code": "unauthorized",
"message": "Invalid access token"
}{
"code": "forbidden",
"message": "Forbidden. Access to the requested resource was denied."
}{
"code": "not_found",
"message": "Invalid resource identifier"
}{
"code": "rate_limited",
"message": "You've exceeded the API rate limit. Try again later."
}Create experiment
Create an experiment.
To run this experiment, you’ll need to create an iteration and then update the experiment with the startIteration instruction.
Experiment types
Use the type field to specify the experiment type: experiment (default), mab (multi-armed bandit), or holdout.
For multi-armed bandit experiments, set reallocationFrequencyMillis on the iteration to control how often traffic is reallocated across variations.
Results analysis
Use the methodology field to specify the results analysis approach: frequentist (default) or bayesian. Multi-armed bandit experiments support only bayesian, which is their default.
Use the dataSource field to specify the source of metric data: launchdarkly (default), snowflake, or databricks.
Use the analysisConfig field to customize analysis settings such as the Bayesian threshold, significance threshold, or multiple comparison correction method.
To learn more, read Creating experiments.
curl --request POST \
--url https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/experiments \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "Example experiment",
"key": "experiment-key-123abc",
"iteration": {
"hypothesis": "Example hypothesis, the new button placement will increase conversion",
"metrics": [
{
"key": "metric-key-123abc",
"isGroup": true,
"primary": true,
"analysisUnit": "user"
}
],
"treatments": [
{
"name": "Treatment 1",
"baseline": true,
"allocationPercent": "10",
"parameters": [
{
"flagKey": "example-flag-for-experiment",
"variationId": "e432f62b-55f6-49dd-a02f-eb24acf39d05"
}
],
"assignmentVariantId": "treatment-1"
}
],
"flags": "{\"example-flag-key\": { \"ruleId\": \"e432f62b-55f6-49dd-a02f-eb24acf39d05\", \"flagConfigVersion\": 12, \"notInExperimentVariationId\": \"e432f62b-55f6-49dd-a02f-eb24acf39d05\" }}",
"canReshuffleTraffic": true,
"primarySingleMetricKey": "metric-key-123abc",
"primaryFunnelKey": "metric-group-key-123abc",
"randomizationUnit": "user",
"reallocationFrequencyMillis": 3600000,
"covariateId": "<string>",
"attributes": [
"country",
"device",
"os"
]
},
"description": "An example experiment, used in testing",
"maintainerId": "12ab3c45de678910fgh12345",
"holdoutId": "f3b74309-d581-44e1-8a2b-bb2933b4fe40",
"tags": [
"<string>"
],
"methodology": "frequentist",
"analysisConfig": {
"bayesianThreshold": "10",
"significanceThreshold": "5",
"testDirection": "<string>",
"multipleComparisonCorrectionMethod": "bonferroni",
"multipleComparisonCorrectionScope": "variations",
"sequentialTestingEnabled": true
},
"dataSource": "snowflake",
"type": "experiment"
}
'import requests
url = "https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/experiments"
payload = {
"name": "Example experiment",
"key": "experiment-key-123abc",
"iteration": {
"hypothesis": "Example hypothesis, the new button placement will increase conversion",
"metrics": [
{
"key": "metric-key-123abc",
"isGroup": True,
"primary": True,
"analysisUnit": "user"
}
],
"treatments": [
{
"name": "Treatment 1",
"baseline": True,
"allocationPercent": "10",
"parameters": [
{
"flagKey": "example-flag-for-experiment",
"variationId": "e432f62b-55f6-49dd-a02f-eb24acf39d05"
}
],
"assignmentVariantId": "treatment-1"
}
],
"flags": "{\"example-flag-key\": { \"ruleId\": \"e432f62b-55f6-49dd-a02f-eb24acf39d05\", \"flagConfigVersion\": 12, \"notInExperimentVariationId\": \"e432f62b-55f6-49dd-a02f-eb24acf39d05\" }}",
"canReshuffleTraffic": True,
"primarySingleMetricKey": "metric-key-123abc",
"primaryFunnelKey": "metric-group-key-123abc",
"randomizationUnit": "user",
"reallocationFrequencyMillis": 3600000,
"covariateId": "<string>",
"attributes": ["country", "device", "os"]
},
"description": "An example experiment, used in testing",
"maintainerId": "12ab3c45de678910fgh12345",
"holdoutId": "f3b74309-d581-44e1-8a2b-bb2933b4fe40",
"tags": ["<string>"],
"methodology": "frequentist",
"analysisConfig": {
"bayesianThreshold": "10",
"significanceThreshold": "5",
"testDirection": "<string>",
"multipleComparisonCorrectionMethod": "bonferroni",
"multipleComparisonCorrectionScope": "variations",
"sequentialTestingEnabled": True
},
"dataSource": "snowflake",
"type": "experiment"
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'Example experiment',
key: 'experiment-key-123abc',
iteration: {
hypothesis: 'Example hypothesis, the new button placement will increase conversion',
metrics: [{key: 'metric-key-123abc', isGroup: true, primary: true, analysisUnit: 'user'}],
treatments: [
{
name: 'Treatment 1',
baseline: true,
allocationPercent: '10',
parameters: [
{
flagKey: 'example-flag-for-experiment',
variationId: 'e432f62b-55f6-49dd-a02f-eb24acf39d05'
}
],
assignmentVariantId: 'treatment-1'
}
],
flags: '{"example-flag-key": { "ruleId": "e432f62b-55f6-49dd-a02f-eb24acf39d05", "flagConfigVersion": 12, "notInExperimentVariationId": "e432f62b-55f6-49dd-a02f-eb24acf39d05" }}',
canReshuffleTraffic: true,
primarySingleMetricKey: 'metric-key-123abc',
primaryFunnelKey: 'metric-group-key-123abc',
randomizationUnit: 'user',
reallocationFrequencyMillis: 3600000,
covariateId: '<string>',
attributes: ['country', 'device', 'os']
},
description: 'An example experiment, used in testing',
maintainerId: '12ab3c45de678910fgh12345',
holdoutId: 'f3b74309-d581-44e1-8a2b-bb2933b4fe40',
tags: ['<string>'],
methodology: 'frequentist',
analysisConfig: {
bayesianThreshold: '10',
significanceThreshold: '5',
testDirection: '<string>',
multipleComparisonCorrectionMethod: 'bonferroni',
multipleComparisonCorrectionScope: 'variations',
sequentialTestingEnabled: true
},
dataSource: 'snowflake',
type: 'experiment'
})
};
fetch('https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/experiments', 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/projects/{projectKey}/environments/{environmentKey}/experiments",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => 'Example experiment',
'key' => 'experiment-key-123abc',
'iteration' => [
'hypothesis' => 'Example hypothesis, the new button placement will increase conversion',
'metrics' => [
[
'key' => 'metric-key-123abc',
'isGroup' => true,
'primary' => true,
'analysisUnit' => 'user'
]
],
'treatments' => [
[
'name' => 'Treatment 1',
'baseline' => true,
'allocationPercent' => '10',
'parameters' => [
[
'flagKey' => 'example-flag-for-experiment',
'variationId' => 'e432f62b-55f6-49dd-a02f-eb24acf39d05'
]
],
'assignmentVariantId' => 'treatment-1'
]
],
'flags' => '{"example-flag-key": { "ruleId": "e432f62b-55f6-49dd-a02f-eb24acf39d05", "flagConfigVersion": 12, "notInExperimentVariationId": "e432f62b-55f6-49dd-a02f-eb24acf39d05" }}',
'canReshuffleTraffic' => true,
'primarySingleMetricKey' => 'metric-key-123abc',
'primaryFunnelKey' => 'metric-group-key-123abc',
'randomizationUnit' => 'user',
'reallocationFrequencyMillis' => 3600000,
'covariateId' => '<string>',
'attributes' => [
'country',
'device',
'os'
]
],
'description' => 'An example experiment, used in testing',
'maintainerId' => '12ab3c45de678910fgh12345',
'holdoutId' => 'f3b74309-d581-44e1-8a2b-bb2933b4fe40',
'tags' => [
'<string>'
],
'methodology' => 'frequentist',
'analysisConfig' => [
'bayesianThreshold' => '10',
'significanceThreshold' => '5',
'testDirection' => '<string>',
'multipleComparisonCorrectionMethod' => 'bonferroni',
'multipleComparisonCorrectionScope' => 'variations',
'sequentialTestingEnabled' => true
],
'dataSource' => 'snowflake',
'type' => 'experiment'
]),
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/projects/{projectKey}/environments/{environmentKey}/experiments"
payload := strings.NewReader("{\n \"name\": \"Example experiment\",\n \"key\": \"experiment-key-123abc\",\n \"iteration\": {\n \"hypothesis\": \"Example hypothesis, the new button placement will increase conversion\",\n \"metrics\": [\n {\n \"key\": \"metric-key-123abc\",\n \"isGroup\": true,\n \"primary\": true,\n \"analysisUnit\": \"user\"\n }\n ],\n \"treatments\": [\n {\n \"name\": \"Treatment 1\",\n \"baseline\": true,\n \"allocationPercent\": \"10\",\n \"parameters\": [\n {\n \"flagKey\": \"example-flag-for-experiment\",\n \"variationId\": \"e432f62b-55f6-49dd-a02f-eb24acf39d05\"\n }\n ],\n \"assignmentVariantId\": \"treatment-1\"\n }\n ],\n \"flags\": \"{\\\"example-flag-key\\\": { \\\"ruleId\\\": \\\"e432f62b-55f6-49dd-a02f-eb24acf39d05\\\", \\\"flagConfigVersion\\\": 12, \\\"notInExperimentVariationId\\\": \\\"e432f62b-55f6-49dd-a02f-eb24acf39d05\\\" }}\",\n \"canReshuffleTraffic\": true,\n \"primarySingleMetricKey\": \"metric-key-123abc\",\n \"primaryFunnelKey\": \"metric-group-key-123abc\",\n \"randomizationUnit\": \"user\",\n \"reallocationFrequencyMillis\": 3600000,\n \"covariateId\": \"<string>\",\n \"attributes\": [\n \"country\",\n \"device\",\n \"os\"\n ]\n },\n \"description\": \"An example experiment, used in testing\",\n \"maintainerId\": \"12ab3c45de678910fgh12345\",\n \"holdoutId\": \"f3b74309-d581-44e1-8a2b-bb2933b4fe40\",\n \"tags\": [\n \"<string>\"\n ],\n \"methodology\": \"frequentist\",\n \"analysisConfig\": {\n \"bayesianThreshold\": \"10\",\n \"significanceThreshold\": \"5\",\n \"testDirection\": \"<string>\",\n \"multipleComparisonCorrectionMethod\": \"bonferroni\",\n \"multipleComparisonCorrectionScope\": \"variations\",\n \"sequentialTestingEnabled\": true\n },\n \"dataSource\": \"snowflake\",\n \"type\": \"experiment\"\n}")
req, _ := http.NewRequest("POST", 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.post("https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/experiments")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Example experiment\",\n \"key\": \"experiment-key-123abc\",\n \"iteration\": {\n \"hypothesis\": \"Example hypothesis, the new button placement will increase conversion\",\n \"metrics\": [\n {\n \"key\": \"metric-key-123abc\",\n \"isGroup\": true,\n \"primary\": true,\n \"analysisUnit\": \"user\"\n }\n ],\n \"treatments\": [\n {\n \"name\": \"Treatment 1\",\n \"baseline\": true,\n \"allocationPercent\": \"10\",\n \"parameters\": [\n {\n \"flagKey\": \"example-flag-for-experiment\",\n \"variationId\": \"e432f62b-55f6-49dd-a02f-eb24acf39d05\"\n }\n ],\n \"assignmentVariantId\": \"treatment-1\"\n }\n ],\n \"flags\": \"{\\\"example-flag-key\\\": { \\\"ruleId\\\": \\\"e432f62b-55f6-49dd-a02f-eb24acf39d05\\\", \\\"flagConfigVersion\\\": 12, \\\"notInExperimentVariationId\\\": \\\"e432f62b-55f6-49dd-a02f-eb24acf39d05\\\" }}\",\n \"canReshuffleTraffic\": true,\n \"primarySingleMetricKey\": \"metric-key-123abc\",\n \"primaryFunnelKey\": \"metric-group-key-123abc\",\n \"randomizationUnit\": \"user\",\n \"reallocationFrequencyMillis\": 3600000,\n \"covariateId\": \"<string>\",\n \"attributes\": [\n \"country\",\n \"device\",\n \"os\"\n ]\n },\n \"description\": \"An example experiment, used in testing\",\n \"maintainerId\": \"12ab3c45de678910fgh12345\",\n \"holdoutId\": \"f3b74309-d581-44e1-8a2b-bb2933b4fe40\",\n \"tags\": [\n \"<string>\"\n ],\n \"methodology\": \"frequentist\",\n \"analysisConfig\": {\n \"bayesianThreshold\": \"10\",\n \"significanceThreshold\": \"5\",\n \"testDirection\": \"<string>\",\n \"multipleComparisonCorrectionMethod\": \"bonferroni\",\n \"multipleComparisonCorrectionScope\": \"variations\",\n \"sequentialTestingEnabled\": true\n },\n \"dataSource\": \"snowflake\",\n \"type\": \"experiment\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://app.launchdarkly.com/api/v2/projects/{projectKey}/environments/{environmentKey}/experiments")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"Example experiment\",\n \"key\": \"experiment-key-123abc\",\n \"iteration\": {\n \"hypothesis\": \"Example hypothesis, the new button placement will increase conversion\",\n \"metrics\": [\n {\n \"key\": \"metric-key-123abc\",\n \"isGroup\": true,\n \"primary\": true,\n \"analysisUnit\": \"user\"\n }\n ],\n \"treatments\": [\n {\n \"name\": \"Treatment 1\",\n \"baseline\": true,\n \"allocationPercent\": \"10\",\n \"parameters\": [\n {\n \"flagKey\": \"example-flag-for-experiment\",\n \"variationId\": \"e432f62b-55f6-49dd-a02f-eb24acf39d05\"\n }\n ],\n \"assignmentVariantId\": \"treatment-1\"\n }\n ],\n \"flags\": \"{\\\"example-flag-key\\\": { \\\"ruleId\\\": \\\"e432f62b-55f6-49dd-a02f-eb24acf39d05\\\", \\\"flagConfigVersion\\\": 12, \\\"notInExperimentVariationId\\\": \\\"e432f62b-55f6-49dd-a02f-eb24acf39d05\\\" }}\",\n \"canReshuffleTraffic\": true,\n \"primarySingleMetricKey\": \"metric-key-123abc\",\n \"primaryFunnelKey\": \"metric-group-key-123abc\",\n \"randomizationUnit\": \"user\",\n \"reallocationFrequencyMillis\": 3600000,\n \"covariateId\": \"<string>\",\n \"attributes\": [\n \"country\",\n \"device\",\n \"os\"\n ]\n },\n \"description\": \"An example experiment, used in testing\",\n \"maintainerId\": \"12ab3c45de678910fgh12345\",\n \"holdoutId\": \"f3b74309-d581-44e1-8a2b-bb2933b4fe40\",\n \"tags\": [\n \"<string>\"\n ],\n \"methodology\": \"frequentist\",\n \"analysisConfig\": {\n \"bayesianThreshold\": \"10\",\n \"significanceThreshold\": \"5\",\n \"testDirection\": \"<string>\",\n \"multipleComparisonCorrectionMethod\": \"bonferroni\",\n \"multipleComparisonCorrectionScope\": \"variations\",\n \"sequentialTestingEnabled\": true\n },\n \"dataSource\": \"snowflake\",\n \"type\": \"experiment\"\n}"
response = http.request(request)
puts response.read_body{
"key": "experiment-key-123abc",
"name": "Example experiment",
"_maintainerId": "12ab3c45de678910fgh12345",
"_creationDate": "1654104600000",
"environmentKey": "<string>",
"_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/my-experiment",
"type": "application/json"
}
},
"_id": "12ab3c45de678910fgh12345",
"description": "An example experiment, used in testing",
"methodology": "bayesian",
"dataSource": "snowflake",
"assignmentSourceType": "snowflake",
"archivedDate": "1654104600000",
"tags": [
"experiment",
"feature"
],
"holdoutId": "f3b74309-d581-44e1-8a2b-bb2933b4fe40",
"currentIteration": {
"hypothesis": "The new button placement will increase conversion",
"status": "running",
"createdAt": "1654104600000",
"_id": "12ab3c45de678910fgh12345",
"startedAt": "1655314200000",
"endedAt": "1656610200000",
"winningTreatmentId": "122c9f3e-da26-4321-ba68-e0fc02eced58",
"winningReason": "We ran this iteration for two weeks and the winning variation was clear",
"canReshuffleTraffic": true,
"flags": {},
"reallocationFrequencyMillis": 3600000,
"version": 0,
"primaryMetric": {
"key": "metric-key-123abc",
"_versionId": "<string>",
"name": "My metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"isGroup": true,
"isNumeric": true,
"eventKey": "event-key-123abc",
"metrics": [
{
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>",
"nameInGroup": "Step 1",
"randomizationUnits": [
"user"
],
"analysisUnits": [
"user"
]
}
],
"analysisType": "mean",
"analysisUnit": "user"
},
"primarySingleMetric": {
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>"
},
"primaryFunnel": {
"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"
}
},
"metrics": [
{
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>",
"nameInGroup": "Step 1",
"randomizationUnits": [
"user"
],
"analysisUnits": [
"user"
]
}
]
},
"randomizationUnit": "user",
"attributes": [
"<string>"
],
"treatments": [
{
"name": "Treatment 1",
"allocationPercent": "10",
"_id": "122c9f3e-da26-4321-ba68-e0fc02eced58",
"baseline": true,
"parameters": [
{
"variationId": "<string>",
"flagKey": "<string>"
}
],
"assignmentVariantId": "treatment_a"
}
],
"secondaryMetrics": [
{
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>"
}
],
"metrics": [
{
"key": "metric-key-123abc",
"_versionId": "<string>",
"name": "My metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"isGroup": true,
"isNumeric": true,
"eventKey": "event-key-123abc",
"metrics": [
{
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>",
"nameInGroup": "Step 1",
"randomizationUnits": [
"user"
],
"analysisUnits": [
"user"
]
}
],
"analysisType": "mean",
"analysisUnit": "user"
}
],
"layerSnapshot": {
"key": "checkout-flow",
"name": "Checkout Flow",
"reservationPercent": 10,
"otherReservationPercent": 70
},
"covariateInfo": {
"id": "74a49a2b-4834-4246-917e-5d85231d8c2a",
"fileName": "covariate.csv",
"createdAt": "1654104600000"
},
"assignmentDataSource": {
"key": "my-assignment-data-source",
"name": "Snowflake production assignments",
"experimentId": "experiment-123",
"startTime": "1690000000000",
"endTime": "1690000000000"
}
},
"type": "experiment",
"_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>"
}
}
]
},
"draftIteration": {
"hypothesis": "The new button placement will increase conversion",
"status": "running",
"createdAt": "1654104600000",
"_id": "12ab3c45de678910fgh12345",
"startedAt": "1655314200000",
"endedAt": "1656610200000",
"winningTreatmentId": "122c9f3e-da26-4321-ba68-e0fc02eced58",
"winningReason": "We ran this iteration for two weeks and the winning variation was clear",
"canReshuffleTraffic": true,
"flags": {},
"reallocationFrequencyMillis": 3600000,
"version": 0,
"primaryMetric": {
"key": "metric-key-123abc",
"_versionId": "<string>",
"name": "My metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"isGroup": true,
"isNumeric": true,
"eventKey": "event-key-123abc",
"metrics": [
{
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>",
"nameInGroup": "Step 1",
"randomizationUnits": [
"user"
],
"analysisUnits": [
"user"
]
}
],
"analysisType": "mean",
"analysisUnit": "user"
},
"primarySingleMetric": {
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>"
},
"primaryFunnel": {
"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"
}
},
"metrics": [
{
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>",
"nameInGroup": "Step 1",
"randomizationUnits": [
"user"
],
"analysisUnits": [
"user"
]
}
]
},
"randomizationUnit": "user",
"attributes": [
"<string>"
],
"treatments": [
{
"name": "Treatment 1",
"allocationPercent": "10",
"_id": "122c9f3e-da26-4321-ba68-e0fc02eced58",
"baseline": true,
"parameters": [
{
"variationId": "<string>",
"flagKey": "<string>"
}
],
"assignmentVariantId": "treatment_a"
}
],
"secondaryMetrics": [
{
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>"
}
],
"metrics": [
{
"key": "metric-key-123abc",
"_versionId": "<string>",
"name": "My metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"isGroup": true,
"isNumeric": true,
"eventKey": "event-key-123abc",
"metrics": [
{
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>",
"nameInGroup": "Step 1",
"randomizationUnits": [
"user"
],
"analysisUnits": [
"user"
]
}
],
"analysisType": "mean",
"analysisUnit": "user"
}
],
"layerSnapshot": {
"key": "checkout-flow",
"name": "Checkout Flow",
"reservationPercent": 10,
"otherReservationPercent": 70
},
"covariateInfo": {
"id": "74a49a2b-4834-4246-917e-5d85231d8c2a",
"fileName": "covariate.csv",
"createdAt": "1654104600000"
},
"assignmentDataSource": {
"key": "my-assignment-data-source",
"name": "Snowflake production assignments",
"experimentId": "experiment-123",
"startTime": "1690000000000",
"endTime": "1690000000000"
}
},
"previousIterations": [
{
"hypothesis": "The new button placement will increase conversion",
"status": "running",
"createdAt": "1654104600000",
"_id": "12ab3c45de678910fgh12345",
"startedAt": "1655314200000",
"endedAt": "1656610200000",
"winningTreatmentId": "122c9f3e-da26-4321-ba68-e0fc02eced58",
"winningReason": "We ran this iteration for two weeks and the winning variation was clear",
"canReshuffleTraffic": true,
"flags": {},
"reallocationFrequencyMillis": 3600000,
"version": 0,
"primaryMetric": {
"key": "metric-key-123abc",
"_versionId": "<string>",
"name": "My metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"isGroup": true,
"isNumeric": true,
"eventKey": "event-key-123abc",
"metrics": [
{
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>",
"nameInGroup": "Step 1",
"randomizationUnits": [
"user"
],
"analysisUnits": [
"user"
]
}
],
"analysisType": "mean",
"analysisUnit": "user"
},
"primarySingleMetric": {
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>"
},
"primaryFunnel": {
"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"
}
},
"metrics": [
{
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>",
"nameInGroup": "Step 1",
"randomizationUnits": [
"user"
],
"analysisUnits": [
"user"
]
}
]
},
"randomizationUnit": "user",
"attributes": [
"<string>"
],
"treatments": [
{
"name": "Treatment 1",
"allocationPercent": "10",
"_id": "122c9f3e-da26-4321-ba68-e0fc02eced58",
"baseline": true,
"parameters": [
{
"variationId": "<string>",
"flagKey": "<string>"
}
],
"assignmentVariantId": "treatment_a"
}
],
"secondaryMetrics": [
{
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>"
}
],
"metrics": [
{
"key": "metric-key-123abc",
"_versionId": "<string>",
"name": "My metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"isGroup": true,
"isNumeric": true,
"eventKey": "event-key-123abc",
"metrics": [
{
"key": "metric-key-123abc",
"name": "Example metric",
"kind": "custom",
"_links": {
"self": {
"href": "/api/v2/metrics/my-project/my-metric",
"type": "application/json"
}
},
"_versionId": "version-id-123abc",
"isNumeric": true,
"unitAggregationType": "sum",
"analysisType": "mean",
"eventKey": "event-key-123abc",
"analysisUnit": "<string>",
"nameInGroup": "Step 1",
"randomizationUnits": [
"user"
],
"analysisUnits": [
"user"
]
}
],
"analysisType": "mean",
"analysisUnit": "user"
}
],
"layerSnapshot": {
"key": "checkout-flow",
"name": "Checkout Flow",
"reservationPercent": 10,
"otherReservationPercent": 70
},
"covariateInfo": {
"id": "74a49a2b-4834-4246-917e-5d85231d8c2a",
"fileName": "covariate.csv",
"createdAt": "1654104600000"
},
"assignmentDataSource": {
"key": "my-assignment-data-source",
"name": "Snowflake production assignments",
"experimentId": "experiment-123",
"startTime": "1690000000000",
"endTime": "1690000000000"
}
}
],
"analysisConfig": {
"bayesianThreshold": "<string>",
"significanceThreshold": "<string>",
"testDirection": "<string>",
"multipleComparisonCorrectionMethod": "bonferroni",
"multipleComparisonCorrectionScope": "variations",
"sequentialTestingEnabled": true
},
"mutableFieldsByStatus": {
"not_started": {},
"running": {},
"stopped": {}
}
}{
"code": "invalid_request",
"message": "Invalid request body"
}{
"code": "unauthorized",
"message": "Invalid access token"
}{
"code": "forbidden",
"message": "Forbidden. Access to the requested resource was denied."
}{
"code": "not_found",
"message": "Invalid resource identifier"
}{
"code": "rate_limited",
"message": "You've exceeded the API rate limit. Try again later."
}Path Parameters
Body
Response
Experiment response
The location and content type of related resources
Show child attributes
Show child attributes
{
"parent": {
"href": "/api/v2/projects/my-project/environments/my-environment",
"type": "application/json"
},
"self": {
"href": "/api/v2/projects/my-project/environments/my-environment/experiments/my-experiment",
"type": "application/json"
}
}