Skip to main content

Update Cohort

Endpoint

/i/cohorts/edit

Enterprise Only
This API is available exclusively in Countly Enterprise.

Overview

Updates an existing cohort definition or metadata (name/description/steps/segmentation/visibility/group sharing fields).
If segmentation-related fields change, existing cohort data is reset and recalculation is triggered.

Authentication

  • API key parameter: api_key
  • Auth token parameter: auth_token
  • Auth token header: countly-token

Permissions

  • Required permission: Create on cohorts
  • If type=manual, required permission is Create on profile groups

Request Parameters

ParameterTypeRequiredDescription
api_keyStringYes (or auth_token)Authentication credential
auth_tokenStringYes (or api_key)Authentication credential
app_idStringYesApp identifier
cohort_idStringYesCohort ID to update
cohort_nameStringNoNew cohort name
cohort_descStringNoNew cohort description
stepsArrayNoUpdated steps. If sent in query/body text, pass as JSON string
user_segmentationObjectNoUpdated user segmentation. If sent in query/body text, pass as JSON string
visibilityStringYes (current handler behavior)Allowed values: global, private
shared_email_editArrayNoUpdated shared edit users (JSON string when passed in query/body text)

At least one updatable field should be provided with cohort_id.
Current handler also validates visibility as required, even when only metadata fields are edited.

Response

Success Response

{
"result": "Success"
}

Response Fields

FieldTypeDescription
resultStringOperation result string

Error Responses

HTTP StatusError ResponseDescription
400{"result":"Not enough args"}Required inputs missing
400{"result":"Invalid visibility"}visibility is not global/private
400{"result":"All steps must contain event"}Step missing event
400{"result":"All steps must contain type"}Step missing type
400{"result":"All steps must contain period"}Step missing period
400{"result":"Cannot save data"}Update operation failed
404{"result":"Cohort not found"}Cohort ID not found for app

Notes:

  • Auth/permission failures are handled by authentication and permission validation.

Behavior/Processing

  • Parses steps, user_segmentation, and shared_email_edit from JSON strings when passed as strings.
  • Normalizes cohort_name to stored field name.
  • If segmentation changed:
    • clears cohort historical data from cohortdata
    • unsets chr.<cohort_id> for all app_users{app_id} rows
    • triggers recalculation/setup flow
    • marks related reports dirty
  • If only metadata changed (for example name/description), recalculation is not forced.
  • Writes system log entry with before/update payload.

Database Collections

CollectionUsed forData touched by this endpoint
countly.cohortsEndpoint data sourceStores endpoint-related records this endpoint reads or modifies.
countly.cohortdataEndpoint data sourceStores endpoint-related records this endpoint reads or modifies.
countly.app_users{app_id}Per-app user profilesStores user-level properties and profile fields affected by this endpoint.
countly.systemlogsAudit trailContains system action records used by this endpoint for audit output or audit writes.

Examples

Example 1: Rename Cohort

https://your-server.com/i/cohorts/edit
?api_key=API_KEY
&app_id=APP_ID
&cohort_id=COHORT_ID
&cohort_name=High Intent Users
&visibility=global

Example 2: Update Segmentation Steps

https://your-server.com/i/cohorts/edit
?api_key=API_KEY
&app_id=APP_ID
&cohort_id=COHORT_ID
&steps=[{"event":"[CLY]_session","type":"did","period":"30days"}]
&visibility=private

Decoded payload:

{
"cohort_id": "COHORT_ID",
"visibility": "private",
"steps": [
{
"event": "[CLY]_session",
"type": "did",
"period": "30days"
}
]
}

Example 3: Update User Segmentation

https://your-server.com/i/cohorts/edit
?api_key=API_KEY
&app_id=APP_ID
&cohort_id=COHORT_ID
&user_segmentation={"query":{"up.country":"DE"}}
&visibility=global

Limitations

  • visibility must be valid when provided.
  • JSON-string parameters must be valid JSON.
  • Segmentation changes reset historical cohort data for the cohort.


Ⓔ Enterprise

This feature is part of Countly Enterprise.

Get Access:

Already a Customer? Use support portal if you have any questions.


Last Updated

2026-02-16