PostHog cohorts API

The cohorts API from PostHog — 8 operation(s) for cohorts.

OpenAPI Specification

posthog-cohorts-api-openapi.yml Raw ↑
openapi: 3.0.3
info:
  title: PostHog actions cohorts API
  version: 1.0.0
  description: ''
tags:
- name: cohorts
paths:
  /api/projects/{project_id}/cohorts/:
    get:
      operationId: cohorts_list
      parameters:
      - name: limit
        required: false
        in: query
        description: Number of results to return per page.
        schema:
          type: integer
      - name: offset
        required: false
        in: query
        description: The initial index from which to return the results.
        schema:
          type: integer
      - $ref: '#/components/parameters/ProjectIdPath'
      tags:
      - cohorts
      security:
      - PersonalAPIKeyAuth:
        - cohort:read
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PaginatedCohortList'
          description: ''
      x-explicit-tags:
      - core
    post:
      operationId: cohorts_create
      parameters:
      - $ref: '#/components/parameters/ProjectIdPath'
      tags:
      - cohorts
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Cohort'
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/Cohort'
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/Cohort'
      security:
      - PersonalAPIKeyAuth:
        - cohort:write
      responses:
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Cohort'
          description: ''
      x-explicit-tags:
      - core
  /api/projects/{project_id}/cohorts/{id}/:
    get:
      operationId: cohorts_retrieve
      parameters:
      - in: path
        name: id
        schema:
          type: integer
        description: A unique integer value identifying this cohort.
        required: true
      - $ref: '#/components/parameters/ProjectIdPath'
      tags:
      - cohorts
      security:
      - PersonalAPIKeyAuth:
        - cohort:read
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Cohort'
          description: ''
      x-explicit-tags:
      - core
    put:
      operationId: cohorts_update
      parameters:
      - in: path
        name: id
        schema:
          type: integer
        description: A unique integer value identifying this cohort.
        required: true
      - $ref: '#/components/parameters/ProjectIdPath'
      tags:
      - cohorts
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Cohort'
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/Cohort'
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/Cohort'
      security:
      - PersonalAPIKeyAuth:
        - cohort:write
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Cohort'
          description: ''
      x-explicit-tags:
      - core
    patch:
      operationId: cohorts_partial_update
      parameters:
      - in: path
        name: id
        schema:
          type: integer
        description: A unique integer value identifying this cohort.
        required: true
      - $ref: '#/components/parameters/ProjectIdPath'
      tags:
      - cohorts
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PatchedCohort'
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/PatchedCohort'
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/PatchedCohort'
      security:
      - PersonalAPIKeyAuth:
        - cohort:write
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Cohort'
          description: ''
      x-explicit-tags:
      - core
    delete:
      operationId: cohorts_destroy
      description: Hard delete of this model is not allowed. Use a patch API call to set "deleted" to true
      parameters:
      - in: path
        name: id
        schema:
          type: integer
        description: A unique integer value identifying this cohort.
        required: true
      - $ref: '#/components/parameters/ProjectIdPath'
      tags:
      - cohorts
      security:
      - PersonalAPIKeyAuth:
        - cohort:write
      responses:
        '405':
          description: No response body
      x-explicit-tags:
      - core
  /api/projects/{project_id}/cohorts/{id}/activity/:
    get:
      operationId: cohorts_activity_retrieve
      parameters:
      - in: path
        name: id
        schema:
          type: integer
        description: A unique integer value identifying this cohort.
        required: true
      - $ref: '#/components/parameters/ProjectIdPath'
      tags:
      - cohorts
      security:
      - PersonalAPIKeyAuth:
        - activity_log:read
      responses:
        '200':
          description: No response body
      x-explicit-tags:
      - core
  /api/projects/{project_id}/cohorts/{id}/add_persons_to_static_cohort/:
    patch:
      operationId: cohorts_add_persons_to_static_cohort_partial_update
      parameters:
      - in: path
        name: id
        schema:
          type: integer
        description: A unique integer value identifying this cohort.
        required: true
      - $ref: '#/components/parameters/ProjectIdPath'
      tags:
      - cohorts
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PatchedAddPersonsToStaticCohortRequest'
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/PatchedAddPersonsToStaticCohortRequest'
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/PatchedAddPersonsToStaticCohortRequest'
      security:
      - PersonalAPIKeyAuth:
        - cohort:write
      responses:
        '200':
          description: No response body
      x-explicit-tags:
      - core
  /api/projects/{project_id}/cohorts/{id}/calculation_history/:
    get:
      operationId: cohorts_calculation_history_retrieve
      parameters:
      - in: path
        name: id
        schema:
          type: integer
        description: A unique integer value identifying this cohort.
        required: true
      - $ref: '#/components/parameters/ProjectIdPath'
      tags:
      - cohorts
      security:
      - PersonalAPIKeyAuth:
        - cohort:read
      responses:
        '200':
          description: No response body
      x-explicit-tags:
      - core
  /api/projects/{project_id}/cohorts/{id}/persons/:
    get:
      operationId: cohorts_persons_retrieve
      parameters:
      - in: query
        name: format
        schema:
          type: string
          enum:
          - csv
          - json
      - in: path
        name: id
        schema:
          type: integer
        description: A unique integer value identifying this cohort.
        required: true
      - in: query
        name: limit
        schema:
          type: integer
        description: Maximum number of persons to return per page (defaults to 100).
      - in: query
        name: offset
        schema:
          type: integer
        description: Number of persons to skip before starting to return results.
      - $ref: '#/components/parameters/ProjectIdPath'
      tags:
      - cohorts
      security:
      - PersonalAPIKeyAuth:
        - cohort:read
        - person:read
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CohortPersonsResponse'
            text/csv:
              schema:
                $ref: '#/components/schemas/CohortPersonsResponse'
          description: ''
      x-explicit-tags:
      - core
  /api/projects/{project_id}/cohorts/{id}/remove_person_from_static_cohort/:
    patch:
      operationId: cohorts_remove_person_from_static_cohort_partial_update
      parameters:
      - in: path
        name: id
        schema:
          type: integer
        description: A unique integer value identifying this cohort.
        required: true
      - $ref: '#/components/parameters/ProjectIdPath'
      tags:
      - cohorts
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PatchedRemovePersonRequest'
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/PatchedRemovePersonRequest'
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/PatchedRemovePersonRequest'
      security:
      - PersonalAPIKeyAuth:
        - cohort:write
      responses:
        '200':
          description: No response body
      x-explicit-tags:
      - core
  /api/projects/{project_id}/cohorts/activity/:
    get:
      operationId: cohorts_all_activity_retrieve
      parameters:
      - $ref: '#/components/parameters/ProjectIdPath'
      tags:
      - cohorts
      security:
      - PersonalAPIKeyAuth:
        - activity_log:read
      responses:
        '200':
          description: No response body
      x-explicit-tags:
      - core
