Skip to content
FRAGMENT
H Reconcile transactions#

Your Ledger should track transactions made by your product. To do this, you need to represent every account you hold at external financial systems in your Ledger.

This section covers the second of two steps to record transactions in your Ledger:

  1. Sync transactions from external financial systems into FRAGMENT using Links.
  2. Once synced, you can record them in your Ledger using reconcileTx.

a. Linked Ledger Accounts

#

To represent external accounts in your Ledger, create a Ledger Account and link it to an External Account.

Any Ledger Line that posts to a linked Ledger Account must match a synced transaction in its corresponding External Account.

To link a Ledger Account to an External Account, set linkedAccount on a Ledger Account in your Schema:

Linked Ledger Account with hardcoded IDs
{
  "chartOfAccounts": {
    "accounts": [
      {
        "key": "assets-root",
        "name": "Assets",
        "type": "asset",
        "children": [{
          "key": "operating",
          "name": "Operating Bank",
          "linkedAccount": {
            "linkId": "some-link-id",
            "externalId": "bank-account-1"
          }
        }]
      }
    ]
  }
}

The linkId comes from the Link you create in the dashboard. The externalId is the ID of the account at your external financial system.

The CLI automatically replaces variables with ${ENV_VAR} syntax when running fragment store-schema. This lets you use different External Accounts per environment:

Linked Ledger Account with env var IDs
{
  "chartOfAccounts": {
    "accounts": [
      {
        "key": "assets-root",
        "name": "Assets",
        "type": "asset",
        "children": [{
          "key": "operating",
          "name": "Operating Bank",
          "linkedAccount": {
            "linkId": "${BANK_LINK_ID}",
            "externalId": "${BANK_ACCOUNT_ID}"
          }
        }]
      }
    ]
  }
}

To link a Ledger Account template to an External Account, parameterize the linkedAccount field:

Linked Ledger Account with parameter IDs
{
  "chartOfAccounts": {
    "accounts": [
      {
        "key": "assets-root",
        "name": "Assets",
        "type": "asset",
        "children": [{
          "key": "operating",
          "name": "Operating Bank",
          "template": true,
          "linkedAccount": {
            "linkId": "{{BANK_LINK_ID}}",
            "externalId": "{{BANK_ACCOUNT_ID}}"
          }
        }]
      }
    ]
  }
}

These parameters will be required when posting a Ledger Entry to a linked Ledger Account. This can be useful if you're creating bank accounts per customer, for example.

b. Reconcile a Tx

#

To reconcile a transaction from an external system, follow the same two-step process as when posting Ledger Entries:

  1. Define the structure of the Ledger Entry in your Schema.
  2. Post the Ledger Entry using the API.

Ledger Entries posting to a linked Ledger Account must specify the Tx from the External Account tied to the Ledger Account. This lets FRAGMENT know which transaction to reconcile:

LedgerEntrySchema with Linked Ledger Account
{
  "key": "schema-key",
  "chartOfAccounts": {...},
  "ledgerEntries": {
    "types": [
      {
        "type": "user_funds_account_via_link",
        "description": "Funding {{user_id}} for {{funding_amount}}",
        "lines": [
          {
            "account": { "path": "assets/operating" },
            "key": "funds_arrive_in_bank",
            "tx": {
              "externalId": "{{bank_transaction_id}}"
            }
          },
          {
            "account": { "path": "liabilities/users:{{user_id}}/available" },
            "key": "increase_user_balance"
          }
        ]
      }
    ]
  }
}

Notes:

  • Ledger Lines posting to a linked Ledger Account must match 1:1 with the Tx that's being reconciled.
  • bank_transaction_id represents the ID of the transaction at the external system.

Instead of calling addLedgerEntry, use the reconcileTx mutation:

