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

# Rules and matches

> Learn how End Close matching rules pair records one-to-one or roll many records up into one, and how to make or undo a match by hand.

A rule tells End Close which records on Side A of a [reconciliation](https://endclose.com/docs/concepts/reconciliations.md) belong with which records on Side B. When a rule finds records that belong together, it groups them into a match, and those [records](https://endclose.com/docs/concepts/records.md) count as reconciled in that reconciliation.

## How rules and matches fit with the other concepts

* Rules belong to one [reconciliation](https://endclose.com/docs/concepts/reconciliations.md) and compare fields across its two sides.
* A match groups [records](https://endclose.com/docs/concepts/records.md) from that reconciliation's [data streams](https://endclose.com/docs/concepts/data-streams.md). A record can be in at most one match per reconciliation.
* Records that no rule or person matches stay open, and become [exceptions](https://endclose.com/docs/concepts/exceptions.md) once overdue.
* End Close's reconciliation agent writes rules for you, and you can write your own. See [Matching rules](https://endclose.com/docs/guides/matching-rules.md).

## Rule fields

| Field | Description |
| - | - |
| `priority` | Lower values run first. Records matched by an earlier rule aren't available to later ones. |
| `cardinality` | `one_to_one` (the default) or `many_to_one`. |
| `filters` | The conditions that compare a field on Side A to a field on Side B. |
| `group_by` | For `many_to_one` rules, the fields that group records on the many side. |
| `rollup` | For `many_to_one` rules, how grouped records are summed and compared. |
| `description` | Optional text saying what the rule matches. |
| `source` | `user` for rules you create, `ai` for rules End Close's agent creates. |
| `status` | `active` rules run. `proposed` rules wait for review. |

## Rule types

| Type | What it matches | Example |
| - | - | - |
| One-to-one | One record on Side A with one record on Side B. | An invoice and the bank payment for it. |
| Many-to-one | Several records on one side, summed, with one record on the other. | A day of Stripe charges and the payout that settles them. |

There's no many-to-many rule type yet. To match several records on each side, make the match by hand.

### One-to-one rules

A one-to-one rule is a tree of conditions joined with AND or OR. Each condition compares a Side A field (`key`) with a Side B field (`value`) using an operator: `eq`, `neq`, `contains`, `gt`, `gte`, `lt`, `lte`, `in` or `not_in`. Fields are the standard record fields (`amount`, `date`, `description`, `direction`, `external_id`) or metadata in dot notation, such as `metadata.invoice_number`.

A one-to-one rule must compare amounts and must include at least two exact `eq` conditions, so it can't pair records on amount alone.

```json One-to-one rule theme={"dark"}
{
  "reconciliation_id": "0193a7c4-2b8d-7e10-a3f5-91c04d6e8a21",
  "priority": 1,
  "cardinality": "one_to_one",
  "description": "Same amount and invoice number, within three days",
  "filters": {
    "kind": "group",
    "operand": "and",
    "rules": [
      { "kind": "condition", "key": "amount", "operand": "eq", "value": "amount" },
      { "kind": "condition", "key": "metadata.invoice_number", "operand": "eq", "value": "description",
        "transforms": { "value": "alphanumeric_only" } },
      { "kind": "condition", "key": "date", "operand": "eq", "value": "date",
        "tolerance_amount": 3, "tolerance_unit": "day" }
    ]
  }
}
```

An `eq` condition can carry a tolerance in `dollar`, `percent`, `day` or `month`, which loosens that comparison. A condition with a tolerance doesn't count toward the two exact conditions. Transforms normalize a field before it's compared: `lowercase`, `uppercase`, `alphanumeric_only`, `digits_only`, or `first_n_chars`.

### Many-to-one rules

A many-to-one rule, also called a rollup rule, groups records on one side and matches each group's total to a single record on the other side.

| Setting | What it does |
| - | - |
| `group_by` | The fields to group by. The first is the main axis. |
| `rollup.group_by_kind` | `date` (the default) groups records by day and looks for a date window whose running total matches. `identifier` groups records that share an exact value, such as a batch ID in metadata. |
| `rollup.side` | Which side is grouped. `a` (the default) sums Side A records against one Side B record. `b` sums Side B records against one Side A record, for example several bank payments that settle one invoice. |
| `rollup.lookback_days` and `rollup.date_field` | An optional time window for the grouped records. Set both or neither. |
| `rollup.tolerance` | How far, in cents, a group's total may be from the other record and still match. |
| `rollup.net` | `false` (the default) adds amounts without their direction. `true` sums credits minus debits and compares the signed total to the other record's signed amount, for example sales less refunds against a net payout. |

When `rollup.tolerance` is set and a group matches within it, End Close books the difference as an [adjustment](https://endclose.com/docs/concepts/reconciliations.md#adjustments) on the reconciliation's own adjustments stream, so the match still nets to zero. It only makes that match when there's exactly one candidate group within the variance and that group has exactly one candidate record.

A many-to-one rule's `filters` accept only AND-combined `eq` conditions without tolerances. Each one keeps groups with the matching record that shares the value, for example `metadata.operator eq metadata.operator`. See [Rollup rules](https://endclose.com/docs/guides/rollup-rules.md) for worked examples.

## When rules run

A continuous reconciliation checks each new record against its one-to-one rules as it arrives, and runs its rollup rules shortly after an import lands. A batch reconciliation runs every active rule, in priority order, when you start a run. See [Continuous and batch reconciliations](https://endclose.com/docs/concepts/reconciliations.md#continuous-and-batch-reconciliations).

## Matches

A match is a group of records that account for each other in one reconciliation.

| Field | Description |
| - | - |
| `id` | The match's identifier. |
| `reconciliation_id` | The reconciliation the match belongs to. |
| `reconciliation_rule_id` | The rule that made the match. Empty for a match made by hand. |
| `group_key` | For rollup matches, the key of the group that matched. |
| `record_count` | How many records the match holds. |

A match can hold many records. To list them, call `GET /records?reconciliation_match_id={id}`.

### Match records by hand

`POST /reconciliation_matches` matches any set of records, on one side or both. Every record must be unmatched in that reconciliation and belong to one of its data streams. A record matched in a different reconciliation is fine.

```bash cURL theme={"dark"}
curl -X POST https://api.endclose.com/v1/reconciliation_matches \
  -H "X-API-Key: $ENDCLOSE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "reconciliation_id": "0193a7c4-2b8d-7e10-a3f5-91c04d6e8a21",
    "record_ids": [
      "0193b2a0-1c3d-7f44-9a8e-5b6c7d8e9f01",
      "0193b2a0-1c3d-7f44-9a8e-5b6c7d8e9f02",
      "0193b2a0-1c3d-7f44-9a8e-5b6c7d8e9f03"
    ],
    "create_adjustment": true,
    "adjustment_reason": "Wire fee"
  }'
```

```json Response theme={"dark"}
{
  "id": "0193b2a4-8e21-7a90-b3c4-0d1e2f3a4b5c",
  "group_key": null,
  "reconciliation_id": "0193a7c4-2b8d-7e10-a3f5-91c04d6e8a21",
  "reconciliation_rule_id": null,
  "created_at": "2026-11-09T15:42:10Z",
  "record_count": 4
}
```

With `create_adjustment: true`, End Close adds an adjustment record when the records don't balance, which is why `record_count` is one more than the records you sent. Leave it out to match the records exactly as they are. Manual matches also give the [reconciliation agent](https://endclose.com/docs/concepts/reconciliations.md#the-reconciliation-agent) a new example to learn rules from.

### Undo a match

`DELETE /reconciliation_matches/{id}` removes the match. Its records go back to unmatched in that reconciliation and are open to rules and people again.

## Related

> [card] [Matching rules](https://endclose.com/docs/guides/matching-rules.md)
>
> Write and test one-to-one rules.

> [card] [Rollup rules](https://endclose.com/docs/guides/rollup-rules.md)
>
> Match batches and payouts with many-to-one rules.

> [card] [Reconciliations](https://endclose.com/docs/concepts/reconciliations.md)
>
> Sides, runs and adjustments.

> [card] [API reference](https://endclose.com/docs/api-reference/overview.md)
>
> Rule and match endpoints.


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