Transactions

A transaction is one business fact — a date, a narration, and a set of entries. It carries no amount of its own. The money lives entirely in its entries, whose debits equal their credits.

Amounts are integers in minor units. 150000 means ₹1,500.00. Decimals are refused, not rounded.

The model in one line

A transaction is a dated fact. Its entries are how it lands on accounts. The entries' debits equal their credits.


POST /api/v1/transactions

Create a transaction and its entries in one atomic call. Either the whole thing is written or nothing is — a rejected call leaves no partial rows behind, so retrying after a validation error is safe.

Request

{
  "date": "2026-08-05",
  "narration": "Rent paid — Aug 2026",
  "type": "vendor_paid",
  "status": "posted",
  "source": "sap",
  "source_ref": "4900001234",
  "entries": [
    { "account": "a1b2c3d4e5f6", "debit": 3000000, "credit": 0, "dimensions": { "cost_centre": "Mumbai" } },
    { "account": "a1b2c3d4e5f6", "debit": 2000000, "credit": 0, "dimensions": { "cost_centre": "Delhi" } },
    { "account": "f6e5d4c3b2a1", "debit": 0, "credit": 5000000 }
  ]
}
FieldRequiredNotes
dateyesYYYY-MM-DD. The accounting date, not when it was keyed in
entriesyes for postedArray; see below
timenoHH:MM or HH:MM:SS, wall-clock as the source printed it
narrationnoWhat happened, in words
typenoBusiness event, free text — vendor_paid, sales_recorded
statusnoposted (default) or draft
currencynoDefaults to INR
sourcenomanual (default), or the upstream system's name
source_refnoThe upstream document number
detailsnoThe upstream event as it arrived, any shape

Each entry takes one of account (this ledger’s id) or account_ref (the account’s source_ref, resolved against this org’s chart), one of debit or credit, and optionally memo and dimensions. See naming an account by its upstream reference.

What is enforced

  1. Debits equal credits for anything reaching posted
  2. At least two entries on a posted transaction
  3. No entry against a group account — post to its children
  4. Every account exists in this organization and is postable

Drafts are exempt from 1 and 2: a draft is work in progress, and refusing to save a half-built one would leave nowhere to put it.

Idempotency

When source and source_ref are both given, they are the transaction's identity. Re-posting one already sent returns the existing transaction with created: false rather than creating a second copy:

{ "data": { "id": "...", "created": false, "...": "..." } }

This is what makes an interrupted sync safe to re-run — for a shadow ledger the normal case, not an edge one.

A re-post does not update the existing transaction. A posted transaction is immutable; correcting one means voiding it and posting a replacement.

Response

201 with created: true, or 200 with created: false. The body carries the transaction, its entries, and total_debit / total_credit.


POST /api/v1/transactions/bulk

Create many transactions in one request. Up to 500 per batch.

A month of upstream output is tens of thousands of transactions, and one POST each is the shape that makes a loader take an hour. This takes an array and reports on each item separately.

Request

{
  "transactions": [
    {
      "date": "2026-08-05",
      "narration": "Warranty provision — Aug 2026",
      "source": "sap",
      "source_ref": "4900001234",
      "entries": [
        { "account_ref": "400100", "debit": 5000000 },
        { "account_ref": "213400", "credit": 5000000 }
      ]
    },
    { "...": "..." }
  ],
  "dry_run": false
}

Each item is shaped exactly as the body of POST /api/v1/transactions. An envelope rather than a bare array, because dry_run has to live somewhere and because every other body in this API is an object.

FieldRequiredNotes
transactionsyes1 to 500 transaction objects
dry_runnotrue validates and reports; nothing is written

Naming an account by its upstream reference

An entry takes account (this ledger's id) or account_ref (the account's source_ref), never both. A file produced from SAP or a billing register knows accounts by their own code and never by an id this ledger generated, so without account_ref every caller has to download the chart and join it first. The join belongs on this side.

Add account_source when two systems' charts both use the code. source_ref is unique per (org, source), not per org, so a ref matching accounts from two sources is refused with ACCOUNT_REF_AMBIGUOUS (422) listing the candidates — picking one would post real money to an account nobody named.

account_ref works on POST /api/v1/transactions and on draft entry edits too.

Response

200 with a result per item, in input order, whenever the batch was accepted — even if every item in it failed:

{
  "data": {
    "results": [
      { "index": 0, "source": "sap", "source_ref": "4900001234", "result": "created",  "id": "a1b2c3d4e5f6", "created": true,  "status": "posted", "entry_count": 2 },
      { "index": 1, "source": "sap", "source_ref": "4900001235", "result": "existing", "id": "f6e5d4c3b2a1", "created": false },
      { "index": 2, "source": "sap", "source_ref": "4900001236", "result": "failed",   "id": null, "created": false,
        "error": { "code": "UNBALANCED", "message": "…", "details": { "difference": 50000 } } }
    ],
    "summary": { "total": 3, "created": 1, "existing": 1, "failed": 1, "valid": 0 },
    "dry_run": false,
    "max_batch_size": 500
  }
}
resultMeaning
createdWritten. id is the new transaction
existing(source, source_ref) was already imported. Nothing was written; id is the one that was already there
validDry run only: it would have been created
failedRefused. error carries the ledger's code, message and figures