reconcileTx mutation
mutation ReconcileTx(
  $entry: LedgerEntryInput!
) {
  reconcileTx(
    entry: $entry
  ) {
    ... on ReconcileTxResult {
      entry {
        type
        created
        posted
      }
      lines {
        amount
        key
        description
        account {
          path
        }
      }
    }
    ... on Error {
      code
      message
    }
  }
}

The parameters look similar to addLedgerEntry. Specify the Ledger Entry type that you are using and provide the parameters defined in the Schema:

reconcileTx variables
{
  "entry": {
    "type": "user_funding",
    "ledger": {
      "ik": "quickstart-ledger"
    },
    "parameters": {
      "txId": "tx_12345",
      "customerId": "customer-1"
    }
  }
}

ik and posted are optional when posting Ledger Entries with reconcileTx:

  • ik: the Tx.externalId is used to ensure that reconciling a transaction is idempotent
  • posted: the timestamp of the Ledger Entry is taken from the Tx to ensure the Ledger mirrors the external system

c. Reconciling multiple Txs

#

Book transfers are a common type of money movement which produce two Txs at your bank as part of one transaction.

To reconcile multiple Txs using reconcileTx:

LedgerEntrySchema with multiple Txs
{
  "key": "schema-key",
  "chartOfAccounts": {...},
  "ledgerEntries": {
    "types": [
      {
        "type": "user_funds_account_via_link",
        "description": "Funding {{user_id}} for {{funding_amount}}",
        "lines": [
          {
            "key": "funds_arrive_in_operating_bank",
            "account": { "path": "assets/operating-bank-account" },
            "tx": {
              "externalId": "{{bank_transaction_id}}"
            }
          },
          {
            "key": "funds_leave_holding_bank",
            "account": { "path": "assets/holding-bank-account" },
            "tx": {
              "externalId": "{{bank_transaction_id}}"
            }
          }
        ]
      }
    ]
  }
}

Notes:

  • Reconciling multiple Txs is only permitted if they have the same posted timestamp.
  • You can only reconcile multiple Txs within the same Link.

d. Unreconciled Txs

#

Transactions synced to FRAGMENT but not reconciled to a Ledger are considered unreconciled.

You can query unreconciled transactions in a linked Ledger Account using the unreconciledTxs field on theLedgerAccount.

unreconciledTxs query
query GetUnreconciledTxs (
  $ledgerAccount: LedgerAccountMatchInput!
) {
  ledgerAccount(ledgerAccount: $ledgerAccount) {
    id
    unreconciledTxs {
      nodes {
        id
        description
        amount
        externalId
        externalAccountId
      }
      pageInfo {
        endCursor
        hasNextPage
      }
    }
  }
}

The variables specify the path of the linked Ledger Account you are querying and the Ledger it belongs to.

unreconciledTxs variables
{
  "ledgerAccount": {
    "path": "assets/operating",
    "ledger": {...}
  }
}

unreconciledTxs is eventually consistent, so if you've recently transacted at a Native Link or just synced manually for a Custom Link, you may not see the transaction in the query results immediately.

e. Clearing accounts

#

Clearing accounts track temporary balances that go to zero when a workflow completes. Set clearing: true on a Ledger Account in your Schema. This setting is immutable once the Ledger is deployed. For example, add this account to chartOfAccounts.accounts:

Clearing account template
{
  "key": "receivables",
  "type": "asset",
  "template": true,
  "clearing": true
}

Use template: true to create a separate clearing account for each workflow. Supply a workflow or transaction ID in the account path when posting an entry:

Clearing account path on a Ledger Line
{
  "account": {
    "path": "receivables:{{workflow_id}}"
  },
  "amount": "{{amount}}"
}
Status#

The clearingStatus field on LedgerAccount indicates whether the account has an outstanding balance:

  • pending: At least one currency has a non-zero balance.
  • cleared: All currencies have a zero balance.
  • null: The account is not configured as a clearing account.

Use the clearingStatus filter to list accounts with either status. Status reads and filters are eventually consistent, even when balances are strongly consistent:

