Skip to content

Accounting

The accounting part of the API reads accounting dictionaries and the chart of accounts, writes accounting documents, cash and bank transactions and settlements, and gives lists of changes for synchronization. Shared methods and fields have the same names for every ERP. Today only the Comarch Optima integration has the accounting scopes. ERPNext and Fakturownia do not have them, so the methods on this page do not support them.

The page has two parts. The first describes what is shared by every ERP. The second, Comarch Optima, collects the rules that come from Optima: what the VAT register accepts, what posting needs, how cash and bank behave.

The table in the guide gives the key’s scope for every method. Refusal reasons (422) are described on the Errors and limits page, and the parameters and responses of every method in the reference.

accounting.profile says how the company keeps its books. bookkeeping is doubleEntry (a full ledger), kpir or ryczalt, and null when the company has not chosen its type of bookkeeping. baseCurrency is the company’s currency and country its country. ledgerLicensed says whether the integration can write to the ERP’s general ledger: create accounts, write a proposed journal entry and post a document.

The chart of accounts, journals, journal entries and ledger settlements on the accounts need bookkeeping: "doubleEntry", otherwise 422 notDoubleEntry. Creating accounts, a proposed journal entry and accountingDocuments.post also need ledgerLicensed: true, otherwise 422 ledgerNotLicensed. Accounting documents without a proposed journal entry, and cash and bank, work with every type of bookkeeping.

Dictionaries are the codes you assign accounting documents and journal entries to.

  • fiscalYears.list, journals.list, vatRegisters.list, cashAccounts.list, paymentMethods.list and accountingCategories.list return the whole dictionary on one page, without nextCursor. Inactive VAT registers, cash and bank registers, payment methods and categories are on the list too, with active: false. A fiscal year has status (open or closed) and current instead. You choose integrations with the filters.integrationId filter, and those that did not respond are in failedIntegrationIds.
  • ledgerAccounts.list reads the chart of accounts of one company in one fiscal year. It requires integrationId and fiscalYearId (from fiscalYears.list) and has no failedIntegrationIds. A fiscal year the company does not have gives 404. You read further pages with a cursor, as on other lists.
  • The filter { "number": { "$regex": "^402-" } } returns the analytic accounts of account 402. { "isPostable": { "$eq": true } } keeps the accounts you can post to.

You create accounts with two methods. Both answer { "result": …, "warnings": [] }, where result is the last-level account or the counterparty’s account, in the shape of the ledgerAccounts.get response.

  • ledgerAccounts.create creates analytic accounts under an existing account, level by level. A level that already exists stays unchanged, its name included. A retry writes nothing more.
  • ledgerAccounts.ensureSubledgerAccount returns a counterparty’s settlement account under an account with the counterparty dictionary, and creates it if it is missing. The API does not create accounts of other dictionaries.

An accounting document (accountingDocument) is an approved purchase (kind: "purchase") or sales (kind: "sales") document entered in the ERP’s books. You read it with accountingDocuments.get and accountingDocuments.list.

  • number is the number the ERP assigned, and documentNumber is the number from the document, for example from the invoice.
  • origin says where the document comes from: invoice (from an invoice in the ERP, which invoiceId names for invoices.get), eInvoice (imported from an e-invoicing system), imported (imported from another application), manual (typed in the ERP) or other. In the other direction, an invoice from invoices.list and invoices.get names its accounting document in accountingDocumentId. It is null when the invoice has no accounting document, and always in ERPNext and Fakturownia. invoices.get can show the state from up to 5 minutes ago.
  • importSource is the import mark the ERP keeps on the document: the application (appId) and the document’s key in that application (rowId). A document typed in the ERP has null.
  • status is the document’s state in the books: draft, approved, posted, reversed or voided. Which of them occur depends on the ERP. journalEntry shows the document’s journal entry. The proposed journal entry that post books by is a field of the ERP’s variant, in Optima proposedJournalEntry.
  • totals gives the amounts in the document’s currency (currency), and totalsBase in the company’s currency. exchangeRate is the document’s exchange rate. For a document in the company’s currency it is null.
  • A line in lines has net (net) and tax (tax) in the document’s currency, a rate (taxRate.percent) and a tax category (taxRate.category): standardRated, zeroRated, exempt, reverseCharge, intraCommunity, export, outOfScope or other. A purchase line has deductible (full, none or partial), and on sales it is null.
  • eInvoice has the document’s number in the e-invoicing system as { "system": …, "number": "…" }, where system is ksef, sdi, peppol or other, or the field is null.
  • taxReporting holds the tax marks of the country in the country field. Today there is only the Polish block, with the marks for JPK_V7.
  • filters.modifiedAt with $gt returns the documents changed since your last read. Id filters, for example filters.counterPartyId, take the id in that integration’s format. Any other value, and an empty list in $in, give 400.

