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

# Create a new ruleset

Creates a new automation ruleset with specified trigger conditions, filters, and actions. The ruleset can be created in either LIVE or PAUSED status. When a priority is specified, all existing rules at or below that priority are shifted down. For time-based triggers (time.unanswered\_by\_client, time.unanswered\_by\_team), matching conversations are automatically excluded from future processing. Validates that the trigger exists, filters are valid for the trigger type, and actions are properly configured.


## OpenAPI

````yaml https://api.getfernand.com/openapi.json post /organization/rules
openapi: 3.0.3
info:
  title: Fernand API Documentation
  version: '3.0'
  description: This is the documentation for the [Fernand](https://getfernand.com) API.
  termsOfService: https://getfernand.com/terms
  contact:
    name: Fernand Support
    url: https://getfernand.com
    email: support@getfernand.com
  x-logo:
    url: https://app.getfernand.com/images/favicon/icon_128.png
servers:
  - url: https://api.getfernand.com
    description: ''
    x-last-modified: 1764750693905
security:
  - apiKeyHeader: []
externalDocs:
  description: You can access our documentation online by visiting https://api.fernand.help
  url: https://api.fernand.help
paths:
  /organization/rules:
    post:
      tags:
        - Rulesets
      summary: Create a new ruleset
      description: >-
        Creates a new automation ruleset with specified trigger conditions,
        filters, and actions. The ruleset can be created in either LIVE or
        PAUSED status. When a priority is specified, all existing rules at or
        below that priority are shifted down. For time-based triggers
        (time.unanswered_by_client, time.unanswered_by_team), matching
        conversations are automatically excluded from future processing.
        Validates that the trigger exists, filters are valid for the trigger
        type, and actions are properly configured.
      operationId: createRuleset
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  maxLength: 250
                  description: Name of the ruleset (required).
                  example: Auto-assign incoming messages
                trigger:
                  type: string
                  maxLength: 50
                  description: >
                    Event that triggers this rule (required). Must be one of:

                    messages.new_conversation, messages.incoming,
                    messages.response, messages.disable_ai,
                    messages.delivery_failure, messages.spam, messages.note,
                    status.closed, status.opened, status.snoozed,
                    status.unsnoozed, teammates.assigned, teammate.mentioned,
                    time.unanswered_by_client, time.unanswered_by_team,
                    tickets.ticket_done
                  example: messages.incoming
                trigger_data:
                  type: string
                  description: >
                    Additional data for the trigger (optional, required for
                    certain triggers):

                    - For "teammates.assigned" or "teammate.mentioned":
                    "no_one", "anyone", or an Agent ID

                    - For "time.*" triggers: duration and period in format
                    "{duration} {period}" (e.g., "2 hours", "3 days")
                  example: anyone
                filters:
                  type: array
                  description: >-
                    Array of filter conditions (optional). Filters determine
                    when the rule should execute based on entity properties.
                  items:
                    type: object
                  example:
                    - field: conversation.status
                      operator: equals
                      value: OPENED
                actions:
                  type: array
                  description: >-
                    Array of actions to execute when rule matches (required).
                    Must contain at least one action.
                  items:
                    type: object
                    properties:
                      name:
                        type: string
                        description: Name of the action to execute
                      data:
                        type: object
                        description: Optional data for the action
                  example:
                    - name: conversation.assign
                      data:
                        agent_id: 123
                status:
                  type: string
                  enum:
                    - PAUSED
                    - LIVE
                  description: Initial status of the ruleset (optional, defaults to LIVE).
                  example: LIVE
                stop:
                  type: boolean
                  description: >-
                    If true, stops processing subsequent rules when this rule
                    matches (optional, defaults to false).
                  example: false
                priority:
                  type: integer
                  description: >-
                    Priority order for rule execution (optional). If not
                    specified, rule is added at the end. Lower numbers execute
                    first.
                  example: 0
              required:
                - name
                - trigger
                - actions
      responses:
        '200':
          description: Ruleset created successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Ruleset'
        '400':
          description: >-
            Invalid input, validation failed, or trigger/filter/action
            configuration error.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: Error message describing what went wrong
components:
  schemas:
    Ruleset:
      type: object
      properties:
        id:
          type: integer
          format: int32
          description: Unique identifier for the ruleset
        name:
          type: string
          maxLength: 250
          description: Name of the ruleset
          example: Auto-close spam conversations
        description:
          type: string
          maxLength: 500
          nullable: true
          description: Optional description of what the ruleset does
          example: Automatically closes conversations marked as spam
        status:
          type: string
          enum:
            - PAUSED
            - LIVE
          description: Current status of the ruleset
          example: LIVE
        priority:
          type: integer
          format: int16
          description: Priority order for rule execution (lower numbers execute first)
          example: 0
        stop:
          type: boolean
          description: If true, stops processing subsequent rules when this rule matches
          example: false
        trigger_name:
          type: string
          maxLength: 50
          description: |
            Event that triggers this rule. Accepted triggers:
            - messages.new_conversation
            - messages.incoming
            - messages.response
            - messages.delivery_failure
            - messages.spam
            - messages.note
            - messages.disable_ai
            - status.closed
            - status.opened
            - status.snoozed
            - status.unsnoozed
            - teammates.assigned
            - teammate.mentioned
            - time.unanswered_by_client
            - time.unanswered_by_team
            - tickets.ticket_done
          example: messages.incoming
        trigger_data:
          type: string
          maxLength: 250
          nullable: true
          description: >
            Additional data for the trigger (required for certain triggers):

            - For "teammates.assigned" or "teammate.mentioned": "no_one",
            "anyone", or an Agent ID

            - For "time.*" triggers: duration and period in format "{duration}
            {period}" (e.g., "2 hours", "3 days")
          example: 2 hours
        filters:
          type: array
          nullable: true
          description: |
            Array of filter conditions that must be met for the rule to execute.
            Each filter contains conditions to match against the entity.
          items:
            type: object
          example:
            - field: conversation.status
              operator: equals
              value: OPENED
        actions:
          type: array
          description: |
            Array of actions to execute when the rule matches.
            Each action has a name and optional data.
          items:
            type: object
            properties:
              name:
                type: string
                description: Name of the action to execute
              data:
                type: object
                description: Optional data for the action
          example:
            - name: conversation.close
              data: {}
        created:
          type: string
          format: date-time
          description: Timestamp when the ruleset was created (UTC)
          example: '2025-01-21T10:30:00Z'
        last_applied_at:
          type: string
          format: date-time
          nullable: true
          description: Timestamp when the rule was last applied (UTC)
          example: '2025-01-21T15:45:30Z'
        applied_count:
          type: integer
          format: int32
          description: Number of times this rule has been successfully applied
          example: 42
      required:
        - id
        - name
        - status
        - priority
        - stop
        - trigger_name
        - created
        - applied_count
      x-computed-hash: 825d70624279e89eaa8af56e2d0dde159a1fa02f03c1369b8e6285e19c4c5cd8
      x-last-modified: 1776152542
  securitySchemes:
    apiKeyHeader:
      type: apiKey
      description: >-
        Authenticate your account by including your secret key in API requests.

        You can manage your API keys in the
        [Dashboard](https://app.getfernand.com/).


        Authentication to the API is performed by using the HTTP Header
        X-API-Key.
      name: X-API-Key
      in: header
      x-last-modified: 1764750344730

````