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

# Create a rule



## OpenAPI

````yaml /openapi.json post /v1/rules
openapi: 3.1.0
info:
  title: Moneyline API
  description: Enterprise Financial Document Intelligence API
  version: 1.0.0
servers:
  - url: http://localhost:3000
    description: Local
  - url: https://api.moneyline.co
    description: Production
security:
  - apiKey: []
tags:
  - name: AI
  - name: Account
  - name: Analytics
  - name: Annotations
  - name: Api Keys
  - name: Apps
  - name: Audit
  - name: Billing
  - name: Broker
  - name: Categories
  - name: Crm Integrations
  - name: Data Sources
  - name: Document Classes
  - name: Documents
  - name: Email Templates
  - name: Emails
  - name: Enrichers
  - name: Entities
  - name: Exceptions
  - name: Feedback
  - name: File Rename Rules
  - name: Files
  - name: Funders
  - name: ISO Applications
  - name: Integrations
  - name: Invitations
  - name: Logs
  - name: Merchant Groups
  - name: Merchants
  - name: Notifications
  - name: Organization Links
  - name: Pdfs
  - name: Policies
  - name: Positions
  - name: Presence
  - name: Rules
  - name: Search
  - name: Shared
  - name: Shared With Me
  - name: Studio
  - name: Submissions
  - name: Tasks
  - name: Tenant
  - name: Transactions
  - name: Triggers
  - name: Usage
  - name: User
  - name: Users
  - name: Webhooks
  - name: Workflows
paths:
  /v1/rules:
    post:
      tags:
        - Rules
      summary: Create a rule
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                metric:
                  type: string
                  minLength: 1
                operator:
                  type: string
                  enum:
                    - '>='
                    - <=
                    - '=='
                    - '!='
                    - between
                    - in
                threshold:
                  anyOf:
                    - type: number
                    - type: array
                      items:
                        type: number
                      minItems: 2
                      maxItems: 2
                    - type: array
                      items:
                        type: string
                date_range:
                  type: string
                  default: last_90_days
                severity:
                  type: string
                  enum:
                    - info
                    - warning
                    - hard_decline
                  default: warning
                message:
                  type: string
                sort_order:
                  type: integer
              required:
                - name
                - metric
                - operator
                - threshold
              additionalProperties: false
      responses:
        '201':
          description: Default Response
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/Rule'
                required:
                  - data
                additionalProperties: true
        '400':
          description: Default Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Default Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: Default Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Default Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: Default Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: Default Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Default Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      x-codeSamples:
        - lang: typescript
          label: Node.js
          source: |-
            import { Moneyline } from '@moneyline/sdk';

            const client = new Moneyline();

            const result = await client.rules.create({
              name: 'Acme Corp',
              metric: 'string',
              operator: '>=',
              threshold: 'string',
            });
        - lang: python
          label: Python
          source: |-
            from moneyline import Moneyline

            client = Moneyline()

            result = client.rules.create(
                name="Acme Corp",
                metric="string",
                operator=">=",
                threshold="string",
            )
        - lang: go
          label: Go
          source: "client, err := moneyline.NewClient(os.Getenv(\"MONEYLINE_API_KEY\"))\nif err != nil {\n\tlog.Fatal(err)\n}\n\nresult, err := client.Rules.Create(context.Background(), &moneyline.CreateRuleParams{\n\tName     : \"Acme Corp\",\n\tMetric   : \"string\",\n\tOperator : \">=\",\n\tThreshold: \"string\",\n})\nif err != nil {\n\tlog.Fatal(err)\n}"
components:
  schemas:
    Rule:
      type: object
      properties:
        id:
          type: string
        tenantId:
          type: string
        name:
          type: string
        metric:
          type: string
        operator:
          type: string
        threshold: {}
        dateRange:
          type: string
          nullable: true
        severity:
          type: string
        message:
          type: string
          nullable: true
        isActive:
          type: boolean
        sortOrder:
          type: number
        createdAt: {}
        updatedAt: {}
      required:
        - id
        - name
        - metric
        - operator
        - severity
      additionalProperties: true
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            type:
              type: string
              description: Error category, e.g. validation_error, not_found_error
            code:
              type: string
              description: Machine-readable ml_* error code
            message:
              type: string
            param:
              type: string
            doc_url:
              type: string
            suggestion:
              type: string
            request_id:
              type: string
            resource_type:
              type: string
            resource_id:
              type: string
            retry_after_seconds:
              type: number
            validation_errors:
              type: array
              items:
                type: object
                properties:
                  param:
                    type: string
                  message:
                    type: string
                  code:
                    type: string
                required:
                  - param
                  - message
                additionalProperties: false
          required:
            - type
            - code
            - message
          additionalProperties: false
      required:
        - error
      additionalProperties: false
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      description: API key (ml_live_* or ml_test_*)

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.