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

# Create Segment

> Create a customer segment.

> 🚧 Limit on static segments
>
> There is a cap on the number of customers that you can assign to a static segment: **20,000**. If you would like to create a bigger segment, then you can use the unlimited `auto-update` or `passive` segment instead and use some customer metadata to build this segment.

> 🚧 Limit on Active and Passive segments
>
> You can create a maximum of 100 passive and active segments.



## OpenAPI

````yaml /openapi/segments.json post /v1/segments
openapi: 3.0.1
info:
  title: Voucherify API - Segments
  version: v2018-08-01
  description: >-
    Voucherify promotion engine REST API. Please see
    https://docs.voucherify.io/docs for more details.
  contact:
    name: Voucherify Team
    url: https://www.voucherify.io/contact-support
    email: support@voucherify.io
  termsOfService: https://www.voucherify.io/legal/subscription-agreement
  license:
    name: MIT
    url: https://github.com/voucherifyio/voucherify-js-sdk/blob/main/LICENSE
servers:
  - url: https://{cluster}.voucherify.io
    description: Base URL
    variables:
      cluster:
        default: api
        enum:
          - api
          - us1.api
          - as1.api
          - download
          - us1.download
          - as1.download
security: []
paths:
  /v1/segments:
    post:
      tags:
        - Segments
      summary: Create Segment
      description: >-
        Create a customer segment.


        > 🚧 Limit on static segments

        >

        > There is a cap on the number of customers that you can assign to a
        static segment: **20,000**. If you would like to create a bigger
        segment, then you can use the unlimited `auto-update` or `passive`
        segment instead and use some customer metadata to build this segment.


        > 🚧 Limit on Active and Passive segments

        >

        > You can create a maximum of 100 passive and active segments.
      operationId: create-segment
      parameters: []
      requestBody:
        description: Specify the boundary conditions for the customer segment.
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SegmentsCreateRequestBody'
            examples:
              Static Segment:
                value:
                  name: Customers in a new Segment
                  type: static
                  customers:
                    - cust_iajsExT2QB4sGWzABY85WRqV
                    - cust_sehkNIi8Uq2qQuRqSr7xn4Zi
              Dynamic - customers created after a specific date:
                value:
                  name: Customers in a new Dynamic Segment
                  type: auto-update
                  filter:
                    junction: and
                    created_at:
                      conditions:
                        $after:
                          - '2021-12-01T00:00:00.000Z'
              Dynamic - customers with birthday next month:
                value:
                  name: Customers in a new Dynamic Segment
                  type: auto-update
                  filter:
                    junction: and
                    birthdate:
                      conditions:
                        $next_month:
                          - true
                    address.country:
                      conditions:
                        $is: Poland
                    metadata.club_level:
                      conditions:
                        $in:
                          - Gold
                          - Silver
        required: true
      responses:
        '200':
          description: Returns a customer segment object.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SegmentsCreateResponseBody'
              examples:
                Static:
                  value:
                    id: seg_vC8iOSCqUG02EsPzsHynLv8i
                    name: Customers in a new Segment
                    created_at: '2022-09-13T08:57:15.801Z'
                    type: static
                    filter: null
                    initial_sync_status: DONE
                    object: segment
                Dynamic:
                  value:
                    id: seg_nZULMFHhVWIFm9vQ0dytg83Q
                    name: Customers in a new Dynamic Segment
                    created_at: '2022-09-13T09:03:32.764Z'
                    type: auto-update
                    filter:
                      junction: and
                      created_at:
                        conditions:
                          $after:
                            - '2021-12-01T00:00:00.000Z'
                    initial_sync_status: IN_PROGRESS
                    object: segment
      security:
        - X-App-Id: []
          X-App-Token: []
        - X-Voucherify-OAuth:
            - api
            - segments