components:
  schemas:
    PatchedRemovePersonRequest:
      type: object
      properties:
        person_id:
          type: string
          format: uuid
          description: Person UUID to remove from the cohort
    HogQLFilter:
      additionalProperties: false
      properties:
        type:
          title: Type
          type: string
          enum:
          - hogql
        key:
          title: Key
          type: string
        value:
          default: null
          title: Value
          nullable: true
      required:
      - type
      - key
      title: HogQLFilter
      type: object
    EventPropFilter:
      additionalProperties: false
      properties:
        type:
          allOf:
          - $ref: '#/components/schemas/EventPropFilterTypeEnum'
          title: Type
        key:
          title: Key
          type: string
        value:
          title: Value
        operator:
          default: null
          title: Operator
          type: string
          nullable: true
      required:
      - type
      - key
      - value
      title: EventPropFilter
      type: object
    PatchedCohort:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        name:
          type: string
          nullable: true
          maxLength: 400
        description:
          type: string
          maxLength: 1000
        groups: {}
        deleted:
          type: boolean
        filters:
          allOf:
          - $ref: '#/components/schemas/CohortFilters'
          nullable: true
        query:
          nullable: true
        version:
          type: integer
          readOnly: true
          nullable: true
        pending_version:
          type: integer
          readOnly: true
          nullable: true
        is_calculating:
          type: boolean
          readOnly: true
        created_by:
          allOf:
          - $ref: '#/components/schemas/UserBasic'
          readOnly: true
        created_at:
          type: string
          format: date-time
          readOnly: true
          nullable: true
        last_calculation:
          type: string
          format: date-time
          readOnly: true
          nullable: true
        last_backfill_person_properties_at:
          type: string
          format: date-time
          readOnly: true
          nullable: true
        errors_calculating:
          type: integer
          readOnly: true
        last_error_message:
          type: string
          nullable: true
          readOnly: true
        count:
          type: integer
          readOnly: true
          nullable: true
        is_static:
          type: boolean
        cohort_type:
          nullable: true
          description: 'Type of cohort based on filter complexity


            * `static` - static

            * `person_property` - person_property

            * `behavioral` - behavioral

            * `realtime` - realtime

            * `analytical` - analytical'
          oneOf:
          - $ref: '#/components/schemas/CohortTypeEnum'
          - $ref: '#/components/schemas/BlankEnum'
          - $ref: '#/components/schemas/NullEnum'
        experiment_set:
          type: array
          items:
            type: integer
          readOnly: true
        _create_in_folder:
          type: string
          writeOnly: true
          title: ' create in folder'
        _create_static_person_ids:
          type: array
          items:
            type: string
          writeOnly: true
          default: []
          title: ' create static person ids'
    CohortFilters:
      additionalProperties: false
      properties:
        properties:
          $ref: '#/components/schemas/CohortFilterGroup'
      required:
      - properties
      title: CohortFilters
      type: object
    PatchedAddPersonsToStaticCohortRequest:
      type: object
      properties:
        person_ids:
          type: array
          items:
            type: string
            format: uuid
          description: List of person UUIDs to add to the cohort
    RoleAtOrganizationEnum:
      enum:
      - engineering
      - data
      - product
      - founder
      - leadership
      - marketing
      - sales
      - other
      type: string
      description: '* `engineering` - Engineering

        * `data` - Data

        * `product` - Product Management

        * `founder` - Founder

        * `leadership` - Leadership

        * `marketing` - Marketing

        * `sales` - Sales / Success

        * `other` - Other'
    PersonFilter:
      additionalProperties: false
      properties:
        bytecode:
          default: null
          title: Bytecode
          items: {}
          type: array
          nullable: true
        bytecode_error:
          default: null
          title: Bytecode Error
          type: string
          nullable: true
        conditionHash:
          default: null
          title: Conditionhash
          type: string
          nullable: true
        type:
          title: Type
          type: string
          enum:
          - person
        key:
          title: Key
          type: string
        operator:
          default: null
          title: Operator
          type: string
          nullable: true
        value:
          default: null
          title: Value
          nullable: true
        negation:
          default: false
          title: Negation
          type: boolean
      required:
      - type
      - key
      title: PersonFilter
      type: object
    NullEnum:
      enum:
      - null
    PaginatedCohortList:
      type: object
      required:
      - count
      - results
      properties:
        count:
          type: integer
          example: 123
        next:
          type: string
          nullable: true
          format: uri
          example: http://api.example.org/accounts/?offset=400&limit=100
        previous:
          type: string
          nullable: true
          format: uri
          example: http://api.example.org/accounts/?offset=200&limit=100
        results:
          type: array
          items:
            $ref: '#/components/schemas/Cohort'
    UserBasic:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        uuid:
          type: string
          format: uuid
          readOnly: true
        distinct_id:
          type: string
          nullable: true
          maxLength: 200
        first_name:
          type: string
          maxLength: 150
        last_name:
          type: string
          maxLength: 150
        email:
          type: string
          format: email
          title: Email address
          maxLength: 254
        is_email_verified:
          type: boolean
          nullable: true
        hedgehog_config:
          type: object
          additionalProperties: true
          nullable: true
          readOnly: true
        role_at_organization:
          nullable: true
          oneOf:
          - $ref: '#/components/schemas/RoleAtOrganizationEnum'
          - $ref: '#/components/schemas/BlankEnum'
          - $ref: '#/components/schemas/NullEnum'
      required:
      - email
      - hedgehog_config
      - id
      - uuid
    CohortPersonResultTypeEnum:
      enum:
      - person
      type: string
      description: '* `person` - person'
    CohortPersonResult:
      type: object
      properties:
        id:
          type: string
        uuid:
          type: string
          format: uuid
        type:
          $ref: '#/components/schemas/CohortPersonResultTypeEnum'
        name:
          type: string
        distinct_ids:
          type: array
          items:
            type: string
        properties:
          type: object
          additionalProperties: true
        created_at:
          type: string
          format: date-time
          nullable: true
        last_seen_at:
          type: string
          format: date-time
          nullable: true
        is_identified:
          type: boolean
          nullable: true
        matched_recordings:
          type: array
          items:
            type: object
            additionalProperties: true
        value_at_data_point:
          type: number
          format: double
          nullable: true
      required:
      - created_at
      - distinct_ids
      - id
      - is_identified
      - last_seen_at
      - matched_recordings
      - name
      - properties
      - type
      - uuid
      - value_at_data_point
    CohortPersonsResponse:
      type: object
      properties:
        results:
          type: array
          items:
            $ref: '#/components/schemas/CohortPersonResult'
        next:
          type: string
          format: uri
          nullable: true
        previous:
          type: string
          format: uri
          nullable: true
      required:
      - next
      - previous
      - results
    PropertyGroupOperator:
      enum:
      - AND
      - OR
      type: string
    Cohort:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        name:
          type: string
          nullable: true
          maxLength: 400
        description:
          type: string
          maxLength: 1000
        groups: {}
        deleted:
          type: boolean
        filters:
          allOf:
          - $ref: '#/components/schemas/CohortFilters'
          nullable: true
        query:
          nullable: true
        version:
          type: integer
          readOnly: true
          nullable: true
        pending_version:
          type: integer
          readOnly: true
          nullable: true
        is_calculating:
          type: boolean
          readOnly: true
        created_by:
          allOf:
          - $ref: '#/components/schemas/UserBasic'
          readOnly: true
        created_at:
          type: string
          format: date-time
          readOnly: true
          nullable: true
        last_calculation:
          type: string
          format: date-time
          readOnly: true
          nullable: true
        last_backfill_person_properties_at:
          type: string
          format: date-time
          readOnly: true
          nullable: true
        errors_calculating:
          type: integer
          readOnly: true
        last_error_message:
          type: string
          nullable: true
          readOnly: true
        count:
          type: integer
          readOnly: true
          nullable: true
        is_static:
          type: boolean
        cohort_type:
          nullable: true
          description: 'Type of cohort based on filter complexity


            * `static` - static

            * `person_property` - person_property

            * `behavioral` - behavioral

            * `realtime` - realtime

            * `analytical` - analytical'
          oneOf:
          - $ref: '#/components/schemas/CohortTypeEnum'
          - $ref: '#/components/schemas/BlankEnum'
          - $ref: '#/components/schemas/NullEnum'
        experiment_set:
          type: array
          items:
            type: integer
          readOnly: true
        _create_in_folder:
          type: string
          writeOnly: true
          title: ' create in folder'
        _create_static_person_ids:
          type: array
          items:
            type: string
          writeOnly: true
          default: []
          title: ' create static person ids'
      required:
      - count
      - created_at
      - created_by
      - errors_calculating
      - experiment_set
      - id
      - is_calculating
      - last_backfill_person_properties_at
      - last_calculation
      - last_error_message
      - pending_version
      - version
    CohortFilterGroup:
      additionalProperties: false
      description: AND/OR group containing cohort filters. Named to avoid collision with analytics Group model.
      properties:
        type:
          allOf:
          - $ref: '#/components/schemas/PropertyGroupOperator'
          title: Type
        values:
          items:
            discriminator:
              mapping:
                AND: '#/components/schemas/CohortFilterGroup'
                OR: '#/components/schemas/CohortFilterGroup'
                behavioral: '#/components/schemas/BehavioralFilter'
                cohort: '#/components/schemas/CohortFilter'
                person: '#/components/schemas/PersonFilter'
              propertyName: type
            oneOf:
            - $ref: '#/components/schemas/BehavioralFilter'
            - $ref: '#/components/schemas/CohortFilter'
            - $ref: '#/components/schemas/PersonFilter'
            - $ref: '#/components/schemas/CohortFilterGroup'
          title: Values
          type: array
      required:
      - type
      - values
      title: CohortFilterGroup
      type: object
    EventPropFilterTypeEnum:
      enum:
      - event
      - element
      type: string
    BlankEnum:
      enum:
      - ''
    CohortFilter:
      additionalProperties: false
      properties:
        bytecode:
          default: null
          title: Bytecode
          items: {}
          type: array
          nullable: true
        bytecode_error:
          default: null
          title: Bytecode Error
          type: string
          nullable: true
        conditionHash:
          default: null
          title: Conditionhash
          type: string
          nullable: true
        type:
          title: Type
          type: string
          enum:
          - cohort
        key:
          title: Key
          type: string
          enum:
          - id
        value:
          title: Value
          type: integer
        negation:
          default: false
          title: Negation
          type: boolean
      required:
      - type
      - key
      - value
      title: CohortFilter
      type: object
    BehavioralFilter:
      additionalProperties: false
      properties:
        bytecode:
          default: null
          title: Bytecode
          items: {}
          type: array
          nullable: true
        bytecode_error:
          default: null
          title: Bytecode Error
          type: string
          nullable: true
        conditionHash:
          default: null
          title: Conditionhash
          type: string
          nullable: true
        type:
          title: Type
          type: string
          enum:
          - behavioral
        key:
          anyOf:
          - type: string
          - type: integer
          title: Key
        value:
          title: Value
          type: string
        event_type:
          title: Event Type
          type: string
        time_value:
          default: null
          title: Time Value
          type: integer
          nullable: true
        time_interval:
          default: null
          title: Time Interval
          type: string
          nullable: true
        negation:
          default: false
          title: Negation
          type: boolean
        operator:
          default: null
          title: Operator
          type: string
          nullable: true
        operator_value:
          default: null
          title: Operator Value
          type: integer
          nullable: true
        seq_time_interval:
          default: null
          title: Seq Time Interval
          type: string
          nullable: true
        seq_time_value:
          default: null
          title: Seq Time Value
          type: integer
          nullable: true
        seq_event:
          default: null
          title: Seq Event
          anyOf:
          - type: string
          - type: integer
          nullable: true
        seq_event_type:
          default: null
          title: Seq Event Type
          type: string
          nullable: true
        total_periods:
          default: null
          title: Total Periods
          type: integer
          nullable: true
        min_periods:
          default: null
          title: Min Periods
          type: integer
          nullable: true
        event_filters:
          default: null
          title: Event Filters
          items:
            anyOf:
            - $ref: '#/components/schemas/EventPropFilter'
            - $ref: '#/components/schemas/HogQLFilter'
          type: array
          nullable: true
        explicit_datetime:
          default: null
          title: Explicit Datetime
          type: string
          nullable: true
        explicit_datetime_to:
          default: null
          title: Explicit Datetime To
          type: string
          nullable: true
      required:
      - type
      - key
      - value
      - event_type
      title: BehavioralFilter
      type: object
    CohortTypeEnum:
      enum:
      - static
      - person_property
      - behavioral
      - realtime
      - analytical
      type: string
      description: '* `static` - static

        * `person_property` - person_property

        * `behavioral` - behavioral

        * `realtime` - realtime

        * `analytical` - analytical'
  parameters:
    ProjectIdPath:
      in: path
      name: project_id
      required: true
      schema:
        type: string
      description: Project ID of the project you're trying to access. To find the ID of the project, make a call to /api/projects/.
  securitySchemes:
    PersonalAPIKeyAuth:
      type: http
      scheme: bearer
