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

# Create an audience segment

> Create a new audience segment.



## OpenAPI

````yaml /openapi.json post /v1/audience-segments
openapi: 3.1.0
info:
  title: Loops OpenAPI Spec
  description: This is the OpenAPI Spec for the [Loops API](https://loops.so/docs/api).
  version: 1.21.0
servers:
  - url: https://app.loops.so/api
security: []
tags:
  - name: API key
  - name: Audience segments
    description: View audience segments
  - name: Campaigns
    description: Create and manage email campaigns
  - name: Campaign groups
    description: Organize campaigns into groups
  - name: Components
    description: View email components
  - name: Configuration
    description: View configuration settings
  - name: Contacts
    description: Manage contacts in your audience
  - name: Contact properties
    description: Manage contact properties
  - name: Email messages
    description: Manage email message content for campaigns
  - name: Events
    description: Trigger workflows with events
  - name: Event patterns
    description: View workflow event patterns
  - name: Mailing lists
    description: View mailing lists
  - name: Themes
    description: View email themes
  - name: Transactional emails
    description: Create, manage, and send transactional emails
  - name: Transactional groups
    description: Organize transactional emails into groups
  - name: Uploads
    description: Upload image assets
  - name: Workflows
    description: View and mutate workflow graphs
  - name: Workflow nodes
    description: View and mutate workflow nodes
paths:
  /v1/audience-segments:
    post:
      tags:
        - Audience segments
      summary: Create an audience segment
      description: Create a new audience segment.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateAudienceSegmentRequest'
      responses:
        '200':
          description: Audience segment created.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AudienceSegmentResponse'
        '400':
          description: >-
            Invalid request body, a name already used by another segment, or a
            filter with too many conditions.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AudienceSegmentFailureResponse'
        '401':
          description: Invalid API key or content API not enabled for this team.
        '404':
          description: >-
            The filter references a campaign, workflow or workflow email that
            does not exist.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AudienceSegmentFailureResponse'
        '405':
          description: Wrong HTTP request method.
      security:
        - apiKey: []
components:
  schemas:
    CreateAudienceSegmentRequest:
      type: object
      properties:
        name:
          type: string
          maxLength: 255
          description: The name of the audience segment. Must be unique within the team.
          examples:
            - Active users
        description:
          type: string
          maxLength: 1000
          description: An optional description of the audience segment.
        filter:
          type: object
          description: A tree of audience conditions combined with `match`.
          properties:
            match:
              type: string
              enum:
                - all
                - any
            conditions:
              type: array
              minItems: 1
              items:
                $ref: '#/components/schemas/AudienceFilterCondition'
          required:
            - match
            - conditions
          additionalProperties: false
      required:
        - name
        - filter
      additionalProperties: false
    AudienceSegmentResponse:
      $ref: '#/components/schemas/AudienceSegment'
    AudienceSegmentFailureResponse:
      type: object
      properties:
        message:
          type: string
      required:
        - message
    AudienceFilterCondition:
      oneOf:
        - $ref: '#/components/schemas/PropertyCondition'
        - $ref: '#/components/schemas/OptInCondition'
        - $ref: '#/components/schemas/ActivityCondition'
      discriminator:
        propertyName: type
    AudienceSegment:
      type: object
      properties:
        id:
          type: string
          description: The ID of the audience segment.
        name:
          type: string
          description: The name of the audience segment.
        description:
          type:
            - string
            - 'null'
          description: An optional description of the audience segment.
        createdAt:
          type: string
          description: ISO 8601 timestamp for when the audience segment was created.
        updatedAt:
          type: string
          description: ISO 8601 timestamp for when the audience segment was last updated.
        filter:
          $ref: '#/components/schemas/AudienceFilter'
      required:
        - id
        - name
        - description
        - createdAt
        - updatedAt
        - filter
    PropertyCondition:
      type: object
      description: Matches contacts by a property value.
      properties:
        type:
          type: string
          enum:
            - property
        key:
          type: string
          description: The contact property name.
        operator:
          type: string
          enum:
            - any
            - contains
            - notContains
            - equals
            - notEquals
            - greaterThan
            - lessThan
            - isTrue
            - isFalse
            - empty
            - notEmpty
            - dateEmpty
            - dateNotEmpty
            - after
            - before
            - between
        value:
          description: >-
            The comparison value. Omitted for value-less operators (e.g.
            `isTrue`, `empty`). A `{ from, to }` object for `between`.
          oneOf:
            - type: string
            - type: number
            - type: object
              properties:
                from:
                  type: string
                  format: date-time
                to:
                  type: string
                  format: date-time
              required:
                - from
                - to
      required:
        - type
        - key
        - operator
    OptInCondition:
      type: object
      description: Matches contacts by mailing-list opt-in status.
      properties:
        type:
          type: string
          enum:
            - optIn
        status:
          type:
            - string
            - 'null'
          enum:
            - accepted
            - pending
            - rejected
            - null
      required:
        - type
        - status
    ActivityCondition:
      type: object
      description: Matches contacts by their activity on a campaign or workflow.
      properties:
        type:
          type: string
          enum:
            - activity
        action:
          type: string
          enum:
            - sent
            - opened
            - clicked
        negate:
          type: boolean
        target:
          type: string
          enum:
            - campaign
            - workflow
            - workflowEmail
        id:
          type: string
          description: The ID of the campaign, workflow, or workflow email.
      required:
        - type
        - action
        - negate
        - target
        - id
    AudienceFilter:
      type:
        - object
        - 'null'
      description: A tree of audience conditions combined with `match`.
      properties:
        match:
          type: string
          enum:
            - all
            - any
        conditions:
          type: array
          minItems: 1
          items:
            $ref: '#/components/schemas/AudienceFilterCondition'
      required:
        - match
        - conditions
      additionalProperties: false
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer

````

## Related topics

- [Filters and Segments](/docs/contacts/filters-segments.md)
- [Get an audience segment](/docs/api-reference/get-audience-segment.md)
- [List audience segments](/docs/api-reference/list-audience-segments.md)
- [API Introduction](/docs/api-reference/intro.md)
- [Campaigns API examples](/docs/api-reference/examples/campaigns.md)
