Tests
Create, change, delete and copy A/B and multi-variant tests from an agent.
A test lives in one environment. Paths start with /api/agent/organizations/{organizationId}/{environment}/tests. Reading needs any role; creating, changing, deleting and copying need editor or higher.
Create an A/B test
curl -X POST https://improve.obelism.studio/api/agent/organizations/$ORG/staging/tests \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Hero copy",
"options": [
{ "name": "Control", "split": 50 },
{ "name": "Bold", "value": "Try it free", "split": 50 }
],
"events": {
"start": { "event": "page_view", "scope": "/" },
"conversion": { "event": "sign_up", "scope": "hero" }
}
}'| Field | Default |
|---|---|
name | Required |
slug | The slugified name. The SDK looks tests up by it |
type | ab-test |
state | draft. Only active tests are served |
audienceId | null, everyone. Or an audience id |
allocation | 100, the percentage of matching visitors in the test |
options | Control and Variation, 50/50 |
defaultValue | The first option's slug, served to visitors outside the test |
events | None. Set them before going live, or there are no results |
events says what counts: start is the event that enters a visitor in the funnel, conversion is the goal, and metrics are optional steps in between. Each is an { "event", "scope" } pair, the same names your code tracks.
Create a multi-variant test
A multi-variant test has variants instead of options: dimensions whose values are combined. Every combination is an option, with an equal split.
{
"name": "Buy button",
"type": "multi-variant-test",
"variants": [
{ "name": "Colour", "values": ["red", "blue"] },
{ "name": "Size", "values": ["small", "large"] }
]
}This serves red-small, red-large, blue-small and blue-large. Its defaultValue is the first combination.
Change a test
PATCH .../tests/{testId} changes the fields you send. To start a test:
curl -X PATCH https://improve.obelism.studio/api/agent/organizations/$ORG/staging/tests/$TEST \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"state":"active"}'optionsandvariantsare the full new list. An item with anidupdates it, one without is added, and items you leave out are deleted.- Changing
typeneeds the new list, for examplevariantsto switch to a multi-variant test. eventsmerges:start,metricsandconversionyou leave out keep their value. Changing events recalculates the results.
The whole body is checked before anything is saved, so an invalid field changes nothing.
Copy tests to another environment
Copies tests with their state, options and events, like Sync in the dashboard. Results are not copied.
curl -X POST https://improve.obelism.studio/api/agent/organizations/$ORG/staging/tests/sync \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"testIds":["test_01H8XYZ"],"targetEnvironment":"production"}'{ "created": 1, "overwritten": 0 }When a test with the same slug already exists in the target, nothing is copied and the answer is 409 slug_conflict, with a conflicts list. Send "overwrite": true to replace them.
Other operations
| Method | Path | Does |
|---|---|---|
GET | /tests | List the tests, without options and variants |
GET | /tests/{testId} | Get one test with its options or variants |
DELETE | /tests/{testId} | Delete the test and its exposures (204) |