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

# Create Rule

> Custom rules can be created to associate specific attributes to pay statement items depending on the use case. For example, pay statement items that meet certain conditions can be labeled as a pre-tax 401k. This metadata can be retrieved where pay statement item information is available.




## OpenAPI

````yaml post /employer/pay-statement-item/rule
openapi: 3.1.0
info:
  title: API Reference
  version: '2020-09-17'
  contact: {}
  description: >-
    The Finch HRIS API provides a unified way to connect to a multitide of HRIS
    systems. The API requires an access token issued by Finch.


    By default, Organization and Payroll requests use Finch's [Data
    Syncs](/developer-resources/Data-Syncs). If a request is made before the
    initial sync has completed, Finch will request data live from the provider.
    The latency on live requests may range from seconds to minutes depending on
    the provider and batch size.

    For automated integrations, Deductions requests (both read and write) are
    always made live to the provider. Latencies may range from seconds to
    minutes depending on the provider and batch size.



    Employer products are specified by the product parameter, a space-separated
    list of products that your application requests from an employer
    authenticating through Finch Connect. Valid product names are—

    - `company`: Read basic company data


    - `directory`: Read company directory and organization structure


    - `individual`: Read individual data, excluding income and employment data


    - `employment`: Read individual employment and income data


    - `payment`: Read payroll and contractor related payments by the company


    - `pay_statement`: Read detailed pay statements for each individual


    - `benefits`: Create and manage deductions and contributions and enrollment
    for an employer


    [![Open in
    Postman](https://run.pstmn.io/button.svg)](https://god.gw.postman.com/run-collection/21027137-08db0929-883d-4094-a9ce-dbf5a9bee4a4?action=collection%2Ffork&collection-url=entityId%3D21027137-08db0929-883d-4094-a9ce-dbf5a9bee4a4%26entityType%3Dcollection%26workspaceId%3D1edf19bc-e0a8-41e9-ac55-481a4b50790b)
servers:
  - url: https://api.tryfinch.com
    description: ''
security: []
tags:
  - name: Organization
  - name: Payroll
  - name: Deductions
  - name: Management
  - name: Sandbox
paths:
  /employer/pay-statement-item/rule:
    post:
      tags:
        - Payroll
      summary: Create Rule
      description: >
        Custom rules can be created to associate specific attributes to pay
        statement items depending on the use case. For example, pay statement
        items that meet certain conditions can be labeled as a pre-tax 401k.
        This metadata can be retrieved where pay statement item information is
        available.
      operationId: create-rule
      parameters:
        - name: entity_ids
          in: query
          required: false
          description: The entity IDs to create the rule for.
          schema:
            type: array
            items:
              type: string
              format: uuid
            minItems: 1
            maxItems: 1
            example:
              - 550e8400-e29b-41d4-a716-446655440000
          style: form
          explode: true
        - $ref: '#/components/parameters/API-Version'
        - $ref: '#/components/parameters/Content-Type'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateRuleRequest'
      responses:
        '201':
          description: Successfully Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateRuleResponse'
              examples:
                Success:
                  value:
                    id: 5d0b10a1-a09a-430f-81f1-20be735dc5e9
                    priority: 1
                    effective_start_date: '2025-01-01'
                    effective_end_date: '2025-12-31'
                    conditions:
                      - field: name
                        operator: equals
                        value: Salary
                    attributes:
                      metadata:
                        myLabel: My Value
                    entity_type: pay_statement_item
                    created_at: '2025-01-01T10:00:00Z'
                    updated_at: '2025-01-01T10:00:00Z'
        '400':
          description: Malformed Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                Bad Request:
                  value:
                    code: 400
                    name: invalid_request_error
                    finch_code: invalid_request
                    message: >-
                      Validation error: Array must contain at least 1 element(s)
                      at "conditions"
      security:
        - bearerAuth: []
      x-codeSamples:
        - lang: JavaScript
          source: >-
            import Finch from '@tryfinch/finch-api';


            const client = new Finch({
              accessToken: 'My Access Token',
            });


            const rule = await
            client.hris.company.payStatementItem.rules.create();


            console.log(rule.id);
        - lang: Python
          source: |-
            from finch import Finch

            client = Finch(
                access_token="My Access Token",
            )
            rule = client.hris.company.pay_statement_item.rules.create()
            print(rule.id)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/Finch-API/finch-api-go\"\n\t\"github.com/Finch-API/finch-api-go/option\"\n)\n\nfunc main() {\n\tclient := finchgo.NewClient(\n\t\toption.WithAccessToken(\"My Access Token\"),\n\t)\n\trule, err := client.HRIS.Company.PayStatementItem.Rules.New(context.TODO(), finchgo.HRISCompanyPayStatementItemRuleNewParams{})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", rule.ID)\n}\n"
        - lang: Java
          source: >-
            package com.tryfinch.api.example;


            import com.tryfinch.api.client.FinchClient;

            import com.tryfinch.api.client.okhttp.FinchOkHttpClient;

            import
            com.tryfinch.api.models.HrisCompanyPayStatementItemRuleCreateParams;

            import com.tryfinch.api.models.RuleCreateResponse;


            public final class Main {
                private Main() {}

                public static void main(String[] args) {
                    FinchClient client = FinchOkHttpClient.builder()
                        .fromEnv()
                        .accessToken("My Access Token")
                        .build();

                    RuleCreateResponse rule = client.hris().company().payStatementItem().rules().create();
                }
            }
        - lang: Kotlin
          source: >-
            package com.tryfinch.api.example


            import com.tryfinch.api.client.FinchClient

            import com.tryfinch.api.client.okhttp.FinchOkHttpClient

            import
            com.tryfinch.api.models.HrisCompanyPayStatementItemRuleCreateParams

            import com.tryfinch.api.models.RuleCreateResponse


            fun main() {
                val client: FinchClient = FinchOkHttpClient.builder()
                    .fromEnv()
                    .accessToken("My Access Token")
                    .build()

                val rule: RuleCreateResponse = client.hris().company().payStatementItem().rules().create()
            }
        - lang: Ruby
          source: |-
            require "finch_api"

            finch = FinchAPI::Client.new(access_token: "My Access Token")

            rule = finch.hris.company.pay_statement_item.rules.create

            puts(rule)
