> ## Documentation Index
> Fetch the complete documentation index at: https://docs.greenflash.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Get User Segments

> Find out which segments a user belongs to. Returns segment membership data including segment ID, name, type, and preset identifier.

This endpoint returns membership data (not analytics), so it is available on **all plans** including Free.



## OpenAPI

````yaml https://www.greenflash.ai/api/openapi get /users/{userId}/segments
openapi: 3.1.0
info:
  title: Greenflash API Reference
  version: 1.0.0
  description: >-
    Greenflash endpoints for capturing interactions, managing prompts, and
    identifying users.
servers:
  - url: https://www.greenflash.ai/api/v1
    description: Greenflash API v1
security: []
tags:
  - name: Interactions
    description: Capture interactions between users and AI
  - name: Business Events
    description: Capture business events
  - name: Analytics
    description: Understand chat and agentic interactions analyses
  - name: Inbox
    description: Review flagged conversations
  - name: Segments
    description: Manage user segments
  - name: Prompts
    description: Manage prompts
  - name: Chat
    description: Stream chat and agentic conversations
  - name: Models
    description: Manage AI models
  - name: Products
    description: Manage products
  - name: Users
    description: Manage users
  - name: Organizations
    description: Manage organizations
paths:
  /users/{userId}/segments:
    get:
      tags:
        - Users
        - Segments
      summary: Get User Segments
      description: >-
        Find out which segments a user belongs to. Returns segment membership
        data including segment ID, name, type, and preset identifier.


        This endpoint returns membership data (not analytics), so it is
        available on **all plans** including Free.
      parameters:
        - schema:
            type: string
            format: uuid
            description: The user ID to get segment memberships for
          required: true
          description: The user ID to get segment memberships for
          name: userId
          in: path
      responses:
        '200':
          description: User segments retrieved successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GetUserSegmentsResponse'
              example:
                - id: 123e4567-e89b-12d3-a456-426614174000
                  name: Power Users
                  type: system
                  presetId: power-users
                - id: 123e4567-e89b-12d3-a456-426614174001
                  name: Enterprise Customers
                  type: custom
                  presetId: null
        '404':
          description: User not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    description: Whether the API call was successful (false for errors).
                  error:
                    type: string
                    description: Error message describing what went wrong.
                description: Error response for get user segments operations.
              example:
                success: false
                error: User not found
      security:
        - bearerAuth: []
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import Greenflash from 'greenflash';

            const client = new Greenflash({
              apiKey: process.env['GREENFLASH_API_KEY'], // This is the default and can be omitted
            });

            const getUserSegmentsResponse = await client.users.getUserSegments(
              '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
            );

            console.log(getUserSegmentsResponse);
        - lang: Python
          source: |-
            import os
            from greenflash import Greenflash

            client = Greenflash(
                api_key=os.environ.get("GREENFLASH_API_KEY"),  # This is the default and can be omitted
            )
            get_user_segments_response = client.users.get_user_segments(
                "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
            )
            print(get_user_segments_response)
components:
  schemas:
    GetUserSegmentsResponse:
      type: array
      items:
        $ref: '#/components/schemas/UserSegmentMembership'
      description: Array of segments the user belongs to.
    UserSegmentMembership:
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: The segment ID.
        name:
          type: string
          description: The segment name.
        type:
          type: string
          description: The segment type (system or custom).
        presetId:
          type:
            - string
            - 'null'
          description: >-
            The preset identifier for system segments, or null for custom
            segments.
      required:
        - id
        - name
        - type
        - presetId
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````