Create an Experiment
Create a new experiment in a space. Storyblok creates new experiments in draft status. Optionally, include variants and associate stories with the experiment in the same request.
https://mapi.storyblok.com/v1/spaces/:space_id/experimentsPath parameters
Section titled “Path parameters”:space_idrequired numberNumeric ID of a space.
Request body properties
Section titled “Request body properties”experimentrequired objectThe experiment to create.
Show child properties
namerequired stringTechnical name of the experiment. Lowercase letters, numbers, and underscores only. Immutable after creation.
display_namerequired stringHuman-readable display name of the experiment.
descriptionstringDescription of the experiment.
story_idsnumber[]Array of story IDs to associate with the experiment.
experiment_variants_attributesobject[]Array of variants to create with the experiment. The sum of all variant weights must equal
100.Show child properties
namerequired stringTechnical name of the variant. Lowercase letters, numbers, and underscores only.
display_namerequired stringHuman-readable display name of the variant.
weightnumberTraffic weight of the variant in percent (0–100).
is_controlbooleantrueif the variant is the control (baseline). One variant per experiment must be the control.
Response properties
Section titled “Response properties”experimentThe Experiment ObjectThe created experiment object.
Examples
Section titled “Examples”curl "https://mapi.storyblok.com/v1/spaces/288868932106293/experiments/" \ -X POST \ -H "Authorization: YOUR_PERSONAL_ACCESS_TOKEN" \ -H "Content-Type: application/json" \ -d "{\"experiment\":{\"description\":\"A short description for a simple test\",\"display_name\":\"A simple test\",\"experiment_variants_attributes\":[{\"display_name\":\"Control\",\"is_control\":true,\"name\":\"control\",\"weight\":60},{\"display_name\":\"Test\",\"is_control\":false,\"name\":\"test\",\"weight\":40}],\"name\":\"a_simple_test\",\"story_ids\":[176024833123843]}}"// storyblok-js-client@>=7, node@>=18import Storyblok from "storyblok-js-client";
const storyblok = new Storyblok({ oauthToken: "YOUR_PERSONAL_ACCESS_TOKEN",});
try { const response = await storyblok.post('spaces/288868932106293/experiments/', { "experiment": { "description": "A short description for a simple test", "display_name": "A simple test", "experiment_variants_attributes": [ { "display_name": "Control", "is_control": true, "name": "control", "weight": 60 }, { "display_name": "Test", "is_control": false, "name": "test", "weight": 40 } ], "name": "a_simple_test", "story_ids": [ 176024833123843 ] } }) console.log({ response })} catch (error) { console.log(error)}$client = new \Storyblok\ManagementClient('YOUR_PERSONAL_ACCESS_TOKEN');
$payload = ["experiment" => ["description" => "A short description for a simple test","display_name" => "A simple test","experiment_variants_attributes" => [["display_name" => "Control","is_control" => true,"name" => "control","weight" => 60],["display_name" => "Test","is_control" => false,"name" => "test","weight" => 40]],"name" => "a_simple_test","story_ids" => [176024833123843]]];
$client->post('spaces/288868932106293/experiments/', $payload)->getBody();HttpResponse<String> response = Unirest.post("https://mapi.storyblok.com/v1/spaces/288868932106293/experiments/") .header("Content-Type", "application/json") .header("Authorization", "YOUR_PERSONAL_ACCESS_TOKEN") .body({"experiment":{"description":"A short description for a simple test","display_name":"A simple test","experiment_variants_attributes":[{"display_name":"Control","is_control":true,"name":"control","weight":60},{"display_name":"Test","is_control":false,"name":"test","weight":40}],"name":"a_simple_test","story_ids":[176024833123843]}}) .asString();var client = new RestClient("https://mapi.storyblok.com/v1/spaces/288868932106293/experiments/");var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");request.AddHeader("Authorization", "YOUR_PERSONAL_ACCESS_TOKEN");request.AddParameter("application/json", "{\"experiment\":{\"description\":\"A short description for a simple test\",\"display_name\":\"A simple test\",\"experiment_variants_attributes\":[{\"display_name\":\"Control\",\"is_control\":true,\"name\":\"control\",\"weight\":60},{\"display_name\":\"Test\",\"is_control\":false,\"name\":\"test\",\"weight\":40}],\"name\":\"a_simple_test\",\"story_ids\":[176024833123843]}}", ParameterType.RequestBody);IRestResponse response = client.Execute(request);import requests
url = "https://mapi.storyblok.com/v1/spaces/288868932106293/experiments/"
querystring = {}
payload = {"experiment":{"description":"A short description for a simple test","display_name":"A simple test","experiment_variants_attributes":[{"display_name":"Control","is_control":true,"name":"control","weight":60},{"display_name":"Test","is_control":false,"name":"test","weight":40}],"name":"a_simple_test","story_ids":[176024833123843]}}headers = { 'Content-Type': "application/json", 'Authorization': "YOUR_PERSONAL_ACCESS_TOKEN"}
response = requests.request("POST", url, data=payload, headers=headers, params=querystring)
print(response.text)require 'storyblok'client = Storyblok::Client.new(oauth_token: 'YOUR_PERSONAL_ACCESS_TOKEN')
payload = {"experiment" => {"description" => "A short description for a simple test","display_name" => "A simple test","experiment_variants_attributes" => [{"display_name" => "Control","is_control" => true,"name" => "control","weight" => 60},{"display_name" => "Test","is_control" => false,"name" => "test","weight" => 40}],"name" => "a_simple_test","story_ids" => [176024833123843]}}
client.post('spaces/288868932106293/experiments/', payload)let storyblok = URLSession(storyblok: .mapi(accessToken: .personal("YOUR_PERSONAL_ACCESS_TOKEN")))var request = URLRequest(storyblok: storyblok, path: "spaces/288868932106293/experiments/")request.httpMethod = "POST"request.httpBody = try JSONSerialization.data(withJSONObject: [ "experiment": [ "description": "A short description for a simple test", "display_name": "A simple test", "experiment_variants_attributes": [ [ "display_name": "Control", "is_control": true, "name": "control", "weight": 60, ], [ "display_name": "Test", "is_control": false, "name": "test", "weight": 40, ], ], "name": "a_simple_test", "story_ids": [ 176024833123843, ], ],])let (data, _) = try await storyblok.data(for: request)print(try JSONSerialization.jsonObject(with: data))val client = HttpClient { install(Storyblok(MAPI)) { accessToken = Personal("YOUR_PERSONAL_ACCESS_TOKEN") }}
val response = client.post("spaces/288868932106293/experiments/") { setBody(buildJsonObject { putJsonObject("experiment") { put("description", "A short description for a simple test") put("display_name", "A simple test") putJsonArray("experiment_variants_attributes") { addJsonObject { put("display_name", "Control") put("is_control", true) put("name", "control") put("weight", 60) } addJsonObject { put("display_name", "Test") put("is_control", false) put("name", "test") put("weight", 40) } } put("name", "a_simple_test") putJsonArray("story_ids") { add(176024833123843) } } })}
println(response.body<JsonElement>())Was this page helpful?
This site uses reCAPTCHA and Google's Privacy Policy (opens in a new window).Terms of Service (opens in a new window) apply.
Get in touch with the Storyblok community