Skip to main content
Version: 24.05

Get Cohort Members

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​

/o?method=cohort

Overview​

Returns the user IDs (uid) of the users currently in a cohort. For a cohort that is not calculated in real time, it can also start a calculation of the cohort and return a task ID instead.

Authentication​

Pass api_key or auth_token as a query parameter, or send countly-token as a header. See Authentication.

Permissions​

  • Required permission: Read on the cohorts feature

Request Parameters​

ParameterTypeRequiredDescription
api_keyStringYes (or auth_token)API key for authentication
auth_tokenStringYes (or api_key)Auth token for authentication
app_idStringYesApplication identifier
cohortStringYesID of the cohort to read
manualBooleanNoWhen set, the application ID is appended to cohort to build the cohort ID.
generateBooleanNoCalculate the cohort now instead of reading stored members. Ignored when real-time cohorts are enabled or the cohort is manual.
save_reportBooleanNoWith generate, keep the calculation as a saved task even if it finishes quickly.

Examples​

Example 1: Read cohort members​

Request:

curl -X GET "https://your-server.com/o?method=cohort" \
-d "api_key=YOUR_API_KEY" \
-d "app_id=YOUR_APP_ID" \
-d "cohort=COHORT_ID"

Response​

Success Response​

[1, 5, 12, 40]

Response Fields​

FieldTypeDescription
(root array)Arrayuid values of the users that are currently in the cohort.
task_idStringReturned as an object, {"task_id": "..."}, when a calculation of this cohort is already running.

Error Responses​

Status Code: 400 Bad Request

{
"result": "Missing request parameter: cohort"
}
{
"result": "Requested cohort does not exist"
}

Status Code: 406 Not Acceptable

{
"result": "Cannot get cohort results"
}

Behavior​

  • Looks up the cohort by cohort and app_id.
  • If real-time cohorts are enabled, generate is not set, or the cohort is manual, the endpoint reads the uid of every app user that is in the cohort and returns them as an array.
  • Otherwise it starts a calculation of the cohort as a task. If a calculation for the same request is already running, it returns that task's ID. When the calculation finishes quickly the result is returned directly; otherwise the response points to the task.
  • If the drill database is not available, it returns an empty array.
Implementation details

Database Collections

CollectionUsed forData touched by this endpoint
countly.cohortsCohort definitionsReads the requested cohort.
countly.app_users{app_id}Cohort membershipReads uid of users flagged as members of the cohort.
countly.long_tasksTask trackingCreated when a calculation is started.