Writing has four methods. create, update and post answer { "result": …, "warnings": [] }, where result has the shape of the accountingDocuments.get response.

  • accountingDocuments.create enters the document. values is the whole document. null in operationDate, taxPointDate and paymentMethodId leaves the value to the ERP, and in currency it means the company’s currency. The API does not skip what the ERP will not accept: the answer is 422 notSupported with the field’s path.
  • accountingDocuments.update replaces the whole document and requires expectedModifiedAt equal to modifiedAt from your read. When someone changed the document after your read, the API answers 409 and writes nothing.
  • accountingDocuments.delete deletes the document.
  • accountingDocuments.post posts the document by its proposed journal entry.
  • You can update, delete and post any document, including one typed by the accountant. Updating or deleting a posted document (also in the buffer) gives 422 documentPosted, one exported to an accounting office 422 documentExported (unless the connector’s operator may change exported documents), and one in the month of an approved VAT declaration 422 taxPeriodClosed. A settled payment does not stop a change, as in Optima: after a new amount the settlement stays, and deleting the document removes the payment with its settlements and leaves the cash transaction unsettled.

The create of an accounting write (an accounting document, a cash or bank transaction, a settlement) and of a counterparty accepts importSource. The field is required but may be null: then the document looks as if it was typed in the ERP.

  • importSource is { "appId": …, "rowId": … }: your application (1 to 5 characters) and the document’s key in it (1 to 36 characters), both from A-Z, a-z, 0-9, ., _, : and -. The ERP stores them as the document’s import mark and returns them on a read as importSource.
  • The ERP keeps each rowId once, regardless of appId and letter case. The ERP refuses a create with a rowId it already has (422 duplicateDocument) and writes nothing.
  • The API retries nothing for you. After a dropped connection (including a 502 or 504 from a server in front of the API) or a 500 response, check whether the document was created before you send create again. You find an accounting document, a cash or bank transaction, a settlement and a counterparty on its list with the importAppId and importRowId filters together. Without importSource, look the document up by other fields, for example by the number and the counterparty.
  • An accounting document, a cash or bank transaction and a settlement that do not start within a minute get 503 and are not written. Send them again then.

An asset takes importSource too. The guide describes it under Assets.

cashFlowItems.list returns payments: what an invoice, an accounting document or a journal entry is due to pay or receive. Each payment has settlementStatus (unsettled, partiallySettled, settled, or notApplicable when it is not subject to settlement), settledAmount and remainingAmount in its own currency. You find the payments of one document with the invoiceId, accountingDocumentId or journalEntryId filter.

Cash and bank registers are in the cashAccounts.list dictionary. cashStatements.list returns cash reports and bank statements, and cashTransactions.list and cashTransactions.get the transactions in them. A report and a transaction have a status from the same list as an accounting document. settlements.list returns settlements, and ledgerSettlementItems.list the ledger settlements on the general ledger’s accounts.

Id filters on these lists (id, cashAccountId, counterPartyId and the other …Id) take the id in that integration’s format, as on accounting documents. Any other value gives 400. In settlements.list, cashFlowItemId and cashTransactionId match either side of the settlement, and $ne, $nin and $exists: false keep a settlement only when neither side matches.

