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

# Test a rule against past transactions

> Runs the rule against the live transactions you have already submitted and reports how many it would have matched, out of how many tested, with a few example transaction ids. Test transactions are excluded, so a threshold is sized against real traffic only. Optional `dateFrom` and `dateTo` bound the window; `limit` sizes the sample of matching ids collected and never the counts.

Nothing is written: no alerts are raised, no statuses change, and the rule's own status is unaffected. This is how a threshold gets sized before activation — a rule matching most of your traffic will bury the queue.

A test gets 10 seconds of database time. One that needs longer is stopped and answered with a `400` saying so, rather than with counts it did not finish; test a shorter period with `dateFrom` and `dateTo`. Each user or API key may run 10 tests a minute; more are answered with a `429`.



## OpenAPI

````yaml /openapi/transaction-monitoring.json post /api/v1/rules/{rule_id}/test/
openapi: 3.0.3
info:
  title: iDenfy Transaction Monitoring API
  version: v1
  description: >-
    Submit transactions and events for AML monitoring, and read back the alerts,
    cases and reports they produce.
servers:
  - url: https://ivs-tx-monitoring.idenfy.com
    description: Production
security:
  - ApiKeyAuth: []
tags:
  - name: Ingest
    description: Submit transactions and events for monitoring.
  - name: Transactions
    description: Read back submitted transactions and their rule hits.
  - name: Rules
    description: Detection rules evaluated against every submission.
  - name: Alerts
    description: Alerts opened when a rule matches.
  - name: Investigations
    description: Cases opened from one or more alerts.
  - name: SARs
    description: Suspicious activity reports and their attachments.
  - name: Sanctions screening
    description: Sanctions and PEP screening of transaction parties.
  - name: AML monitoring
    description: Ongoing AML monitoring of screened parties.
  - name: Party suspensions
    description: ''
  - name: Webhooks
    description: Outbound event delivery to your endpoints.
  - name: Custom fields
    description: Your own transaction attributes, declared so rules can match them.
  - name: Reference lists
    description: Named value lists rules can reference.
  - name: Notification rules
    description: Slack and email notifications for alerts.
  - name: Reports
    description: Generated compliance reports.
paths:
  /api/v1/rules/{rule_id}/test/:
    post:
      tags:
        - Rules
      summary: Test a rule against past transactions
      description: >-
        Runs the rule against the live transactions you have already submitted
        and reports how many it would have matched, out of how many tested, with
        a few example transaction ids. Test transactions are excluded, so a
        threshold is sized against real traffic only. Optional `dateFrom` and
        `dateTo` bound the window; `limit` sizes the sample of matching ids
        collected and never the counts.


        Nothing is written: no alerts are raised, no statuses change, and the
        rule's own status is unaffected. This is how a threshold gets sized
        before activation — a rule matching most of your traffic will bury the
        queue.


        A test gets 10 seconds of database time. One that needs longer is
        stopped and answered with a `400` saying so, rather than with counts it
        did not finish; test a shorter period with `dateFrom` and `dateTo`. Each
        user or API key may run 10 tests a minute; more are answered with a
        `429`.
      operationId: rules_test_create
      parameters:
        - in: path
          name: rule_id
          schema:
            type: string
            format: uuid
            description: Primary key
          required: true
          description: Identifies the rule.
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RuleSandboxTestRequest'
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/RuleSandboxTestRequest'
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/RuleSandboxTestRequest'
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RuleSandboxTestResponse'
          description: ''
      security:
        - ApiKeyAuth: []
