using Auth0.ManagementApi;
using System.Threading.Tasks;
using Auth0.ManagementApi.Experimentation;
using System.Collections.Generic;
public partial class Examples
{
public async Task Example() {
var client = new ManagementApiClient(
token: "<token>",
clientOptions: new ClientOptions { BaseUrl = "https://{YOUR_DOMAIN}/api/v2" }
);
await client.Experimentation.Experiments.CreateAsync(
new CreateExperimentRequestContent {
Name = "name",
FeatureFlagId = "feature_flag_id",
AuthenticationFlow = "authentication_flow",
AllocationStrategy = AllocationStrategyEnum.Percentage,
AssignmentConfig = new AssignmentConfig {
Subject = SubjectEnum.Device
},
Allocations = new List<AllocationRequestItem>(){
new AllocationRequestItem {
VariationId = "variation_id",
IsControl = true
},
}
}
);
}
}package com.example.usage;
import com.auth0.client.mgmt.ManagementApi;
import com.auth0.client.mgmt.experimentation.types.CreateExperimentRequestContent;
import com.auth0.client.mgmt.types.AllocationRequestItem;
import com.auth0.client.mgmt.types.AllocationStrategyEnum;
import com.auth0.client.mgmt.types.AssignmentConfig;
import com.auth0.client.mgmt.types.SubjectEnum;
import java.util.Arrays;
public class Example {
public static void main(String[] args) {
ManagementApi client = ManagementApi
.builder()
.domain("{YOUR_DOMAIN}")
.token("<token>")
.build();
client.experimentation().experiments().create(
CreateExperimentRequestContent
.builder()
.name("name")
.featureFlagId("feature_flag_id")
.authenticationFlow("authentication_flow")
.allocationStrategy(AllocationStrategyEnum.PERCENTAGE)
.assignmentConfig(
AssignmentConfig
.builder()
.subject(SubjectEnum.DEVICE)
.build()
)
.allocations(
Arrays.asList(
AllocationRequestItem
.builder()
.variationId("variation_id")
.isControl(true)
.build()
)
)
.build()
);
}
}<?php
namespace Example;
use Auth0\SDK\API\Management\Wrapper\ManagementClient;
use Auth0\SDK\API\Management\Wrapper\ManagementClientOptions;
use Auth0\SDK\API\Management\Experimentation\Experiments\Requests\CreateExperimentRequestContent;
use Auth0\SDK\API\Management\Types\AllocationStrategyEnum;
use Auth0\SDK\API\Management\Types\AssignmentConfig;
use Auth0\SDK\API\Management\Types\SubjectEnum;
use Auth0\SDK\API\Management\Types\AllocationRequestItem;
$client = new ManagementClient(new ManagementClientOptions(
domain: '{YOUR_DOMAIN}',
token: '<token>',
));
$client->experimentation->experiments->create(
new CreateExperimentRequestContent([
'name' => 'name',
'featureFlagId' => 'feature_flag_id',
'authenticationFlow' => 'authentication_flow',
'allocationStrategy' => AllocationStrategyEnum::Percentage->value,
'assignmentConfig' => new AssignmentConfig([
'subject' => SubjectEnum::Device->value,
]),
'allocations' => [
new AllocationRequestItem([
'variationId' => 'variation_id',
'isControl' => true,
]),
],
]),
);
from auth0.management import ManagementClient, AssignmentConfig, AllocationRequestItem
client = ManagementClient(
domain="{YOUR_DOMAIN}",
token="<token>",
)
client.experimentation.experiments.create(
name="name",
feature_flag_id="feature_flag_id",
authentication_flow="authentication_flow",
allocation_strategy="percentage",
assignment_config=AssignmentConfig(
subject="device",
),
allocations=[
AllocationRequestItem(
variation_id="variation_id",
is_control=True,
)
],
)
require "auth0"
client = Auth0::Management.new(token: "<token>", base_url: "https://{YOUR_DOMAIN}/api/v2")
client.experimentation.experiments.create(
name: "name",
feature_flag_id: "feature_flag_id",
authentication_flow: "authentication_flow",
allocation_strategy: "percentage",
assignment_config: {
subject: "device"
},
allocations: [{
variation_id: "variation_id",
is_control: true
}]
)
curl --request POST \
--url https://{tenantDomain}/api/v2/experimentation/experiments \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "<string>",
"feature_flag_id": "<string>",
"description": "<string>",
"is_stateful": true,
"allocations": [
{
"variation_id": "<string>",
"is_control": true,
"weight": 50,
"segment_id": "<string>",
"priority": 2,
"is_fallback": true
}
],
"levels": [
123
]
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: '<string>',
feature_flag_id: '<string>',
description: '<string>',
is_stateful: true,
allocations: [
{
variation_id: '<string>',
is_control: true,
weight: 50,
segment_id: '<string>',
priority: 2,
is_fallback: true
}
],
levels: [123]
})
};
fetch('https://{tenantDomain}/api/v2/experimentation/experiments', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{tenantDomain}/api/v2/experimentation/experiments"
payload := strings.NewReader("{\n \"name\": \"<string>\",\n \"feature_flag_id\": \"<string>\",\n \"description\": \"<string>\",\n \"is_stateful\": true,\n \"allocations\": [\n {\n \"variation_id\": \"<string>\",\n \"is_control\": true,\n \"weight\": 50,\n \"segment_id\": \"<string>\",\n \"priority\": 2,\n \"is_fallback\": true\n }\n ],\n \"levels\": [\n 123\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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))
}{
"id": "<string>",
"name": "<string>",
"feature_flag_id": "<string>",
"authentication_flow": "<string>",
"assignment_config": {
"subject": "device"
},
"is_valid": true,
"allocations": [
{
"variation_id": "<string>",
"segment_id": "<string>",
"weight": 123,
"priority": 123,
"is_control": true,
"is_fallback": true,
"variation_snapshot": {}
}
],
"editable_fields": [
"<string>"
],
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"description": "<string>",
"is_stateful": true,
"feature_flag_snapshot": {},
"levels": [
123
],
"started_at": "2023-11-07T05:31:56Z",
"ended_at": "2023-11-07T05:31:56Z"
}Create an experiment for the Experiment Center.
Create a new experiment for A/B testing.
using Auth0.ManagementApi;
using System.Threading.Tasks;
using Auth0.ManagementApi.Experimentation;
using System.Collections.Generic;
public partial class Examples
{
public async Task Example() {
var client = new ManagementApiClient(
token: "<token>",
clientOptions: new ClientOptions { BaseUrl = "https://{YOUR_DOMAIN}/api/v2" }
);
await client.Experimentation.Experiments.CreateAsync(
new CreateExperimentRequestContent {
Name = "name",
FeatureFlagId = "feature_flag_id",
AuthenticationFlow = "authentication_flow",
AllocationStrategy = AllocationStrategyEnum.Percentage,
AssignmentConfig = new AssignmentConfig {
Subject = SubjectEnum.Device
},
Allocations = new List<AllocationRequestItem>(){
new AllocationRequestItem {
VariationId = "variation_id",
IsControl = true
},
}
}
);
}
}package com.example.usage;
import com.auth0.client.mgmt.ManagementApi;
import com.auth0.client.mgmt.experimentation.types.CreateExperimentRequestContent;
import com.auth0.client.mgmt.types.AllocationRequestItem;
import com.auth0.client.mgmt.types.AllocationStrategyEnum;
import com.auth0.client.mgmt.types.AssignmentConfig;
import com.auth0.client.mgmt.types.SubjectEnum;
import java.util.Arrays;
public class Example {
public static void main(String[] args) {
ManagementApi client = ManagementApi
.builder()
.domain("{YOUR_DOMAIN}")
.token("<token>")
.build();
client.experimentation().experiments().create(
CreateExperimentRequestContent
.builder()
.name("name")
.featureFlagId("feature_flag_id")
.authenticationFlow("authentication_flow")
.allocationStrategy(AllocationStrategyEnum.PERCENTAGE)
.assignmentConfig(
AssignmentConfig
.builder()
.subject(SubjectEnum.DEVICE)
.build()
)
.allocations(
Arrays.asList(
AllocationRequestItem
.builder()
.variationId("variation_id")
.isControl(true)
.build()
)
)
.build()
);
}
}<?php
namespace Example;
use Auth0\SDK\API\Management\Wrapper\ManagementClient;
use Auth0\SDK\API\Management\Wrapper\ManagementClientOptions;
use Auth0\SDK\API\Management\Experimentation\Experiments\Requests\CreateExperimentRequestContent;
use Auth0\SDK\API\Management\Types\AllocationStrategyEnum;
use Auth0\SDK\API\Management\Types\AssignmentConfig;
use Auth0\SDK\API\Management\Types\SubjectEnum;
use Auth0\SDK\API\Management\Types\AllocationRequestItem;
$client = new ManagementClient(new ManagementClientOptions(
domain: '{YOUR_DOMAIN}',
token: '<token>',
));
$client->experimentation->experiments->create(
new CreateExperimentRequestContent([
'name' => 'name',
'featureFlagId' => 'feature_flag_id',
'authenticationFlow' => 'authentication_flow',
'allocationStrategy' => AllocationStrategyEnum::Percentage->value,
'assignmentConfig' => new AssignmentConfig([
'subject' => SubjectEnum::Device->value,
]),
'allocations' => [
new AllocationRequestItem([
'variationId' => 'variation_id',
'isControl' => true,
]),
],
]),
);
from auth0.management import ManagementClient, AssignmentConfig, AllocationRequestItem
client = ManagementClient(
domain="{YOUR_DOMAIN}",
token="<token>",
)
client.experimentation.experiments.create(
name="name",
feature_flag_id="feature_flag_id",
authentication_flow="authentication_flow",
allocation_strategy="percentage",
assignment_config=AssignmentConfig(
subject="device",
),
allocations=[
AllocationRequestItem(
variation_id="variation_id",
is_control=True,
)
],
)
require "auth0"
client = Auth0::Management.new(token: "<token>", base_url: "https://{YOUR_DOMAIN}/api/v2")
client.experimentation.experiments.create(
name: "name",
feature_flag_id: "feature_flag_id",
authentication_flow: "authentication_flow",
allocation_strategy: "percentage",
assignment_config: {
subject: "device"
},
allocations: [{
variation_id: "variation_id",
is_control: true
}]
)
curl --request POST \
--url https://{tenantDomain}/api/v2/experimentation/experiments \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "<string>",
"feature_flag_id": "<string>",
"description": "<string>",
"is_stateful": true,
"allocations": [
{
"variation_id": "<string>",
"is_control": true,
"weight": 50,
"segment_id": "<string>",
"priority": 2,
"is_fallback": true
}
],
"levels": [
123
]
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: '<string>',
feature_flag_id: '<string>',
description: '<string>',
is_stateful: true,
allocations: [
{
variation_id: '<string>',
is_control: true,
weight: 50,
segment_id: '<string>',
priority: 2,
is_fallback: true
}
],
levels: [123]
})
};
fetch('https://{tenantDomain}/api/v2/experimentation/experiments', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{tenantDomain}/api/v2/experimentation/experiments"
payload := strings.NewReader("{\n \"name\": \"<string>\",\n \"feature_flag_id\": \"<string>\",\n \"description\": \"<string>\",\n \"is_stateful\": true,\n \"allocations\": [\n {\n \"variation_id\": \"<string>\",\n \"is_control\": true,\n \"weight\": 50,\n \"segment_id\": \"<string>\",\n \"priority\": 2,\n \"is_fallback\": true\n }\n ],\n \"levels\": [\n 123\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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))
}{
"id": "<string>",
"name": "<string>",
"feature_flag_id": "<string>",
"authentication_flow": "<string>",
"assignment_config": {
"subject": "device"
},
"is_valid": true,
"allocations": [
{
"variation_id": "<string>",
"segment_id": "<string>",
"weight": 123,
"priority": 123,
"is_control": true,
"is_fallback": true,
"variation_snapshot": {}
}
],
"editable_fields": [
"<string>"
],
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"description": "<string>",
"is_stateful": true,
"feature_flag_snapshot": {},
"levels": [
123
],
"started_at": "2023-11-07T05:31:56Z",
"ended_at": "2023-11-07T05:31:56Z"
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
Create an experiment with traffic allocation
A human-readable name for the experiment
3 - 255^(?!.*\x00)\S(.*\S)?$The ID of the feature flag this experiment is based on
^flg_[A-HJ-NP-Za-km-z1-9]+$The authentication flow this experiment applies to. Must be one of: authentication, mfa_enrollment, mfa_challenge, password_reset, passkey_enrollment, organization_selection, email_verification.
authentication, mfa_enrollment, mfa_challenge, password_reset, passkey_enrollment, organization_selection, email_verification A description of the experiment
3 - 1024^(?!.*\x00)\S(.*\S)?$Whether the experiment requires stable per-user assignment across its life (EA only)
The traffic allocation strategy for this experiment
percentage, segment Configuration for how users are assigned to variations
Show child attributes
Show child attributes
Traffic allocations mapping variations to weights or segments
1Show child attributes
Show child attributes
Ramp experiment levels configuration.
Response
Experiment successfully created.
^exp_[A-HJ-NP-Za-km-z1-9]+$percentage, segment Show child attributes
Show child attributes
Filter by status. Exact match.
draft, active, paused, completed, archived Show child attributes
Show child attributes
Fields that may be mutated given the experiment's current status. Computed at response time; always current with the API's enforcement logic.
Ramp experiment levels configuration.