cashTransactions.create adds one bank statement line or one cash slip to a register (cashAccountId from cashAccounts.list) and at once settles the payments in settlements against it. Either everything is written or nothing. The answer is { "result": …, "warnings": […] }, where result has the shape of the cashTransactions.get response.

settlements.create settles an amount of two documents, given in sides: a transaction with a payment, a payment with its correction, or two transactions. The amount can be a part of each of them. Both documents must be in the same currency (settlementCurrencyMismatch). The answer is { "result": …, "warnings": […] }, where result has the shape of an item from settlements.list.

  • warnings says what the ERP did not do in the general ledger beside a write that succeeded. The write stays.
  • settlements.delete deletes a settlement.
  • cashTransactions.delete deletes a transaction. It requires expectedModifiedAt equal to modifiedAt from your read, otherwise 409. You cannot correct a transaction. Delete it and create a new one.

cashFlowItems.changes, cashTransactions.changes and accountingDocuments.changes return the documents of one integration changed after cursor, oldest change first. The first call sends cursor: null. The answer always has a cursor for the next call, even when items is empty, so store it every time.

  • The same document can come more than once. Treat later versions as an overwrite.
  • The list of changes runs behind the ERP’s clock, so a change does not show up at once.
  • A settlement changes both sides, so cashFlowItems.changes shows the payment’s new settled amount.
  • A deleted document leaves no trace. To check a document that the list of changes no longer returns, use a list or get (404).
  • A cursor from another list gives 400.

Everything below applies only to the Comarch Optima integration. The page Optima accounting in the API shows which Optima object stands behind each name in the API and which tables the integration reads.

Type of bookkeeping and the Księga Handlowa module

Section titled “Type of bookkeeping and the Księga Handlowa module”

A company that does not keep a full ledger (KPiR or ryczałt) has empty lists of fiscal years and journals. For such a company ledgerAccounts.list and ledgerAccounts.get answer 422 with the reason notDoubleEntry. You can check the company’s type of bookkeeping beforehand with accounting.profile: a full ledger is bookkeeping: "doubleEntry", and ledgerLicensed says whether the connector’s login holds the Księga Handlowa module. Reading the chart of accounts does not need this module, only double-entry books. Creating accounts, writing proposed journal entries and accountingDocuments.post need it.

  • An account’s id is different in every fiscal year, because Optima copies the chart of accounts into the new year. Match accounts by number.
  • An account you can post to (isPostable) is at the lowest level, active, and not a dictionary account without analytic accounts.
  • A VAT register’s code is its name. Optima stores the register on the VAT entry under this name.

You create accounts with the ledgerAccount:create scope. The connector’s login must hold the Księga Handlowa module (ledgerLicensed: true in accounting.profile), otherwise the answer is 422 with the reason ledgerNotLicensed, even when all the accounts already exist.

  • ledgerAccounts.create: parentNumber: "402" with the levels 01 and 05 ends at account 402-01-05. Each level has a segment (up to 20 characters, no -) and a name (up to 50 characters). The full number can have at most 50 characters.
  • The API does not create a synthetic account. A parentNumber missing from the chart of accounts gives 422 invalidReference with path: "parentNumber". An account with a dictionary gives 422 subledgerParentAccount, an account with entries or an opening balance 422 ledgerAccountHasEntries, and a closed period 422 periodLocked.
  • An account exists only in the fiscal year it was created in. Optima carries it into the next year when the accountant opens a new period.
  • ledgerAccounts.ensureSubledgerAccount: parentNumber is an account with the counterparty dictionary, for example 202 or 202-1, and entry is { "kind": "counterParty", "id": 41 }, where id is the counterparty’s id from counterParties.get. Optima takes the new account’s number and name from the counterparty card, according to the company’s setting. An account without the counterparty dictionary, or with the dictionary split into groups, gives 422 notSubledgerParentAccount.
  • warnings in the answer of both methods is always empty for now.

Keep an MPK, a project or an investment as further analytic levels, for example 402-01-05: account 402, MPK 01, project 05. You create such an account with ledgerAccounts.create and then post to the full number. Optima has no field for a project or a department on a journal entry or on a VAT entry.

