Cohorts - Read Cohort Results
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 calculated results of a cohort. Depending on the cohort type and the generate parameter, results are read from the stored cache or calculated in a background task.
Authentication
Pass api_key or auth_token as a query parameter, or send countly-token as a header. See Authentication.
Permissions
Requires cohorts Read permission.
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
method | String | Yes | Must be cohort. |
app_id | String | Yes | Application ID. |
cohort | String | Yes | Cohort ID. |
manual | Boolean/String | No | When set, the application ID is appended to cohort to build the cohort ID. |
generate | Boolean/String | No | When set for a non-manual cohort, the results are calculated instead of read from the cache. Ignored when real-time cohorts are enabled. |
save_report | Boolean/String | No | With generate, keeps the calculation as a saved report. |
api_key | String | Conditional | Required if auth_token is not provided. |
auth_token | String | Conditional | Required if api_key is not provided. |
Examples
Read cached results of a cohort
/o?method=cohort&
app_id=6991c75b024cb89cdc04efd2&
api_key=YOUR_API_KEY&
cohort=65f0cbf8bca6b8e8fbf7f901
Calculate the results
/o?method=cohort&
app_id=6991c75b024cb89cdc04efd2&
api_key=YOUR_API_KEY&
cohort=65f0cbf8bca6b8e8fbf7f901&
generate=true
Response
Success Response
The cohort's stored results are returned as the response body. When the results are being calculated in a background task, a task reference is returned instead:
{
"task_id": "65f1f7b2ad5b9b001f12ab34"
}
An empty array ([]) is returned if the server has no Drill database connection.
Error Responses
400
{
"result": "Missing request parameter: cohort"
}
400
{
"result": "Requested cohort does not exist"
}
406
{
"result": "Cannot get cohort results"
}
Behavior
Behavior Modes
| Mode | Condition | Result |
|---|---|---|
| Cached read | Real-time cohorts are enabled, generate is not set, or the cohort is manual | Returns the stored results of the cohort. |
| Calculation | generate is set, real-time cohorts are disabled, and the cohort is not manual | Calculates the results in a background task. Returns the task_id of a task that is already running for the same request. |