components:
  schemas:
    RuleSandboxTestRequest:
      type: object
      properties:
        dateFrom:
          type: string
          format: date-time
          nullable: true
          description: Only transactions created at or after this instant are tested
        dateTo:
          type: string
          format: date-time
          nullable: true
          description: Only transactions created at or before this instant are tested
        limit:
          type: integer
          maximum: 1000
          minimum: 1
          default: 100
          description: How many matching ids to collect for the sample, 1-1000
    RuleSandboxTestResponse:
      oneOf:
        - $ref: '#/components/schemas/RuleSandboxVelocityTest'
        - $ref: '#/components/schemas/RuleSandboxSqlTest'
        - $ref: '#/components/schemas/RuleSandboxError'
    RuleSandboxVelocityTest:
      type: object
      properties:
        ruleType:
          allOf:
            - $ref: '#/components/schemas/RuleType'
          description: |-
            Always VELOCITY; absent from the SINGLE-rule response shape

            * `SINGLE` - Single
            * `VELOCITY` - Velocity
            * `BEHAVIOURAL` - Unusual behaviour
        windowSeconds:
          type: integer
          description: Rolling window the metric was aggregated over
        threshold:
          type: number
          format: double
          description: Value the metric is compared against
        comparator:
          allOf:
            - $ref: '#/components/schemas/ComparatorEnum'
          description: |-
            How metric meets threshold

            * `>=` - >=
            * `>` - >
            * `<=` - <=
            * `<` - <
        groupBy:
          type: string
          nullable: true
          description: First grouping field, for single-field rules
        groupByFields:
          type: array
          items:
            type: string
          description: Every grouping field, in order
        matchedEntities:
          type: integer
          description: >-
            Count of violating entities — a number, not the entities. Drawn from
            the 500 most recent transactions in the window, so a busier window
            is sampled rather than fully scanned
        hits:
          type: array
          items:
            $ref: '#/components/schemas/RuleSandboxVelocityHit'
          description: >-
            Up to 50 violating entities; `matched_entities` is not truncated to
            this
      required:
        - comparator
        - groupBy
        - groupByFields
        - hits
        - matchedEntities
        - ruleType
        - threshold
        - windowSeconds
    RuleSandboxSqlTest:
      type: object
      properties:
        matchedCount:
          type: integer
          description: >-
            Live transactions in the requested window matching the rule
            fragment, not capped by `limit`
        totalTested:
          type: integer
          description: >-
            Live transactions in the requested window, which `matched_count` is
            a fraction of
        matchRate:
          type: number
          format: double
          description: '`matched_count` over `total_tested`, 0.0 when nothing was tested'
        sampleMatches:
          type: array
          items:
            type: string
          description: Ids of the first five matches, for spot-checking the fragment
      required:
        - matchRate
        - matchedCount
        - sampleMatches
        - totalTested
    RuleSandboxError:
      type: object
      properties:
        error:
          type: string
          description: Why the rule could not be dry-run; no other field is present
      required:
        - error
    RuleType:
      enum:
        - SINGLE
        - VELOCITY
        - BEHAVIOURAL
      type: string
      description: |-
        * `SINGLE` - Single
        * `VELOCITY` - Velocity
        * `BEHAVIOURAL` - Unusual behaviour
    ComparatorEnum:
      enum:
        - '>='
        - '>'
        - <=
        - <
      type: string
      description: |-
        * `>=` - >=
        * `>` - >
        * `<=` - <=
        * `<` - <
    RuleSandboxVelocityHit:
      type: object
      properties:
        entity:
          type: string
          description: Grouped entity, its `group_by_fields` values joined with " | "
        value:
          type: number
          format: double
          description: >-
            Metric the entity reached in the window, compared against
            `threshold`
      required:
        - entity
        - value
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key

````

## Related topics

- [Transaction Monitoring Dashboard: Detection Rules](https://documentation.idenfy.com/guides/dashboard/transaction-monitoring/rules.md)
- [Transaction Monitoring API Test Mode](https://documentation.idenfy.com/transaction-monitoring/test-mode.md)
- [Activate a rule](https://documentation.idenfy.com/api-reference/transaction-monitoring/rules/activate-a-rule.md)
- [Create a notification rule](https://documentation.idenfy.com/api-reference/transaction-monitoring/notification-rules/create-a-notification-rule.md)
- [List rules](https://documentation.idenfy.com/api-reference/transaction-monitoring/rules/list-rules.md)


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