The proposed journal entry of a VAT register entry names an account with a ComarchOptimaLedgerAccountRef object:

  • { "kind": "number", "number": "402-01-05" } is an account that already exists, is active and has no analytic accounts;
  • { "kind": "subledger", "parentNumber": "202", "entry": { "kind": "counterParty", "id": 41 } } is the account of counterparty 41 under account 202. If it is missing, the write creates it, as ensureSubledgerAccount does.

In Optima an accounting document is a VAT register entry. accountingDocuments.create enters an approved purchase or sales document in Optima’s VAT register. result in the answer has Optima’s accounting number (number, for example 4/2026/ZAKUP). warnings is always empty for now, also in accountingDocuments.update and accountingDocuments.post.

  • values is the whole document: the type (documentType), the number from the document (documentNumber), the counterparty (counterPartyId), the dates, the payment method (paymentMethodId from paymentMethods.list) and the due date, the currency, the KSeF number (eInvoice), the JPK_V7 marks (taxReporting) and the lines per rate (lines). Optima’s fields are the register (vatRegisterId from vatRegisters.list, of the same kind as the document), the transaction kind (transactionKind), the category (categoryId, categoryDescription), the deduction date on a purchase (deductionDate) and the proposed journal entry (proposedJournalEntry).
  • A line has net (net) and VAT (tax) in the document’s currency, a rate (taxRate.percent) and a tax category (taxRate.category). Optima does not recalculate the amounts. A purchase line has deductible (full, none or partial), and a sales line includeInProRata. Optima’s fields on a line are the kind of purchase or sale (lineKind) and the category (categoryId).
  • null leaves the value to Optima. vatRegisterId takes the only active register of that kind, and when there are several or none, the answer is 422 invalidReference with path: "vatRegisterId". transactionKind and paymentMethodId take the value from the counterparty card (a card without a default payment method leaves it to Optima), operationDate is the issue date, and lineKind and includeInProRata take Optima’s default value. taxPointDate and deductionDate equal to null leave the date Optima computes.

Optima stores one transaction kind per document, and on a read it computes a line’s tax category from the rate and that transaction kind. So the category must read back unchanged: a line Optima reads as another category gives 422 notSupported with the line’s path, for example lines[1].taxRate.category. An exempt or outOfScope line has a rate and VAT equal to 0.

  • taxReporting is required, null gives 422 notSupported. The marks go to Optima as JPK_V7 codes: the document type code (WEW for internalDocument, RO for salesSummary, IMP for customsDeclaration), documentMarker, ksefMarker, gtu and procedures. A code Optima does not have gives 422 invalidReference with the path of the field it came from, for example taxReporting.gtu[0] or documentType. The VAT-7 month is taxReporting.vatDeclarationMonth. cashAccounting sets cash accounting independently of the MK code.
  • gtu and procedures are sets: a repeated code gives 400, and a read returns them ordered by code.
  • The document’s type and marker must read back unchanged. salesSummary and FP exist only on sales, and customsDeclaration, MK and VAT_RR only on purchases. FP, MK and VAT_RR do not combine with internalDocument or with salesSummary, because JPK_V7 has one field for them. Any other combination gives 422 notSupported with path: "documentType" or path: "taxReporting.documentMarker".
  • The API does not skip what Optima’s VAT register will not accept. The answer is 422 notSupported with path: documentType creditNote, debitNote and other, precedingInvoice, lines[].account (accounts go in the proposed journal entry), non-empty lines[].dimensions, eInvoice with a system other than ksef, and gtu and procedures codes on a purchase. JPK_V7 uses them to mark sales only, and Optima’s purchase register drops them on save.
  • Optima checks for duplicates, as set up in the company (duplicate control in the VAT registers). A duplicate Optima finds gives 422 duplicateDocument, and subject holds the duplicate as Optima names it.
  • A VAT-7 month covered by an approved declaration (monthly or quarterly) gives 422 taxPeriodClosed, regardless of the operator’s settings in Optima.
  • Whether the write creates a cash slip and settles the payment depends on the company’s settings in Optima. You see the entry’s payments in cashFlowItems.
  • proposedJournalEntry is the journal entry you approved, stored in Optima as the entry’s predekretacja: a journal (journalId from journals.list, from the fiscal year that contains bookingDate), a booking date and lines (lines) with a debit account, a credit account or both. The two sides must balance to the grosz. A proposed journal entry needs double-entry books and the Księga Handlowa module in the connector’s login (otherwise 422 notDoubleEntry or ledgerNotLicensed), a fiscal year that contains the day of bookingDate (noFiscalYear) and accounts you can post to (invalidReference, ledgerAccountNotPostable). In a company on KPiR or ryczałt send proposedJournalEntry: null.