x-tagGroups:
- name: All endpoints
  tags:
  - LLM Analytics
  - actions
  - activity_log
  - activity_logs
  - advanced_activity_logs
  - alerts
  - annotations
  - approval_policies
  - batch_exports
  - cdp
  - change_requests
  - code
  - code-invites
  - cohorts
  - comments
  - conversations
  - core
  - customer_analytics
  - customer_journeys
  - customer_profile_configs
  - dashboard_templates
  - dashboards
  - data_color_themes
  - data_modeling_jobs
  - data_warehouse
  - dataset_items
  - datasets
  - desktop_recordings
  - domains
  - early_access_feature
  - early_access_features
  - elements
  - endpoints
  - environments
  - error_tracking
  - evaluation_runs
  - evaluations
  - event_definitions
  - event_filter
  - event_schemas
  - events
  - experiment_holdouts
  - experiment_saved_metrics
  - experiments
  - exports
  - external_data_schemas
  - external_data_sources
  - feature_flags
  - file_system
  - file_system_shortcut
  - flag_value
  - groups
  - groups_types
  - health_issues
  - heatmap_screenshots
  - heatmaps
  - hog_flows
  - hog_function_templates
  - hog_functions
  - insight_variables
  - insights
  - integrations
  - invites
  - js-snippet
  - legal_documents
  - lineage
  - live_debugger_breakpoints
  - llm_analytics
  - llm_prompts
  - llm_skills
  - logs
  - managed_viewsets
  - max
  - max_tools
  - mcp_server_installations
  - mcp_servers
  - mcp_store
  - mcp_tools
  - members
  - notebooks
  - oauth_applications
  - object_media_previews
  - organizations
  - persisted_folder
  - persons
  - platform_features
  - plugin_configs
  - product_analytics
  - product_tours
  - project_secret_api_keys
  - projects
  - property_definitions
  - proxy_records
  - public_hog_function_templates
  - query
  - replay
  - reverse_proxy
  - role_external_references
  - roles
  - sandbox-environments
  - sandbox_environments
  - saved
  - schema_property_groups
  - sdk_doctor
  - session_group_summaries
  - session_recording_playlists
  - session_recordings
  - session_summaries
  - sessions
  - signals
  - subscriptions
  - surveys
  - taggers
  - task-automations
  - task-runs
  - task_automations
  - tasks
  - uploaded_media
  - user_home_settings
  - user_interviews
  - users
  - visual_review
  - warehouse_dag
  - warehouse_model_paths
  - warehouse_saved_queries
  - warehouse_saved_query_folders
  - warehouse_tables
  - warehouse_view_link
  - warehouse_view_links
  - web_analytics
  - web_experiments
  - web_vitals
  - welcome
  - workflows