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

# Apply a rule to existing transactions

> Runs a `BANK`-scope rule over transactions already stored, exactly as a sync would: actions, rule logs,
counterparty pairing and destination updates. With `dry_run` (the default) nothing changes and the
response counts what would (`would_change`), what already matches (`already_matching`) and a sample of
ids. A real run is queued and returns `202` with the application to poll; one run per rule at a time
(`409` otherwise). Undo a run with `PUT /rule-logs/undo-bulk` over the logs at `rule_logs_url`.



## OpenAPI

````yaml /openapi/v1.json post /rules/{ruleId}/apply
openapi: 3.2.0
info:
  title: Synci
  version: '1.0'
  description: >-
    Synci is a platform for integrating financial accounts with your favorite
    apps.
servers:
  - url: https://api.synci.io/api/v1
security:
  - oauth2: []
  - http: []
tags:
  - name: Finance
    kind: nav
  - name: Connections
    parent: Finance
  - name: Accounts
    parent: Finance
  - name: Transactions
    parent: Finance
  - name: Institutions
    parent: Finance
  - name: Destinations
    kind: nav
  - name: YNAB
    parent: Destinations
  - name: Lunch Money
    parent: Destinations
  - name: Google Sheets
    parent: Destinations
  - name: SimpleFIN
    parent: Destinations
  - name: Notion
    parent: Destinations
  - name: Account
    kind: nav
  - name: Webhooks
    parent: Account
  - name: User
    parent: Account
  - name: rule-engine
    summary: Rules
    kind: nav
  - name: Rules
    parent: rule-engine
  - name: Rule Logs
    parent: rule-engine
  - name: Transfers
    kind: nav
  - name: Transfer Links
    parent: Transfers
  - name: Transfer Logs
    parent: Transfers
paths:
  /rules/{ruleId}/apply:
    post:
      tags:
        - Rules
      summary: Apply a rule to existing transactions
      description: >-
        Runs a `BANK`-scope rule over transactions already stored, exactly as a
        sync would: actions, rule logs,

        counterparty pairing and destination updates. With `dry_run` (the
        default) nothing changes and the

        response counts what would (`would_change`), what already matches
        (`already_matching`) and a sample of

        ids. A real run is queued and returns `202` with the application to
        poll; one run per rule at a time

        (`409` otherwise). Undo a run with `PUT /rule-logs/undo-bulk` over the
        logs at `rule_logs_url`.
      operationId: rules.apply
      parameters:
        - name: ruleId
          in: path
          required: true
          description: The rule ID
          schema:
            type: integer
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ApplyRuleRequest'
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      would_change:
                        type: integer
                        const: 0
                      already_matching:
                        type: integer
                        const: 0
                      sample_transaction_ids:
                        type: array
                        items:
                          type: string
                        minItems: 0
                        maxItems: 0
                    required:
                      - would_change
                      - already_matching
                      - sample_transaction_ids
                required:
                  - data
        '202':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    const: Rule application queued.
                  data:
                    $ref: '#/components/schemas/RuleApplicationResource'
                required:
                  - message
                  - data
        '401':
          $ref: '#/components/responses/AuthenticationException'
        '403':
          $ref: '#/components/responses/AuthorizationException'
        '404':
          $ref: '#/components/responses/ModelNotFoundException'
        '409':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                  data:
                    $ref: '#/components/schemas/RuleApplicationResource'
                required:
                  - message
                  - data
        '422':
          $ref: '#/components/responses/ValidationException'
components:
  schemas:
    ApplyRuleRequest:
      type: object
      properties:
        dry_run:
          type: boolean
          description: >-
            When true (the default) nothing is changed: the response counts what
            a real run would change.
        booking_date_after:
          type:
            - string
            - 'null'
          format: date-time
          description: >-
            Only consider transactions booked on or after this date. Default: no
            limit.
        financial_account_ids:
          type:
            - array
            - 'null'
          description: >-
            Restrict the run to these accounts. Default: every account the rule
            is attached to. Each must be attached to the rule.
          items:
            type: integer
      title: ApplyRuleRequest
    RuleApplicationResource:
      type: object
      properties:
        id:
          type: string
        rule_id:
          type: string
          description: The rule that was applied.
        status:
          type: string
          description: '`QUEUED`, `RUNNING`, `COMPLETED` or `FAILED`.'
        changed:
          type: string
          description: Transactions the rule's actions changed so far.
        total:
          type: string
          description: Transactions whose conditions matched so far.
        financial_account_ids:
          type: string
          description: >-
            The accounts the run covered; null means every account the rule is
            attached to.
        booking_date_after:
          type:
            - string
            - 'null'
          description: >-
            Only transactions booked on or after this date were considered; null
            means no limit.
        message:
          type:
            - string
            - 'null'
          description: Recovery guidance; stored exception details are private diagnostics.
          enum:
            - >-
              The application could not finish. Some transactions may already
              have changed. Review the application logs before trying again.
            - null
        started_at:
          type: string
        completed_at:
          type: string
        rule_logs_url:
          type: string
          description: >-
            The rule logs written by this run, for "undo this application" via
            `PUT /rule-logs/undo-bulk`.
        created_at:
          type: string
      required:
        - id
        - rule_id
        - status
        - changed
        - total
        - financial_account_ids
        - booking_date_after
        - message
        - started_at
        - completed_at
        - rule_logs_url
        - created_at
      title: RuleApplicationResource
  responses:
    AuthenticationException:
      description: Unauthenticated
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                description: Error overview.
            required:
              - message
    AuthorizationException:
      description: Authorization error
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                description: Error overview.
            required:
              - message
    ModelNotFoundException:
      description: Not found
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                description: Error overview.
            required:
              - message
    ValidationException:
      description: Validation error
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                description: Errors overview.
              errors:
                type: object
                description: A detailed description of each field that failed validation.
                additionalProperties:
                  type: array
                  items:
                    type: string
            required:
              - message
              - errors
  securitySchemes:
    oauth2:
      type: oauth2
      flows:
        authorizationCode:
          authorizationUrl: https://api.synci.io/oauth/authorize
          tokenUrl: https://api.synci.io/oauth/token
          scopes:
            profile:read: View your name, email, and profile details
            accounts:read: View your connected financial accounts and balances
            accounts:write: >-
              Update, sync, and remove your financial accounts, and change their
              settings
            transactions:read: View your transactions
            transactions:write: Create, update, and delete your transactions
            sensitive:read: >-
              See sensitive identifiers like account numbers and account holder
              names
            transfer-links:read: View your transfer links and their transfer history
            transfer-links:write: Create, update, and delete transfer links, and undo transfers
            rules:read: View your rules and rule activity
            rules:write: Create, update, and delete rules, and undo rule actions
            webhooks:read: View your webhook endpoints
            webhooks:write: >-
              Create, update, and delete webhook endpoints, and rotate their
              secrets
            destinations:read: View your connected destinations
            destinations:write: Connect, update, and remove destinations
            financial-connections:read: View your connected institutions
            financial-connections:write: Manage your connected institutions
    http:
      type: http
      description: Bearer token (personal access token or OAuth access token)
      scheme: bearer

````

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