On a read, origin has this meaning in Optima: invoice (carried over from an invoice of the same kind in the Handel module, an FZ in the purchase register or an FS in the sales register; invoiceId names it for invoices.get), other (carried over from the Handel module, but without an invoice of the same kind to name, for example from a receipt), eInvoice (imported from KSeF in Optima), imported (with another import mark, including an importSource given in the API) or manual (typed in Optima). An invoice’s accountingDocumentId is null until the invoice is carried over to the VAT register, or when its entry is no longer there. In Optima status has only draft and posted. status is posted when the entry’s journal entry, or its KPiR or ryczałt entry, is approved, and journalEntry shows the journal entry even while it is still in the buffer. The id in the filters.counterPartyId and filters.vatRegisterId filters is a number in Optima, which you can also send as text made of digits only, for example "41". Any other value (null, 0, empty text, a code such as "C00041", a notation such as "1e1") and an empty list in $in give 400.

  • documentType is the type of the document: invoice, creditNote or debitNote (an entry marked in Optima as a correction: a decreasing one when the gross total is negative or zero, an increasing one when it is positive), internalDocument (JPK code WEW), salesSummary (RO on sales), customsDeclaration (IMP on purchases) or other. other is the type of the technical document Optima adds to a sales invoice to settle it in JPK_V7, and of an entry whose correction field has a value other than 0 and 1. When an entry has several document type codes, the first one counts, in the order FP, RO, WEW on sales and MK, VAT_RR, WEW on purchases. When an entry fits several types at once, for example it is a correction with the WEW code or a purchase with the IMP and WEW codes, documentType shows one of them, and the codes of the others are in otherJpkCodes.
  • number is Optima’s accounting number, and documentNumber is the number from the invoice. position is the position in the register.
  • totalsBase gives the amounts in PLN. For a document in PLN exchangeRate is null.
  • receiptDate is the date a purchase was received, null on sales. recordedDate is the date of the entry in the register, and taxPointDate the tax point date.
  • taxReporting holds the marks for JPK_V7: the VAT-7 month (vatDeclarationMonth, null when the entry does not go to JPK_V7), the gtu codes, procedures, ksefMarker (OFF, BFK or DI), documentMarker (FP on sales, MK or VAT_RR on purchases), splitPayment and cashAccounting (the entry’s cash accounting, independent of the MK code). A code this block has no field for, for example MPP, is in otherJpkCodes. The JPK_V7 file Optima creates leaves out GTU codes on an internal document and procedure codes on a periodic summary (RO). The API returns them as they are stored on the entry.
  • The integration computes taxRate.category from the entry’s transaction kind (transactionKind) and the line’s rate. A combination it cannot assign unambiguously has other.
  • deductible on a purchase line says how much VAT can be deducted. On sales it is null, and includeInProRata says whether the line enters the pro rata. account and dimensions are always null, because Optima books lines through the proposed journal entry.
  • accountingDocuments.get also returns proposedJournalEntry, the entry’s predekretacja: a journal (journalId, journalCode), a booking date and lines with a debit account, a credit account or both. You write it in values.proposedJournalEntry.

