Enroll User in Variant
Endpoint
/i?method=ab_enroll_variant
Ⓔ Enterprise Only
This API is available exclusively in Countly Enterprise.
Overview
Manually enroll a user into a specific variant for the experiment that contains the given parameter key. This overrides percentage-based assignment for that user and experiment.
Authentication
Authentication Methods:
- App Key (parameter):
app_key=YOUR_APP_KEY
Permissions
- No additional permissions required
Request Parameters
Content-Type: application/x-www-form-urlencoded
| Parameter | Type | Required | Description |
|---|---|---|---|
app_key | String | Yes | Application key |
device_id | String | Yes | Device ID for the target user |
key | String | Yes | Experiment parameter key to locate the experiment |
variant | String | Yes | Variant name to enroll the user into |
Response
Success Response
{
"result": "Success"
}
Response Fields
| Field | Type | Description |
|---|---|---|
result | String | Result message |
Error Responses
- Missing key:
{
"result": "Invalid request, key is missing"
}
- Variant not found:
{
"result": "Variant not found"
}
Examples
Example 1: Enroll User into Variant
Request:
curl "https://your-server.com/i?method=ab_enroll_variant" \
-d "app_key=YOUR_APP_KEY" \
-d "device_id=DEVICE_ID" \
-d "key=button_color" \
-d "variant=Red Button"
Response:
{
"result": "Success"
}
Behavior/Processing
- Dispatches from
/ito the SDK ingestion handler whenmethod=ab_enroll_variant. - Requires
key; the handler converts it tokeys=["<key>"]and fetches running experiments that contain that parameter. - Looks for a variant whose
namematchesvariantand whose parameters include the requestedkey. - If a match is found, removes any existing assignment for that experiment from
app_users{appId}.ab, then adds{experiment_id, variant_index}for the selected variant. - If no running experiment is found for the key, returns
No experiments found. If the experiment exists but no matching variant/key pair exists, returnsVariant not found. - Variant matching is exact after converting the requested
variantto a string.
Database Collections
| Collection | Used for | Data touched by this endpoint |
|---|---|---|
countly.app_users{appId} | Primary: | Updates the ab field for the enrolled user. |
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