Fetch Active Experiments
Endpoint
/o/sdk?method=ab_fetch_experiments
Ⓔ Enterprise Only
This API is available exclusively in Countly Enterprise.
Overview
Fetch active experiments (documents with status missing or status="running") with variant parameters. If the request context includes params.app_user.ab, the response includes currentVariant for matching experiments.
Authentication
Authentication Methods:
- App Key (parameter):
app_key=YOUR_APP_KEY
Permissions
- No additional permissions required
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
app_key | String | Yes | Application key |
device_id | String | No | Device identifier used by SDK context to resolve current user |
Response
Success Response
[
{
"id": "5d4472152de8f07336f3b352",
"name": "My test experiment",
"description": "Experiment description",
"currentVariant": "Control group",
"variants": {
"Control group": {
"button_text": "q"
},
"Variant A": {
"button_text": "w"
}
}
}
]
Response Fields
| Field | Type | Description |
|---|---|---|
id | String | Experiment ObjectId |
name | String | Experiment name |
description | String | Experiment description |
currentVariant | String or null | User's assigned variant name, if available |
variants | Object | Variant name to parameter/value map |
Error Responses
- Query error payload:
{
"result": "Error while fetching ab-testing variants."
}
Behavior/Processing
- Handles
/o/sdk?method=ab_fetch_experimentsand reads experiments fromcountly_out.ab_testing_experiments{appId}. - Includes experiments whose
statusis missing or exactlyrunning; draft and completed experiments are not returned. - Converts each experiment into an SDK-facing object with
id,name,description,currentVariant, and avariantsobject. variantsis keyed by variant name. Each variant value is an object mapping every parameter name in that variant to its configured value.- If the SDK request resolved an app user and
params.app_user.abcontains an assignment for the experiment,currentVariantis set from that assignedvariant_index; otherwise it isnull. - On database errors, returns
Error while fetching ab-testing variants..
Database Collections
| Collection | Used for | Data touched by this endpoint |
|---|---|---|
countly_out.ab_testing_experiments{appId} | Primary: | Experiment definitions and variants. |
params.app_user.ab | Related request context | Current variant is resolved from SDK user assignments when available. |
Examples
Example 1: Fetch Active Experiments
Request:
curl "https://your-server.com/o/sdk?method=ab_fetch_experiments" \
-d "app_key=YOUR_APP_KEY" \
-d "device_id=DEVICE_ID"
Related Endpoints
Ⓔ Enterprise
This feature is part of Countly Enterprise.
Get Access:
Already a Customer? Use support portal if you have any questions
Last Updated
2026-04-18