Updating, deleting and posting:

  • accountingDocuments.update: Optima recalculates the payments from the new amounts, so read them again after an update. You cannot move an entry between the purchase register and the sales register (vatRegisterKindMismatch).
  • accountingDocuments.post books the entry by its proposed journal entry into the buffer of the journal it names. The accountant approves it in Optima. So after posting to the buffer, result in the answer has status: "draft" and journalEntry.status: "draft". An entry whose journal entry the accountant has already approved has status: "posted" and journalEntry.status: "posted". An entry that already has a journal entry (from the API, from the accountant or from Optima’s booking agent) answers the same way, with the entry and that journal entry in journalEntry, and writes nothing. The answer does not say whether the journal entry was created now. An entry without a proposed journal entry gives 422 noProposedJournalEntry, a booking date outside the fiscal years noFiscalYear, a closed period periodLocked, and a posting Optima did not carry out postingFailed. post needs double-entry books and the Księga Handlowa module (notDoubleEntry, ledgerNotLicensed).
  • id in update, delete and post, as in accountingDocuments.get, is a number in Optima, which you can also send as text made of digits only. Any other value gives 400.
  • You can update and delete any entry, including one typed by the accountant. Updating or deleting an entry that is posted (by a journal entry, in KPiR or in the ryczałt records, also in the buffer) gives 422 documentPosted, and one in the month of an approved declaration taxPeriodClosed. An entry exported to an accounting office gives documentExported, unless the connector’s Optima operator may change exported documents. A settled payment does not stop a change. Optima updates or refuses an entry carried over from the Handel module by its own rules.

Cash and bank also work in a company on KPiR. The exception is ledgerSettlementItems.list: a company without double-entry books has no ledger settlements, so its integration is listed in failedIntegrationIds. accounting.profile tells you this in advance.

A VAT entry carried over from a document in the Handel module (an invoice or a receipt) has no payments of its own, so the accountingDocumentId filter in cashFlowItems.list returns that document’s payments.

The status of a report (cashStatements.list) is posted only once the accountant approves its journal entry. KPiR entries do not change a report’s status, so in a company on KPiR a report always has draft. The status of a transaction is posted when the accountant approves its journal entry or its KPiR entry, as on VAT entries. A journal entry or a KPiR entry in the buffer gives draft.

cashTransactions.create:

  • The register must exist and be active (invalidReference with path: "cashAccountId") and be in PLN (notSupported with path: "cashAccountId").
  • With cashStatementId: null the transaction goes into the report that covers date. A closed report gives 422 statementClosed. A day after the last report opens a new report. A day in a gap between reports gives 422 noOpenStatement, because the accountant opens such a report.
  • documentSymbol: null takes the register’s default numbering scheme for the direction.
  • party: null takes the counterparty of the first payment being settled.
  • A settlement cannot exceed what is left to settle on the payment, and the settlements together cannot exceed the transaction’s amount (settlementExceedsRemaining).
  • Optima stores amounts to the grosz, from 0.01 to 9999999999999.99. The API writes an amount at most a millionth of a grosz away from a whole grosz (a little more for very large amounts, because a number that large cannot be stored more precisely) rounded to that grosz: 0.30000000000000004 as 0.3, and 0.010000001 as 0.01. An amount further from a whole grosz gives 422 notSupported with that amount’s path, for example amount or settlements[0].amount. An amount that rounds to zero or to more than 9999999999999.99 ends the same way. The same applies to amount in settlements.create.

In a company with double-entry books Optima also settles the ledger settlements on the accounts itself. When that fails, the write stays, and warnings has the stage ledgerSyncFailed with Optima’s message. When the company has “Automatyczne rozliczenia i rozrachunki” turned off, Optima leaves the ledger settlements alone and the accountant settles them.

  • settlements.delete: you cannot delete through the API a settlement carried over to the ledger settlements (422 settlementLinkedToLedger), nor one used on an interest note or a netting (settlementUsedByDocument).
  • cashTransactions.delete deletes a transaction that is in an open report, is not posted, not even to the buffer (documentPosted), and has no settlements (documentSettled, delete the settlements first).

The list of changes runs 60 seconds behind the clock of Optima’s database. So a change shows up about a minute after the write.