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

# Create segment

> Create a new contact segment. For data-driven segments, conditions must be provided.



## OpenAPI

````yaml /openapi.json post /v1/segments
openapi: 3.0.3
info:
  title: Emailr API
  version: 1.0.0
servers:
  - url: https://api.emailr.dev
    description: Production
security: []
tags:
  - name: emails
    description: Email sending and management
  - name: contacts
    description: Contact management
  - name: templates
    description: Email template management
  - name: domains
    description: Domain verification and management
  - name: webhooks
    description: Webhook configuration
  - name: broadcasts
    description: Broadcast campaign management
  - name: segments
    description: Contact segmentation
paths:
  /v1/segments:
    post:
      tags:
        - segments
      summary: Create segment
      description: >-
        Create a new contact segment. For data-driven segments, conditions must
        be provided.
      operationId: createSegment
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateSegmentRequest'
      responses:
        '200':
          description: Segment created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Segment'
        '400':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - bearerAuth: []
components:
  schemas:
    CreateSegmentRequest:
      type: object
      properties:
        name:
          type: string
          minLength: 1
          example: Active Users
        description:
          type: string
          example: Users who opened an email in the last 30 days
        type:
          allOf:
            - $ref: '#/components/schemas/SegmentType'
            - default: manual
              description: >-
                Segment type: 'manual' for static segments, 'data_driven' for
                dynamic filter-based segments
        conditions:
          $ref: '#/components/schemas/FilterConditions'
        tags:
          type: array
          items:
            type: string
          description: Tags for categorization. Lowercase, max 50 chars each, max 20 tags.
          example:
            - newsletter
            - vip
      required:
        - name
    Segment:
      type: object
      properties:
        id:
          type: string
          format: uuid
          example: 123e4567-e89b-12d3-a456-426614174000
        organization_id:
          type: string
          format: uuid
        name:
          type: string
        description:
          type: string
          nullable: true
        type:
          $ref: '#/components/schemas/SegmentType'
        conditions:
          type: object
          additionalProperties: {}
        tags:
          type: array
          items:
            type: string
          description: Tags for categorization.
          example:
            - newsletter
            - vip
        created_by:
          type: string
          nullable: true
          format: uuid
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
      required:
        - id
        - organization_id
        - name
        - description
        - type
        - conditions
        - tags
        - created_by
        - created_at
        - updated_at
    Error:
      type: object
      properties:
        error:
          type: string
          example: An error occurred
        code:
          type: string
          example: VALIDATION_ERROR
        details: {}
      required:
        - error
    SegmentType:
      type: string
      enum:
        - manual
        - data_driven
      description: 'Segment type: ''manual'' or ''data_driven'''
      example: data_driven
    FilterConditions:
      type: object
      properties:
        logic:
          type: string
          enum:
            - and
            - or
          example: and
        rules:
          type: array
          items:
            $ref: '#/components/schemas/FilterRule'
          example:
            - field: properties.plan_type
              operator: equals
              value: premium
      required:
        - logic
        - rules
      description: >-
        Filter conditions for data-driven segments. Required when type is
        'data_driven'.
      example:
        logic: and
        rules:
          - field: properties.plan_type
            operator: equals
            value: premium
    FilterRule:
      type: object
      properties:
        field:
          type: string
          example: properties.plan_type
        operator:
          type: string
          enum:
            - exists
            - not_exists
            - equals
            - not_equals
            - greater_than
            - less_than
            - greater_than_or_equal
            - less_than_or_equal
            - contains
            - not_contains
            - starts_with
            - ends_with
          example: equals
        value:
          example: premium
      required:
        - field
        - operator
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: API key authentication. Use your API key as the bearer token.

````