Read clearing status
query GetClearingAccount($ledgerAccount: LedgerAccountMatchInput!) {
  ledgerAccount(ledgerAccount: $ledgerAccount) {
    path
    clearingStatus
    postedWindow {
      earliest
      latest
    }
  }
}
Posted window#

The postedWindow field describes the range of Ledger Line posted timestamps across all currencies in the account:

  • earliest: The earliest posted timestamp.
  • latest: The latest posted timestamp.

postedWindow is null for accounts without entries and accounts not configured for clearing. Reads and filters on these timestamps are eventually consistent. Combine clearingStatus with timestamp filters to find accounts that need investigation:

  • earliestPosted filters by the earliest posting time.
  • latestPosted filters by the latest posting time, such as accounts with no recent activity.
  • Both timestamp filters require a clearingStatus filter in the same query.

f. Get a reconciliation report

#

Use ledger.reconciliationReport to count pending clearing accounts and unreconciled transactions by age. Counts are eventually consistent. Age is measured from the time of the request, returned as the report's endTime. Configure the report with:

  • granularity: Use hourly, daily, or monthly. Monthly intervals use calendar months.
  • intervals: Request 1–7 intervals, including the open-ended oldest interval.
  • clearingAccounts: Pass {} for all pending accounts, or restrict them with filter.path.
  • unreconciledTxs: Provide links and optionally restrict transactions with filter.posted. Requires link.read.

This query requests both counts. Transactions are counted when they have not been reconciled to any account in this Ledger. A transaction reconciled to a different Ledger can therefore still count as unreconciled in this report. The selected Links can include External Accounts that are not linked to this Ledger:

Get a reconciliation report
query GetReconciliationReport($ledger: LedgerMatchInput!, $links: [LinkMatchInput!]!) {
  ledger(ledger: $ledger) {
    reconciliationReport(
      granularity: daily
      intervals: 3
      clearingAccounts: {}
      unreconciledTxs: { links: $links }
    ) {
      endTime
      intervals {
        startTime
        endTime
        clearingAccountCount
        unreconciledTxCount
      }
    }
  }
}

Choose the Ledger and Links to include. Provide 1–100 Link selectors, using a FRAGMENT ID or a Custom Link's creation IK:

Reconciliation report variables
{
  "ledger": { "ik": "quickstart-ledger" },
  "links": [{ "id": "some-link-id" }]
}

Intervals are returned youngest first. With daily and intervals: 3, the age ranges are:

  1. Up to 24 hours.
  2. More than 24 hours, up to 48 hours.
  3. More than 48 hours. startTime is null.

Omit either input to skip that count; the corresponding count field returns null. Clearing accounts are counted once per interval. Different pending currencies can place the same account in multiple intervals. To count only clearing accounts for a specific workflow, use a path filter:

Report on receivables
query GetReceivablesReport($ledger: LedgerMatchInput!) {
  ledger(ledger: $ledger) {
    reconciliationReport(
      granularity: daily
      intervals: 3
      clearingAccounts: { filter: { path: { matches: "receivables:*" } } }
    ) {
      intervals {
        startTime
        endTime
        clearingAccountCount
      }
    }
  }
}
Retrieve records in an interval#

Use an interval's startTime and endTime directly as inclusive bounds in the corresponding list query. Omit after when startTime is null:

  • Pending clearing accounts: query ledger.ledgerAccounts. Filter by clearingStatus: { equalTo: pending } and earliestPosted: { after: startTime, before: endTime }.
  • Unreconciled transactions: query ledger.unreconciledTxs with posted: { after: startTime, before: endTime }.

Preserve the report's scope when retrieving records:

  • Reuse clearingAccounts.filter.path as filter.path in the clearing-status query, if provided.
  • Pass the same links to ledger.unreconciledTxs.
  • Intersect any original unreconciledTxs.filter.posted bounds with the interval bounds.
  • Use pagination to retrieve every record.