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

# Create an accounting code rule



## OpenAPI

````yaml /spec/openapi.json post /accounting_code_rules
openapi: 3.0.0
info:
  title: Nmbr API
  description: API to interact with Nmbr Payroll
  version: 1.0.0
servers:
  - url: https://sandbox.nmbr.co/services/payroll
security:
  - CompanyToken: []
tags:
  - name: Accounting Codes
  - name: Accounting Code Rules
  - name: Adjustments
  - name: Allowances
  - name: Allowance Line Items
  - name: Allowance Types
  - name: Async Tasks
  - name: Bank Accounts
  - name: Business Entities
  - name: Business Entity Verifications
  - name: Business Entity ROE Authorizations
  - name: Business Presets
  - name: Calculations
  - name: Companies
  - name: Contractors
  - name: Deductions
  - name: Deduction Line Items
  - name: Deduction Types
  - name: Earnings
  - name: Earning Line Items
  - name: Earning Types
  - name: Effective Tax Properties
  - name: Employees
  - name: Employee Benefits
  - name: Employee Benefit Line Items
  - name: Employee Benefit Types
  - name: Employer Benefits
  - name: Employer Benefit Line Items
  - name: Employer Benefit Types
  - name: Employer Statutory Withholding Line Items
  - name: Employer Statutory Withholding Types
  - name: Forms
  - name: Form Batches
  - name: Form Types
  - name: Holidays
  - name: Integrations
  - name: Journal Entries
  - name: Overtime Rates
  - name: Partners
  - name: Pay Rates
  - name: Pay Schedules
  - name: Pay Splits
  - name: Pay Stubs
  - name: Payments
  - name: Payrolls
  - name: Reimbursements
  - name: Reimbursement Line Items
  - name: Reimbursement Types
  - name: Remittance Accounts
  - name: Remittance Account Enrollments
  - name: Reports
  - name: Statutory Withholding Line Items
  - name: Statutory Withholding Types
  - name: Tags
  - name: Tag Groups
  - name: Tax Properties
  - name: Tax Property Templates
  - name: Tokens
  - name: Usage Records
  - name: Usage Summaries
  - name: Vacation Pay
  - name: Vacation Pay Settings
  - name: Webhooks
  - name: Work Assignments
paths:
  /accounting_code_rules:
    post:
      tags:
        - Accounting Code Rules
      summary: Create an accounting code rule
      operationId: accounting-code-rules-store
      requestBody:
        content:
          application/json:
            schema:
              allOf:
                - type: object
                  properties:
                    business_entity_id:
                      type: string
                    tag_group_id:
                      type: string
                      description: >-
                        A tag group to scope this rule to. When set without
                        `tag_id`, creates a tag-group-level rule that applies to
                        all tags in the group.
                    tag_id:
                      type: string
                      description: >-
                        A tag from the business entity's accounting code tag
                        group. Optional — when omitted, the rule matches line
                        items by `type`/`subtype` or `business_preset_id` alone.
                    type:
                      type: string
                      description: >-
                        The line item type to scope this rule to (e.g.
                        `earning`, `deduction`). Mutually exclusive with
                        `business_preset_id`.
                      enum:
                        - allowance
                        - deduction
                        - earning
                        - employee_benefit
                        - employer_benefit
                        - employer_statutory_withholding
                        - reimbursement
                        - statutory_withholding
                    subtype:
                      type: string
                      description: >-
                        The line item subtype to further scope this rule (e.g.
                        `wage`, `salary`). Requires `type` to be set.
                      nullable: true
                    business_preset_id:
                      type: string
                      description: >-
                        A business preset to scope this rule to. Provides the
                        highest specificity match. Mutually exclusive with
                        `type` and `subtype`.


                        When both `tag_id` and `tag_group_id` are omitted,
                        either `type` or `business_preset_id` must be set.
                    expense_accounting_code_id:
                      type: string
                    liability_accounting_code_id:
                      type: string
                    expense_accounting_code_template:
                      $ref: '#/components/schemas/AccountingCodeTemplate'
                    liability_accounting_code_template:
                      $ref: '#/components/schemas/AccountingCodeTemplate'
                - type: object
                  required:
                    - business_entity_id
            example:
              business_entity_id: <id>
              type: earning
              subtype: wage
              expense_accounting_code_id: <id>
              liability_accounting_code_id: <id>
              expense_accounting_code_template:
                segments:
                  - type: accounting_code
                    id: <id>
                    prefix: GL-
                  - type: tag_group
                    tag_group_id: <id>
                    prefix: '-'
                    transform:
                      - uppercase
                    fallback: '0000'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    description: The unique identifier of the object in Nmbr.
                    readOnly: true
                  object:
                    type: string
                    description: The type of the object in Nmbr (`"accounting_code_rule"`).
                    readOnly: true
                  data:
                    $ref: '#/components/schemas/AccountingCodeRule'
              example:
                id: <id>
                object: accounting_code_rule
                data:
                  business_entity:
                    id: <id>
                    object: business_entity
                    links:
                      self: /business_entities/<id>
                  tag_group: null
                  tag: null
                  type: earning
                  subtype: wage
                  business_preset: null
                  expense_accounting_code:
                    id: <id>
                    object: accounting_code
                    links:
                      self: /accounting_codes/<id>
                  liability_accounting_code:
                    id: <id>
                    object: accounting_code
                    links:
                      self: /accounting_codes/<id>
                  expense_accounting_code_template:
                    segments:
                      - type: accounting_code
                        id: <id>
                        prefix: GL-
                      - type: tag_group
                        tag_group_id: <id>
                        prefix: '-'
                        transform:
                          - uppercase
                        fallback: '0000'
                  liability_accounting_code_template: null
                  created_at: '2026-01-01T00:00:00.000000Z'
                  updated_at: '2026-01-01T00:00:00.000000Z'
                links:
                  self: /accounting_code_rules/<id>