components:
  schemas:
    SegmentsCreateRequestBody:
      title: Create Customer Segment Request Body
      description: Request body schema for **POST** `v1/segments`.
      oneOf:
        - $ref: '#/components/schemas/SegmentsCreateRequestBodyStatic'
        - $ref: '#/components/schemas/SegmentsCreateRequestBodyDynamic'
    SegmentsCreateResponseBody:
      title: Create Customer Segment Response Body
      description: Response body schema for **POST** `v1/segments`.
      allOf:
        - $ref: '#/components/schemas/Segment'
    SegmentsCreateRequestBodyStatic:
      title: Static Customer Segment
      type: object
      description: >-
        Request body schema for creating a static customer segment in **POST**
        `v1/segments`.
      properties:
        name:
          type: string
          description: Segment name.
        type:
          type: string
          description: >-
            Defines that the segment is static, meaning it includes only the
            manually selected customers.
          default: static
          enum:
            - static
        customers:
          type: array
          description: Array of customer IDs.
          items:
            type: string
    SegmentsCreateRequestBodyDynamic:
      title: Active or Passive Customer Segment
      type: object
      description: >-
        Request body schema for creating an active or passive customer segment
        in **POST** `v1/segments`.
      properties:
        name:
          type: string
          description: Segment name.
        type:
          type: string
          description: >-
            Defines whether the segment is:

            - Active (`auto-update`): customers enter and leave the segment
            based on the defined filters and the `customer.segment.entered` and
            `customer.segment.left` events are triggered,

            - Passive (`passive`): customers enter and leave the segment based
            on the defined filters, but the `customer.segment.entered` and
            `customer.segment.left` events are not triggered.
          enum:
            - auto-update
            - passive
        filter:
          type: object
          description: >-
            Defines a set of criteria for an `auto-update` or `passive` segment
            type.
    Segment:
      title: Segment
      type: object
      properties:
        id:
          type: string
          example: seg_1wc52c5z6r1kQ81brO8j9Hk2
          description: Unique segment ID.
        name:
          type: string
          description: Segment name.
        created_at:
          type: string
          example: '2022-05-12T13:01:56.896Z'
          description: >-
            Timestamp representing the date and time when the segment was
            created. The value is shown in the ISO 8601 format.
          format: date-time
        updated_at:
          type: string
          format: date-time
          example: '2022-10-03T12:24:58.008Z'
          description: >-
            Timestamp in ISO 8601 format indicating when the segment was
            updated.
        type:
          type: string
          enum:
            - auto-update
            - passive
            - static
          description: >-
            Defines whether the segment is:

            - Active (`auto-update`): customers enter and leave the segment
            based on the defined filters and the `customer.segment.entered` and
            `customer.segment.left` events are triggered,

            - Passive (`passive`): customers enter and leave the segment based
            on the defined filters, but the `customer.segment.entered` and
            `customer.segment.left` events are not triggered,

            - Static (`static`): manually selected customers.
        filter:
          type: object
          nullable: true
          description: >-
            Defines a set of criteria for an `auto-update` or `passive` segment
            type.
        object:
          type: string
          default: segment
          description: >-
            The type of the object represented by JSON. This object stores
            information about the customer segment.
          enum:
            - segment
      description: This is an object representing a customer segment.
  securitySchemes:
    X-App-Id:
      type: apiKey
      name: X-App-Id
      in: header
    X-App-Token:
      type: apiKey
      name: X-App-Token
      in: header
    X-Voucherify-OAuth:
      type: oauth2
      flows:
        implicit:
          authorizationUrl: https://api.voucherify.io/v1/oauth/token
          scopes:
            api: Gives access to whole server-side API.
            vouchers: >-
              Gives access to all endpoints and methods starting with
              `v1/vouchers`.
            client_api: Gives access to whole client-side API.
            client_vouchers: >-
              Gives access to all endpoints and methods starting with
              `/client/v1/vouchers`.
            promotions: >-
              Gives access to all endpoints and methods starting with
              `/v1/promotions`.
            client_promotions: >-
              Gives access to all endpoints and methods starting with
              `/client/v1/promotions`
            campaigns: >-
              Gives access to all endpoints and methods starting with
              `v1/campaigns`.
            client_publish: >-
              Gives access to all endpoints and methods starting with
              `/client/v1/publish`.
            exports: >-
              Gives access to all endpoints and methods starting with
              `/v1/exports`.
            publications: >-
              Gives access to all endpoints and methods starting with
              `/v1/publications`.
            client_validate: >-
              Gives access to all endpoints and methods starting with
              `/client/v1/validate`.
            validations: >-
              Gives access to all endpoints and methods starting with
              `/v1/validations`.
            client_validations: >-
              Gives access to all endpoints and methods starting with
              `/client/v1/validations`.
            qualifications: >-
              Gives access to all endpoints and methods starting with
              `/v1/qualifications`.
            client_qualifications: >-
              Gives access to all endpoints and methods starting with
              `/client/v1/qualifications`.
            client_redeem: >-
              Gives access to all endpoints and methods starting with
              `/client/v1/redeem
            redemptions: >-
              Gives access to all endpoints and methods starting with
              `/v1/redemptions`.
            client_redemptions: >-
              Gives access to all endpoints and methods starting with
              `/client/v1/redemptions`
            customers: >-
              Gives access to all endpoints and methods starting with
              `/v1/customers`.
            client_customers: >-
              Gives access to all endpoints and methods starting with
              `/client/v1/customers`.
            orders: >-
              Gives access to all endpoints and methods starting with
              `/v1/orders`.
            products: >-
              Gives access to all endpoints and methods starting with
              `/v1/products`.
            skus: >-
              Gives access to all endpoints and methods starting with
              `/v1/SKUs`.
            validation-rules: >-
              Gives access to all endpoints and methods starting with
              `/v1/validation-rules`.
            validation-rules-assignments: >-
              Gives access to all endpoints and methods starting with
              `/v1/validation-rules-assignments
            segments: >-
              Gives access to all endpoints and methods starting with
              `/v1/segments`.
            events: >-
              Gives access to all endpoints and methods starting with
              `/v1/events`.
            client_events: >-
              Gives access to all endpoints and methods starting with
              `client/v1/events`.
            rewards: >-
              Gives access to all endpoints and methods starting with
              `/v1/rewards`.
            assets: >-
              Gives access to all endpoints and methods starting with
              `/v1/assets`.
            task-results: >-
              Gives access to all endpoints and methods starting with
              `/v1/task-results`.
            loyalties: >-
              Gives access to all endpoints and methods starting with
              `/v1/loyalties`.
            client_consents: >-
              Gives access to all endpoints and methods starting with
              `client/v1/consents`.
            consents: >-
              Gives access to all endpoints and methods starting with
              `/v1/consents`.
            async-actions: >-
              Gives access to all endpoints and methods starting with
              `/v1/async-actions`.
            product-collections: >-
              Gives access to all endpoints and methods starting with
              `/v1/product-collections`.
            categories: >-
              Gives access to all endpoints and methods starting with
              `/v1/categories`.
            metadata-schemas: >-
              Gives access to all endpoints and methods starting with
              `/v1/metadata-schemas`.
            locations: >-
              Gives access to all endpoints and methods starting with
              `/v1/locations`.
            referrals: >-
              Gives access to all endpoints and methods starting with
              `/v1/referrals`.
            trash-bin: >-
              Gives access to all endpoints and methods starting with
              `/v1/trash-bin`.
            templates: >-
              Gives access to all endpoints and methods starting with
              `/v1/templates`.

````