components:
  parameters:
    API-Version:
      name: Finch-API-Version
      in: header
      required: true
      schema:
        type: string
        default: '2020-09-17'
        format: date
        pattern: ([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))
      description: >-
        Header used to specify the version for a given API request. Current
        version is 2020-09-17.
    Content-Type:
      name: Content-Type
      in: header
      required: true
      schema:
        type: string
        default: application/json
      description: 'Used to indicate the original media type of the resource '
  schemas:
    CreateRuleRequest:
      type: object
      properties:
        effective_start_date:
          $ref: '#/components/schemas/Date'
          description: Specifies when the rule should begin applying based on the date.
        effective_end_date:
          $ref: '#/components/schemas/Date'
          description: >-
            Specifies when the rules should stop applying rules based on the
            date.
        conditions:
          type: array
          items:
            type: object
            properties:
              field:
                type: string
                description: The field to be checked in the rule.
              operator:
                type: string
                description: The operator to be used in the rule.
                enum:
                  - equals
              value:
                type: string
                description: The value of the field to be checked in the rule.
        attributes:
          type: object
          description: Specifies the fields to be applied when the condition is met.
          properties:
            metadata:
              type: object
              description: >-
                The metadata to be attached in the entity. It is a key-value
                pairs where the values can be of any type (string, number,
                boolean, object, array, etc.).
              additionalProperties: true
        entity_type:
          type: string
          description: The entity type to which the rule is applied.
          enum:
            - pay_statement_item
    CreateRuleResponse:
      allOf:
        - type: object
          properties:
            id:
              type: string
              description: Finch id (uuidv4) for the rule.
              pattern: '[0-9a-f]{8}[-]?(?:[0-9a-f]{4}[-]?){3}[0-9a-f]{12}'
            priority:
              type: integer
              description: The priority of the rule.
            created_at:
              type: string
              format: date-time
              description: The datetime when the rule was created.
            updated_at:
              type: string
              format: date-time
              description: The datetime when the rule was last updated.
        - $ref: '#/components/schemas/CreateRuleRequest'
    Error:
      title: Error
      type: object
      description: Generic error response structure
      properties:
        code:
          type: integer
          description: The status code of the request.
        name:
          type: string
          description: Identifier describing the error.
        finch_code:
          type: string
          description: A descriptive identifier for the error.
        message:
          type: string
          description: >-
            A short English description that provides more information about the
            error.
    Date:
      type: string
      title: Date
      nullable: true
      pattern: (\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Please use your Access Token

````