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

# Create Client Rule

> Creates a new worker matching rule for a specific client. Rules filter which workers are eligible for this client's events based on custom field values, credentials, and tags.

Rules filter which workers are eligible for this client's events. A rule is defined by a `field_id` (referencing a worker custom field) and an `operator` (`is`, `is not`, etc.).

The response includes the full rule structure with resolved field names, credentials, and tags:

* **`fields`** — Custom field conditions (e.g., "Facial Hair is Yes").
* **`credentials`** — Credential requirements (e.g., "has Completion certificate").
* **`has_tags`** — Workers must have these tags.
* **`does_not_have_tags`** — Workers must not have these tags.


## OpenAPI

````yaml api-reference/v01.12.00/openapi-v01.12.00.json POST /clients/{id}/rules
openapi: 3.0.0
info:
  title: Roosted
  version: 0.1.12
  contact:
    name: Support
    url: https://support.roostedhr.com/support/home
    email: support@roostedhr.com
  description: |-
    Enterprise API

    Sandbox keys and Production keys are requested from support
servers:
  - url: https://api.roostedhr.com/api/1_12
  - url: https://sandbox.roostedhr.com/api/1_12
security:
  - X-API-KEY: []
tags:
  - name: Announcements
  - name: Areas
  - name: Clients
  - name: Company
  - name: Configuration
  - name: Events
  - name: Locations
  - name: Payroll Groups
  - name: Rate Cards
  - name: Shifts
  - name: Skillsets
  - name: Time Tracking
  - name: Wage Rules
  - name: Workers
paths:
  /clients/{id}/rules:
    parameters:
      - schema:
          type: string
        name: id
        in: path
        required: true
        description: Client ID
    post:
      tags:
        - Clients
      summary: Create Client Rule
      description: >-
        Creates a new worker matching rule for a specific client. Rules filter
        which workers are eligible for this client's events based on custom
        field values, credentials, and tags.
      operationId: post-client-rule
      requestBody:
        description: Rule definition. Requires `field_id` and `operator`.
        content:
          application/json:
            schema:
              type: object
              properties:
                field_id:
                  type: integer
                  description: Custom field ID to match against.
                operator:
                  type: string
                  description: Comparison operator (e.g., `is`, `is not`).
                tag_id:
                  type: string
                  nullable: true
                  description: Tag ID for tag-based rules.
                value:
                  nullable: true
                  oneOf:
                    - type: string
                    - type: integer
                  description: Value to compare against.
              required:
                - field_id
                - operator
            examples:
              Create Client Rule:
                value:
                  field_id: 111
                  operator: is not
                  tag_id: null
                  value: Value
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClientRule'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: string
                    description: Machine-readable error code.
                  error:
                    type: string
                    description: Human-readable error message.
              examples:
                Missing field_id:
                  value:
                    code: CLI-1300
                    error: Rule field_id is required
                Missing operator:
                  value:
                    code: CLI-1400
                    error: Rule operator is required
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: string
                    description: Machine-readable error code.
                  error:
                    type: string
                    description: Human-readable error message.
              examples:
                Invalid API key:
                  value:
                    code: ATH-100
                    error: Invalid or missing API key
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: string
                    description: Machine-readable error code.
                  error:
                    type: string
                    description: Human-readable error message.
              examples:
                Insufficient permissions:
                  value:
                    code: CLI-1900
                    error: Insufficient permissions to manage clients
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: string
                    description: Machine-readable error code.
                  error:
                    type: string
                    description: Human-readable error message.
              examples:
                Not found:
                  value:
                    code: CLI-300
                    error: Client not found
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: string
                    description: Machine-readable error code.
                  error:
                    type: string
                    description: Human-readable error message.
              examples:
                Unexpected error:
                  value:
                    code: CLI-2000
                    error: An unexpected error occurred
components:
  schemas:
    ClientRule:
      title: ClientRule
      type: object
      description: >-
        A worker matching rule for a client, composed of field conditions,
        credential requirements, and tag filters.
      properties:
        fields:
          type: array
          items:
            $ref: '#/components/schemas/ClientRuleField'
        credentials:
          type: array
          items:
            $ref: '#/components/schemas/ClientRuleCredential'
        has_tags:
          type: array
          items:
            $ref: '#/components/schemas/ClientRuleTag'
        does_not_have_tags:
          type: array
          items:
            $ref: '#/components/schemas/ClientRuleTag'
    ClientRuleField:
      title: ClientRuleField
      type: object
      properties:
        id:
          type: string
          description: Rule field entry ID.
        field_id:
          type: string
          description: Custom field ID.
        field_type:
          type: string
          description: Field type (e.g., dropdown, text).
        field_name:
          type: string
          description: Field display name.
        operator:
          type: string
          description: Comparison operator (e.g., is, is not).
        answers:
          type: array
          nullable: true
          items:
            type: object
            properties:
              id:
                type: string
              display:
                type: string
        value:
          type: string
          nullable: true
          description: Selected value.
    ClientRuleCredential:
      title: ClientRuleCredential
      type: object
      properties:
        id:
          type: string
          description: Rule credential entry ID.
        credentials_id:
          type: string
          description: Credential definition ID.
        field_id:
          type: string
          nullable: true
        field_type:
          type: string
          nullable: true
        field_name:
          type: string
          nullable: true
        name:
          type: string
          description: Credential name.
        operator:
          type: string
          description: Comparison operator (e.g., has, does not have).
        answers:
          type: array
          nullable: true
          items:
            type: object
            properties:
              id:
                type: string
              display:
                type: string
        value:
          type: string
          nullable: true
    ClientRuleTag:
      title: ClientRuleTag
      type: object
      properties:
        rule_id:
          type: string
          description: Parent rule ID.
        id:
          type: string
          description: Tag ID.
        text:
          type: string
          description: Tag display text.
        operator:
          type: string
          description: Tag match operator (e.g., has, does not have).
  securitySchemes:
    X-API-KEY:
      name: X-API-KEY
      type: apiKey
      in: header

````