components:
  schemas:
    AccountingCodeTemplate:
      type: object
      description: >-
        Assembles a formatted accounting code for the journal entry report: each
        segment resolves to a value, is wrapped and transformed, and the results
        are concatenated in order. Only valid on rules with no tag and no tag
        group; `null` when unset.
      nullable: true
      properties:
        segments:
          type: array
          description: Ordered segments concatenated into the generated code.
          items:
            type: object
            anyOf:
              - type: object
                description: Emits the referenced accounting code's `code`.
                title: Fixed accounting code
                properties:
                  type:
                    type: string
                    enum:
                      - accounting_code
                  id:
                    type: string
                    description: Id of an accounting code in this business entity.
                  prefix:
                    type: string
                    description: Literal text prepended to the resolved value.
                    nullable: true
                    maxLength: 255
                  suffix:
                    type: string
                    description: Literal text appended to the resolved value.
                    nullable: true
                    maxLength: 255
                  transform:
                    type: array
                    description: >-
                      Transforms applied to the resolved value in the order
                      listed.
                    nullable: true
                    items:
                      type: string
                      enum:
                        - alphanumeric
                        - lowercase
                        - uppercase
                  max_length:
                    type: integer
                    description: Truncates the resolved value to this many characters.
                    nullable: true
                    minimum: 1
                  fallback:
                    type: string
                    description: >-
                      Substituted when the resolved value is empty. When absent
                      or empty, an empty segment is dropped instead — prefix and
                      suffix included.
                    nullable: true
                    maxLength: 255
                required:
                  - type
                  - id
              - type: object
                description: >-
                  Emits the row's tag in this group — its expense template code
                  in an expense template, its liability template code in a
                  liability template.
                title: Tag group code
                properties:
                  type:
                    type: string
                    enum:
                      - tag_group
                  tag_group_id:
                    type: string
                    description: Id of a tag group in this business entity.
                  prefix:
                    type: string
                    description: Literal text prepended to the resolved value.
                    nullable: true
                    maxLength: 255
                  suffix:
                    type: string
                    description: Literal text appended to the resolved value.
                    nullable: true
                    maxLength: 255
                  transform:
                    type: array
                    description: >-
                      Transforms applied to the resolved value in the order
                      listed.
                    nullable: true
                    items:
                      type: string
                      enum:
                        - alphanumeric
                        - lowercase
                        - uppercase
                  max_length:
                    type: integer
                    description: Truncates the resolved value to this many characters.
                    nullable: true
                    minimum: 1
                  fallback:
                    type: string
                    description: >-
                      Substituted when the resolved value is empty. When absent
                      or empty, an empty segment is dropped instead — prefix and
                      suffix included.
                    nullable: true
                    maxLength: 255
                required:
                  - type
                  - tag_group_id
          minItems: 1
          maxItems: 20
      required:
        - segments
    AccountingCodeRule:
      type: object
      title: Accounting Code Rule
      properties:
        business_entity:
          type: object
          properties:
            id:
              type: string
              description: The unique identifier of the object in Nmbr.
              readOnly: true
            object:
              type: string
              description: The type of the object in Nmbr (`"business_entity"`).
              readOnly: true
        tag_group:
          type: object
          properties:
            id:
              type: string
              description: The unique identifier of the object in Nmbr.
              readOnly: true
            object:
              type: string
              description: The type of the object in Nmbr (`"tag_group"`).
              readOnly: true
        tag:
          type: object
          properties:
            id:
              type: string
              description: The unique identifier of the object in Nmbr.
              readOnly: true
            object:
              type: string
              description: The type of the object in Nmbr (`"tag"`).
              readOnly: true
        type:
          type: string
          description: >-
            The line item type this rule applies to (e.g. `earning`,
            `deduction`). When combined with `subtype`, narrows the rule to a
            specific line item category. Mutually exclusive with
            `business_preset`.
          nullable: true
          maxLength: 255
        subtype:
          type: string
          description: >-
            The line item subtype this rule applies to (e.g. `wage`, `salary`).
            Must be accompanied by a `type`.
          nullable: true
          maxLength: 255
        business_preset:
          description: >-
            A business preset this rule applies to. Provides the highest
            specificity match. Mutually exclusive with `type` and `subtype`.
        expense_accounting_code:
          type: object
          description: The expense accounting code assigned when this rule matches.
          properties:
            id:
              type: string
              description: The unique identifier of the object in Nmbr.
              readOnly: true
            object:
              type: string
              description: The type of the object in Nmbr (`"accounting_code"`).
              readOnly: true
        liability_accounting_code:
          description: The liability accounting code assigned when this rule matches.
        expense_accounting_code_template:
          $ref: '#/components/schemas/AccountingCodeTemplate'
        liability_accounting_code_template:
          $ref: '#/components/schemas/AccountingCodeTemplate'
        created_at:
          type: string
          description: The date and time the object was created in Nmbr.
          readOnly: true
          format: dateTime
        updated_at:
          type: string
          description: The date and time the object was last updated in Nmbr.
          readOnly: true
          format: dateTime
  securitySchemes:
    CompanyToken:
      type: http
      scheme: bearer

````