Cohorts

For instructions on how to authenticate to use this endpoint, see API overview.

Endpoints

GET
POST
GET
PATCH
DELETE
GET
PATCH
GET
GET
GET
PATCH
GET

List all cohorts

Required API key scopes

cohort:read

Path parameters

  • project_id
    string

    Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/.


Query parameters

  • limit
    integer

    Number of results to return per page.

  • offset
    integer

    The initial index from which to return the results.


Response


Example request

GET /api/projects/:project_id/cohorts
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/cohorts/

Example response

Status 200
RESPONSE
{
"count": 123,
"next": "http://api.example.org/accounts/?offset=400&limit=100",
"previous": "http://api.example.org/accounts/?offset=200&limit=100",
"results": [
{
"id": 0,
"name": "string",
"description": "string",
"groups": null,
"deleted": true,
"filters": null,
"query": null,
"is_calculating": true,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {
"property1": null,
"property2": null
},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"last_calculation": "2019-08-24T14:15:22Z",
"errors_calculating": 0,
"count": 0,
"is_static": true,
"cohort_type": "static",
"experiment_set": [
0
],
"_create_in_folder": "string",
"_create_static_person_ids": [
"string"
]
}
]
}

Create cohorts

Required API key scopes

cohort:write

Path parameters

  • project_id
    string

    Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/.


Request parameters

  • name
    string
  • description
    string
  • groups
  • deleted
    boolean
  • filters

    Filters for the cohort. Examples:

        # Behavioral filter (performed event)
        {
            "properties": {
                "type": "OR",
                "values": [{
                    "type": "OR",
                    "values": [{
                        "key": "address page viewed",
                        "type": "behavioral",
                        "value": "performed_event",
                        "negation": false,
                        "event_type": "events",
                        "time_value": "30",
                        "time_interval": "day"
                    }]
                }]
            }
        }
    
        # Person property filter
        {
            "properties": {
                "type": "OR",
                "values": [{
                    "type": "AND",
                    "values": [{
                        "key": "promoCodes",
                        "type": "person",
                        "value": ["1234567890"],
                        "negation": false,
                        "operator": "exact"
                    }]
                }]
            }
        }
    
        # Cohort filter
        {
            "properties": {
                "type": "OR",
                "values": [{
                    "type": "AND",
                    "values": [{
                        "key": "id",
                        "type": "cohort",
                        "value": 8814,
                        "negation": false
                    }]
                }]
            }
        }
    
  • query
  • is_static
    boolean
  • cohort_type

    Type of cohort based on filter complexity

    • static - static
    • person_property - person_property
    • behavioral - behavioral
    • analytical - analytical
  • _create_in_folder
    string
  • _create_static_person_ids
    array

Response


Example request

POST /api/projects/:project_id/cohorts
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/cohorts/\
-d name="string"

Example response

Status 201
RESPONSE
{
"id": 0,
"name": "string",
"description": "string",
"groups": null,
"deleted": true,
"filters": null,
"query": null,
"is_calculating": true,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {
"property1": null,
"property2": null
},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"last_calculation": "2019-08-24T14:15:22Z",
"errors_calculating": 0,
"count": 0,
"is_static": true,
"cohort_type": "static",
"experiment_set": [
0
],
"_create_in_folder": "string",
"_create_static_person_ids": [
"string"
]
}

Retrieve cohorts

Required API key scopes

cohort:read

Path parameters

  • id
    integer

    A unique integer value identifying this cohort.

  • project_id
    string

    Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/.


Response


Example request

GET /api/projects/:project_id/cohorts/:id
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/cohorts/:id/

Example response

Status 200
RESPONSE
{
"id": 0,
"name": "string",
"description": "string",
"groups": null,
"deleted": true,
"filters": null,
"query": null,
"is_calculating": true,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {
"property1": null,
"property2": null
},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"last_calculation": "2019-08-24T14:15:22Z",
"errors_calculating": 0,
"count": 0,
"is_static": true,
"cohort_type": "static",
"experiment_set": [
0
],
"_create_in_folder": "string",
"_create_static_person_ids": [
"string"
]
}

Update cohorts

Required API key scopes

cohort:write

Path parameters

  • id
    integer

    A unique integer value identifying this cohort.

  • project_id
    string

    Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/.