A result carries identities, not transactions. A caller loading 20,000 rows does not want them echoed back; GET /api/v1/transactions/:id has the rest.

Partial success is a result, not an error. A status other than 200 means nothing in the batch was attempted: bad credentials (401), a body that is not { transactions: [...] } (400), or more than 500 items (BATCH_TOO_LARGE, 413).

What is guaranteed

  • Each transaction is atomic in itself. Its entries post or fail together, in one database transaction. Atomicity is per transaction, not per batch — a batch that fails halfway leaves what it already wrote written.
  • Idempotency is unchanged. (source, source_ref) dedupes against the ledger and within the batch: the same reference twice in one request creates one transaction, and the second result carries duplicate_of_index. This is what makes re-sending the whole file the recovery procedure after a partial run.
  • Items are processed in order, one at a time. The connection pool is shared with every other request, so the batch does not fan out inside the server. Parallelism belongs to the client, which can keep several batches in flight.

One activity-feed row records the batch and its counts, rather than one row per transaction.

Loading a file

fob-lgr transactions push --file txns.ndjson does all of this — chunking, requests in flight, progress, and a re-pushable file of the rows that failed. Reach for the endpoint directly only when the CLI is not where the data is.


GET /api/v1/transactions

ParamNotes
date_from, date_toInclusive, YYYY-MM-DD
statusdraft, posted or void
typeExact match on the business event
source, source_refUpstream identity; together they resolve one row
accountOnly transactions with an entry against this account
dimension.<key>e.g. dimension.cost_centre=Mumbai
qSubstring match on narration
include_entriesfalse omits entries; they are included by default
sort_orderASC or DESC on date, default DESC
page, limitDefault 100 per page, max 500

Entries come back with each transaction by default, along with total_debit and total_credit, so a list is usable without a follow-up call per row.

Results are ordered date, time NULLS LAST, created_at, id — deterministic whether or not a source supplied a time.

# Everything hitting one account in Q1, with its entries
curl "https://ledger.finopsbricks.com/api/v1/transactions?account=a1b2c3d4e5f6&date_from=2026-01-01&date_to=2026-03-31" \
  -H "api-key: $KEY" -H "api-secret: $SECRET"

GET /api/v1/transactions/:id

One transaction with its entries and totals.


PATCH /api/v1/transactions/:id

Two different operations, one at a time.

Changing status

{ "status": "posted" }

The lifecycle:

draft ──post──> posted ──void──> void
  └───void───────────────────────┘

posted is the point of no return. The balance check bites on the way there. After it, a mistake is corrected by voiding and posting a replacement — which is what keeps a shadow ledger reconcilable against the system it mirrors.

Editing content

Drafts only. Send any of date, time, narration, type, currency, details, entries.

entries is replaced wholesale, not merged. Sending three entries leaves the transaction with exactly those three. Patching individual lines would let a caller leave a transaction half-edited with only the eventual balance check noticing.

Editing a posted transaction returns TRANSACTION_IMMUTABLE (409), with one exception below.

Changing the type of a posted transaction

type sent on its own is accepted in any status:

{ "type": "vendor_paid" }

type names the business event and moves no balance, so reclassifying it (an importer that learnt better types, say) needs no void and replacement. Sending type together with any other content field on a posted transaction is still refused. The change is logged in the activity feed with the old and new type.


DELETE /api/v1/transactions/:id

A draft can always be deleted. A posted or void transaction is voided instead, unless the org has Allow hard delete on (Settings → General, org admins only). While it is on, any transaction can be deleted: its entries go with it and its (source, source_ref) is freed, so re-sending the document creates it afresh.

Hard delete is for clearing an import that turned out wrong before re-importing it. The ledger is a mirror, so the upstream export can rebuild what was deleted. For day-to-day corrections, void and post a replacement.

While hard delete is off, deleting a posted or void transaction returns TRANSACTION_IMMUTABLE (409) with details.allow_hard_delete: false.


DELETE /api/v1/transactions

Bulk hard delete: every transaction from one source, optionally in a date range. Only while the org has Allow hard delete on.

ParamRequiredNotes
sourceyese.g. tally. Required so an empty filter can't wipe the org
date_from, date_tonoInclusive, YYYY-MM-DD
dry_runnotrue returns the count without deleting
{ "data": { "matched": 3420, "deleted": 3420, "dry_run": false } }

It can't be undone: run it with dry_run=true first. One activity entry records the filter and the count. While hard delete is off it returns TRANSACTION_IMMUTABLE (409); without source it returns VALIDATION_ERROR (400).


Dimensions

Dimensions sit on the entry, not the transaction. The rent example above is why: one payment split across two branches has expense lines under different cost centres and a bank line under none. That shape cannot be expressed a level up.

Keys are yours to choose. Filter with dimension.<key>=<value> on either this endpoint or entries.