Skip to main content

Enroll User in Variant

Enterprise

This endpoint is part of Countly Enterprise. To get access, contact sales or compare versions. Existing customers can reach the support portal with questions.

Endpoint

/i?method=ab_enroll_variant

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

ParameterTypeRequiredDescription
app_keyStringYesApplication key
device_idStringYesDevice ID for the target user
keyStringYesExperiment parameter key to locate the experiment
variantStringYesVariant name to enroll the user into

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"
}

Response

Success Response

{
"result": "Success"
}

Response Fields

FieldTypeDescription
resultStringResult message

Error Responses

  • Missing key:
{
"result": "Invalid request, key is missing"
}
  • Variant not found:
{
"result": "Variant not found"
}

Behavior

  • Dispatches from /i to the SDK ingestion handler when method=ab_enroll_variant.
  • Requires key; the handler converts it to keys=["<key>"] and fetches running experiments that contain that parameter.
  • Looks for a variant whose name matches variant and whose parameters include the requested key.
  • 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, returns Variant not found.
  • Variant matching is exact after converting the requested variant to a string.
Implementation details

Database Collections

CollectionUsed forData touched by this endpoint
countly.app_users{appId}Primary:Updates the ab field for the enrolled user.