> ## Documentation Index
> Fetch the complete documentation index at: https://statsig-preview.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Segment



## OpenAPI

````yaml api-reference/statsig_openapi.json post /console/v1/segments
openapi: 3.0.0
info:
  title: Console API
  description: >-
    The "Console API" is the CRUD API for performing the actions offered on
    console.statsig.com without needing to go through the web UI.

    If you have any feature requests, drop on in to our [slack
    channel](https://www.statsig.com/slack) and let us know.

    <br /><br />

    <b>Authorization</b>

    <br />

    All requests must include the **STATSIG-API-KEY** field in the header. The
    value should be a **Console API Key** which can be created in the Project
    Settings on
    [console.statsig.com/api_keys](https://console.statsig.com/api_keys)

    <br /><br />

    <b>Rate Limiting</b>

    <br />

    Requests to the Console API are limited to <code>~ 100reqs / 10secs and ~
    900reqs / 15 mins</code>.

    <br /><br />

    <b>Keyboard Search</b>

    <br />

    Use <code>Ctrl/Cmd + K</code> to search for specific endpoints.
  version: 20240601.0.0
  contact: {}
servers:
  - url: https://statsigapi.net
security: []
tags: []
paths:
  /console/v1/segments:
    post:
      tags:
        - Segments
      summary: Create Segment
      parameters:
        - name: x-respect-review-settings
          in: header
          description: Optional header to respect review settings for mutation endpoints.
          required: false
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SegmentCreateContractDto'
      responses:
        '201':
          description: Create Segment Success
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/SingleDataResponse'
                  - properties:
                      data:
                        $ref: '#/components/schemas/SegmentDto'
              examples:
                id_list:
                  value:
                    message: Segment created successfully.
                    data:
                      id: an_id_list
                      isEnabled: true
                      description: helpful summary of what this segment is
                      lastModifierName: CONSOLE API
                      lastModifierID: ahKwUoaNauHu9AmJPc2
                      type: id_list
                      count: 0
                      tags:
                        - a tag
                  summary: ID list segment
                rule_based:
                  value:
                    message: Segment created successfully.
                    data:
                      id: a_rule_based_segment
                      isEnabled: true
                      description: helpful summary of what this segment is
                      lastModifierName: CONSOLE API
                      lastModifierID: ahKwUoaNauHu9AmJPc2
                      type: rule_based
                      count: 0
                      rules:
                        name: All Conditions
                        passPercentage: 10
                        conditions:
                          - type: public
                            operator: string
                            targetValue: 0
                            field: string
                            customID: string
                        returnValue:
                          key: true
                      tags:
                        - a tag
                  summary: Rule-based segment
        '401':
          description: >-
            This endpoint only accepts an active CONSOLE key, but an invalid key
            was sent. Key: console-xxxXXXxxxXXXxxx
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: integer
                    enum:
                      - 401
                  message:
                    type: string
                required:
                  - status
                  - message
              examples:
                Invalid Endpoint:
                  value:
                    status: 401
                    message: >-
                      This endpoint only accepts an active CONSOLE key, but an
                      invalid key was sent. Key: console-xxxXXXxxxXXXxxx
      security:
        - STATSIG-API-KEY: []
components:
  schemas:
    SegmentCreateContractDto:
      type: object
      properties:
        name:
          type: string
          maxLength: 100
          minLength: 3
          pattern: ^[a-zA-Z0-9_\- ]*$
          description: name of the segment
        id:
          type: string
          maxLength: 100
          minLength: 3
          pattern: ^[a-zA-Z0-9_-]*$
          description: optional id of the segment (defaults to name)
        description:
          type: string
          maxLength: 1000
          description: description of the segment
        type:
          type: string
          enum:
            - id_list
            - rule_based
            - analysis_list
          description: type of the segment
        idType:
          default: userID
          type: string
          description: type of id
        tags:
          type: array
          items:
            type: string
          description: optional tags for categorization
        creatorID:
          type: string
          nullable: true
          description: the Statsig ID of the creator of this experiment
        creatorEmail:
          type: string
          nullable: true
          description: the email of the creator of this experiment
        team:
          type: string
          nullable: true
          description: optional name identifier for the responsible team (enterprise only)
        teamID:
          type: string
          nullable: true
          description: optional identifier for the responsible team (enterprise only)
        rules:
          type: array
          items:
            type: object
            properties:
              name:
                type: string
                description: The name of this rule.
              passPercentage:
                type: number
                minimum: 0
                maximum: 100
                multipleOf: 0.01
                description: >-
                  Of the users that meet the conditions of this rule, what
                  percent should return true.
              conditions:
                type: array
                items:
                  type: object
                  properties:
                    targetValue:
                      oneOf:
                        - type: array
                          items:
                            type: string
                        - type: array
                          items:
                            type: number
                        - type: string
                        - type: number
                      nullable: true
                    operator:
                      type: string
                    field:
                      type: string
                      nullable: true
                    customID:
                      type: string
                      nullable: true
                    type:
                      type: string
                      enum:
                        - app_version
                        - browser_name
                        - browser_version
                        - country
                        - custom_field
                        - email
                        - environment_tier
                        - fails_segment
                        - ip_address
                        - os_name
                        - os_version
                        - passes_segment
                        - unit_id
                        - user_id
                  required:
                    - type
              environments:
                type: array
                items:
                  type: string
                nullable: true
                description: The environments this rule is enabled for.
              id:
                type: string
                description: The Statsig ID of this rule.
              baseID:
                type: string
                description: >-
                  The base ID of this rule, i.e. without any added metadata.
                  Will remain the exact same throughout
              returnValue:
                type: object
                additionalProperties: {}
                description: The return value of the rule.
            required:
              - name
              - passPercentage
              - conditions
          description: Rule Object
      required:
        - name
        - type
    SingleDataResponse:
      type: object
      properties:
        message:
          type: string
          description: A simple string explaining the result of the operation.
        data:
          type: object
          description: A single result.
      required:
        - message
        - data
    SegmentDto:
      type: object
      properties:
        isEnabled:
          type: boolean
          description: Is the segment enabled.
        type:
          type: string
          enum:
            - id_list
            - rule_based
            - analysis_list
        count:
          type: number
          description: 'For id_list segments: the length of the ID list'
        rules:
          type: array
          items:
            type: object
            properties:
              name:
                type: string
                description: The name of this rule.
              passPercentage:
                type: number
                minimum: 0
                maximum: 100
                multipleOf: 0.01
                description: >-
                  Of the users that meet the conditions of this rule, what
                  percent should return true.
              conditions:
                type: array
                items:
                  type: object
                  properties:
                    targetValue:
                      oneOf:
                        - type: array
                          items:
                            type: string
                        - type: array
                          items:
                            type: number
                        - type: string
                        - type: number
                      nullable: true
                    operator:
                      type: string
                    field:
                      type: string
                      nullable: true
                    customID:
                      type: string
                      nullable: true
                    type:
                      type: string
                      enum:
                        - app_version
                        - browser_name
                        - browser_version
                        - country
                        - custom_field
                        - email
                        - environment_tier
                        - fails_gate
                        - fails_segment
                        - ip_address
                        - locale
                        - os_name
                        - os_version
                        - passes_gate
                        - passes_segment
                        - public
                        - time
                        - unit_id
                        - user_id
                        - url
                        - javascript
                        - device_model
                        - target_app
                  required:
                    - type
                description: An array of Condition objects.
              environments:
                type: array
                items:
                  type: string
                nullable: true
                description: The environments this rule is enabled for.
              id:
                type: string
                description: The Statsig ID of this rule.
              baseID:
                type: string
                description: >-
                  The base ID of this rule, i.e. without any added metadata.
                  Will remain the exact same throughout
              returnValue:
                type: object
                additionalProperties: {}
                description: The return value of the rule.
            required:
              - name
              - passPercentage
              - conditions
          description: Rule Object
        tags:
          type: array
          items:
            type: string
          description: Optional tags for categorization.
        id:
          type: string
          description: ID
        name:
          type: string
          description: Optional name for the configuration.
        idType:
          type: string
          description: Type of ID
        description:
          type: string
          description: Detailed description of the configuration’s purpose.
        lastModifierID:
          type: string
          nullable: true
          description: ID of the last modifier.
        lastModifiedTime:
          type: number
          nullable: true
          description: Time of the last modification.
        lastModifierEmail:
          type: string
          nullable: true
          description: Email of the last modifier.
        lastModifierName:
          type: string
          nullable: true
          description: Name of the last modifier.
        creatorID:
          type: string
          nullable: true
          description: ID of the user who created the entity.
        createdTime:
          type: number
          description: Timestamp when the entity was created.
        creatorName:
          type: string
          nullable: true
          description: Name of the creator.
        creatorEmail:
          type: string
          nullable: true
          description: Email of the creator.
        targetApps:
          type: array
          items:
            type: string
          description: List of target applications associated with this configuration.
        holdoutIDs:
          type: array
          items:
            type: string
          description: Holdouts applied to this configuration.
        team:
          type: string
          nullable: true
          description: Optional name for the responsible team.
        teamID:
          type: string
          nullable: true
          description: Optional ID of the responsible team.
        version:
          type: number
          description: Version number
      required:
        - isEnabled
        - type
        - id
        - idType
        - description
        - lastModifierID
        - lastModifiedTime
        - lastModifierEmail
        - lastModifierName
        - creatorID
        - createdTime
        - creatorName
        - creatorEmail
  securitySchemes:
    STATSIG-API-KEY:
      type: apiKey
      name: STATSIG-API-KEY
      in: header

````