Request parameters

  • name
    string
  • description
    string
  • groups
  • deleted
    boolean
  • filters

    Filters for the cohort. Examples:

        # Behavioral filter (performed event)
        {
            "properties": {
                "type": "OR",
                "values": [{
                    "type": "OR",
                    "values": [{
                        "key": "address page viewed",
                        "type": "behavioral",
                        "value": "performed_event",
                        "negation": false,
                        "event_type": "events",
                        "time_value": "30",
                        "time_interval": "day"
                    }]
                }]
            }
        }
    
        # Person property filter
        {
            "properties": {
                "type": "OR",
                "values": [{
                    "type": "AND",
                    "values": [{
                        "key": "promoCodes",
                        "type": "person",
                        "value": ["1234567890"],
                        "negation": false,
                        "operator": "exact"
                    }]
                }]
            }
        }
    
        # Cohort filter
        {
            "properties": {
                "type": "OR",
                "values": [{
                    "type": "AND",
                    "values": [{
                        "key": "id",
                        "type": "cohort",
                        "value": 8814,
                        "negation": false
                    }]
                }]
            }
        }
    
  • query
  • is_static
    boolean
  • cohort_type

    Type of cohort based on filter complexity

    • static - static
    • person_property - person_property
    • behavioral - behavioral
    • analytical - analytical
  • _create_in_folder
    string
  • _create_static_person_ids
    array

Response


Example request

PATCH /api/projects/:project_id/cohorts/:id
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl -X PATCH \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/cohorts/:id/\
-d name="string"

Example response

Status 200
RESPONSE
{
"id": 0,
"name": "string",
"description": "string",
"groups": null,
"deleted": true,
"filters": null,
"query": null,
"is_calculating": true,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {
"property1": null,
"property2": null
},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"last_calculation": "2019-08-24T14:15:22Z",
"errors_calculating": 0,
"count": 0,
"is_static": true,
"cohort_type": "static",
"experiment_set": [
0
],
"_create_in_folder": "string",
"_create_static_person_ids": [
"string"
]
}

Delete cohorts

Hard delete of this model is not allowed. Use a patch API call to set "deleted" to true

Required API key scopes

cohort:write

Path parameters

  • id
    integer

    A unique integer value identifying this cohort.

  • project_id
    string

    Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/.


Example request

DELETE /api/projects/:project_id/cohorts/:id
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl -X DELETE \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/cohorts/:id/

Example response

Status 405 No response body

Retrieve cohorts activity retrieve

Required API key scopes

activity_log:read

Path parameters

  • id
    integer

    A unique integer value identifying this cohort.

  • project_id
    string

    Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/.


Example request

GET /api/projects/:project_id/cohorts/:id/activity
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/cohorts/:id/activity/

Example response

Status 200 No response body

Update cohorts add persons to static cohort

Required API key scopes

cohort:write

Path parameters

  • id
    integer

    A unique integer value identifying this cohort.

  • project_id
    string

    Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/.


Request parameters

  • person_ids
    array

    List of person UUIDs to add to the cohort


Example request

PATCH /api/projects/:project_id/cohorts/:id/add_persons_to_static_cohort
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl -X PATCH \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/cohorts/:id/add_persons_to_static_cohort/\
-d person_ids="array"

Example response

Status 200 No response body

Retrieve cohorts calculation history

Required API key scopes

cohort:read

Path parameters

  • id
    integer

    A unique integer value identifying this cohort.

  • project_id
    string

    Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/.


Example request

GET /api/projects/:project_id/cohorts/:id/calculation_history
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/cohorts/:id/calculation_history/

Example response

Status 200 No response body

Retrieve cohorts duplicate as static cohort

Create a static copy of a dynamic cohort

Required API key scopes

cohort:write

Path parameters

  • id
    integer

    A unique integer value identifying this cohort.

  • project_id
    string

    Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/.


Example request

GET /api/projects/:project_id/cohorts/:id/duplicate_as_static_cohort
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/cohorts/:id/duplicate_as_static_cohort/

Example response

Status 200 No response body

Retrieve cohorts persons

Required API key scopes

cohort:readperson:read

Path parameters

  • id
    integer

    A unique integer value identifying this cohort.

  • project_id
    string

    Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/.


Query parameters

  • format
    string
    One of: "csv""json"

Example request

GET /api/projects/:project_id/cohorts/:id/persons
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/cohorts/:id/persons/

Example response

Status 200 No response body

Update cohorts remove person from static cohort

Required API key scopes

cohort:write

Path parameters

  • id
    integer

    A unique integer value identifying this cohort.

  • project_id
    string

    Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/.


Request parameters

  • person_id
    string

    Person UUID to remove from the cohort


Example request

PATCH /api/projects/:project_id/cohorts/:id/remove_person_from_static_cohort
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl -X PATCH \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/cohorts/:id/remove_person_from_static_cohort/\
-d person_id="string"

Example response

Status 200 No response body

Retrieve cohorts activity

Required API key scopes

activity_log:read

Path parameters

  • project_id
    string

    Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/.


Example request

GET /api/projects/:project_id/cohorts/activity
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/cohorts/activity/

Example response

Status 200 No response body

Community questions

Questions about this page? or post a community question.