Books

Categorize or split transactions

Changed on

Sets the categorization of one or more posted bank transactions, all or nothing. Each item names a transaction by its journalEntryId and gives its new categorization as splits: one split per category, each with the ledgerId of the ledger, i.e. general ledger (GL) account, to categorize to (such as an expense or revenue account) and the signed amount of the transaction that goes to it, as a JSON number of dollars with at most two decimal places. One split categorizes the whole transaction to one ledger; several split it across ledgers. Splits use the same sign convention as the transaction's amount from GET /books/transactions (getBooksTransactions), must be nonzero, and must add up to exactly that amount; a split with the opposite sign, such as a refund netted against a purchase, posts on the other side. A split may set the line's description and tagIds; omit them to keep those of the line it replaces. The splits replace every current categorization line of the transaction; its bank line on the source account's ledger is never changed. The last write wins: if the transaction was recategorized after you read it, this request overwrites that change. A split's ledger must belong to the Books instance and be editable, and must not be an uncategorized income or expense ledger or a source account's ledger. Only journal entries of bank transactions can be categorized, and a transaction matched to a transfer between accounts must be unmatched first. Send from 1 to 100 items, each transaction at most once; across all items, the splits may name at most 100 different ledgers. If a journalEntryId, split ledgerId, or tag ID doesn't exist, the whole request fails with 404, and if one belongs to another Books instance, or a split's ledger is read-only (linked to a Mercury account), with 403; no transaction is changed. A few problems fail the whole request with 422 and a message saying why, such as two tags from the same tag group on one split; no transaction is changed. Every item is checked before anything changes: if any item is invalid, no transaction is changed, and the 400 response's errors.errorCode is invalidCategorizationItems with errors.itemErrors listing every problem, each with its 0-based itemIndex into items, a code, and a message. The codes are duplicateJournalEntry, journalEntryNotFound (the journal entry was deleted while the request ran), notTransactionSourced, transferMatched, splitsDoNotSumToTransactionAmount, invalidSplitAmount, ledgerNotFound (the ledger was deleted while the request ran), ledgerNotEditable, ineligibleLedger (a split's ledger can't take a transaction's categorization, such as the opening balances ledger or an accounts receivable or payable ledger), uncategorizedLedger, sourceAccountLedger, and unknownError (any other problem, described by its message); more may be added, so treat an unrecognized code as unknownError and show its message. On success, every transaction has the requested categorization, and the response lists each one's new categorizationLines, in request order. A 500 response doesn't mean nothing changed: Books may have applied the items, so read the transactions again before retrying. To find transactions and their current categorization, use GET /books/transactions (getBooksTransactions); to find ledger IDs, use GET /books/ledgers (getBooksLedgers).

post/books/transactions/categorize

Request

Query parameters

booksIdstring uuid

The Books instance to act on. Must be the token organization's own instance, which it defaults to.

Request body

Example request

{
  "items": [
    {
      "journalEntryId": "7JRNsKwy2Lw66caxVU7WGC",
      "splits": [
        {
          "ledgerId": "7JRNsKwy2Lw66caxVU7WGC",
          "tagIds": [
            "7JRNsKwy2Lw66caxVU7WGC"
          ]
        }
      ]
    }
  ]
}

Response

Example response

{
  "items": [
    {
      "categorizationLines": [
        {
          "ledgerId": "7JRNsKwy2Lw66caxVU7WGC",
          "lineEntryId": "7JRNsKwy2Lw66caxVU7WGC"
        }
      ],
      "journalEntryId": "7JRNsKwy2Lw66caxVU7WGC"
    }
  ]
}

Changes