Skip to main content

Update Cohort

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/cohorts/edit

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

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

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.

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

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

  • 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.

Limitations

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

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.