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.
Profile and dictionaries
Section titled “Profile and dictionaries”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.listandaccountingCategories.listreturn the whole dictionary on one page, withoutnextCursor. Inactive VAT registers, cash and bank registers, payment methods and categories are on the list too, withactive: false. A fiscal year hasstatus(openorclosed) andcurrentinstead. You choose integrations with thefilters.integrationIdfilter, and those that did not respond are infailedIntegrationIds.ledgerAccounts.listreads the chart of accounts of one company in one fiscal year. It requiresintegrationIdandfiscalYearId(fromfiscalYears.list) and has nofailedIntegrationIds. 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.createcreates 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.ensureSubledgerAccountreturns 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.
Accounting documents
Section titled “Accounting documents”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.
numberis the number the ERP assigned, anddocumentNumberis the number from the document, for example from the invoice.originsays where the document comes from:invoice(from an invoice in the ERP, whichinvoiceIdnames forinvoices.get),eInvoice(imported from an e-invoicing system),imported(imported from another application),manual(typed in the ERP) orother. In the other direction, an invoice frominvoices.listandinvoices.getnames its accounting document inaccountingDocumentId. It isnullwhen the invoice has no accounting document, and always in ERPNext and Fakturownia.invoices.getcan show the state from up to 5 minutes ago.importSourceis 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 hasnull.statusis the document’s state in the books:draft,approved,posted,reversedorvoided. Which of them occur depends on the ERP.journalEntryshows the document’s journal entry. The proposed journal entry thatpostbooks by is a field of the ERP’s variant, in OptimaproposedJournalEntry.totalsgives the amounts in the document’s currency (currency), andtotalsBasein the company’s currency.exchangeRateis the document’s exchange rate. For a document in the company’s currency it isnull.- A line in
lineshas 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,outOfScopeorother. A purchase line hasdeductible(full,noneorpartial), and on sales it isnull. eInvoicehas the document’s number in the e-invoicing system as{ "system": …, "number": "…" }, wheresystemisksef,sdi,peppolorother, or the field isnull.taxReportingholds the tax marks of the country in thecountryfield. Today there is only the Polish block, with the marks for JPK_V7.filters.modifiedAtwith$gtreturns the documents changed since your last read. Id filters, for examplefilters.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.createenters the document.valuesis the whole document.nullinoperationDate,taxPointDateandpaymentMethodIdleaves the value to the ERP, and incurrencyit means the company’s currency. The API does not skip what the ERP will not accept: the answer is 422notSupportedwith the field’spath.accountingDocuments.updatereplaces the whole document and requiresexpectedModifiedAtequal tomodifiedAtfrom your read. When someone changed the document after your read, the API answers 409 and writes nothing.accountingDocuments.deletedeletes the document.accountingDocuments.postposts 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 422documentExported(unless the connector’s operator may change exported documents), and one in the month of an approved VAT declaration 422taxPeriodClosed. 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.
Import source
Section titled “Import source”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.
importSourceis{ "appId": …, "rowId": … }: your application (1 to 5 characters) and the document’s key in it (1 to 36 characters), both fromA-Z,a-z,0-9,.,_,:and-. The ERP stores them as the document’s import mark and returns them on a read asimportSource.- The ERP keeps each
rowIdonce, regardless ofappIdand letter case. The ERP refuses acreatewith arowIdit already has (422duplicateDocument) 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
createagain. You find an accounting document, a cash or bank transaction, a settlement and a counterparty on its list with theimportAppIdandimportRowIdfilters together. WithoutimportSource, 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.
Cash and bank
Section titled “Cash and bank”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.
warningssays what the ERP did not do in the general ledger beside a write that succeeded. The write stays.settlements.deletedeletes a settlement.cashTransactions.deletedeletes a transaction. It requiresexpectedModifiedAtequal tomodifiedAtfrom your read, otherwise 409. You cannot correct a transaction. Delete it and create a new one.
Change tracking
Section titled “Change tracking”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.changesshows 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
cursorfrom another list gives 400.
Comarch Optima
Section titled “Comarch Optima”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.
Chart of accounts and dictionaries
Section titled “Chart of accounts and dictionaries”- An account’s
idis different in every fiscal year, because Optima copies the chart of accounts into the new year. Match accounts bynumber. - 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
codeis 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 levels01and05ends at account 402-01-05. Each level has asegment(up to 20 characters, no-) and aname(up to 50 characters). The full number can have at most 50 characters.- The API does not create a synthetic account. A
parentNumbermissing from the chart of accounts gives 422invalidReferencewithpath: "parentNumber". An account with a dictionary gives 422subledgerParentAccount, an account with entries or an opening balance 422ledgerAccountHasEntries, and a closed period 422periodLocked. - 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:parentNumberis an account with the counterparty dictionary, for example 202 or 202-1, andentryis{ "kind": "counterParty", "id": 41 }, whereidis the counterparty’s id fromcounterParties.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 422notSubledgerParentAccount.warningsin 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, asensureSubledgerAccountdoes.
VAT register entries
Section titled “VAT register entries”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.
valuesis the whole document: the type (documentType), the number from the document (documentNumber), the counterparty (counterPartyId), the dates, the payment method (paymentMethodIdfrompaymentMethods.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 (vatRegisterIdfromvatRegisters.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 hasdeductible(full,noneorpartial), and a sales lineincludeInProRata. Optima’s fields on a line are the kind of purchase or sale (lineKind) and the category (categoryId). nullleaves the value to Optima.vatRegisterIdtakes the only active register of that kind, and when there are several or none, the answer is 422invalidReferencewithpath: "vatRegisterId".transactionKindandpaymentMethodIdtake the value from the counterparty card (a card without a default payment method leaves it to Optima),operationDateis the issue date, andlineKindandincludeInProRatatake Optima’s default value.taxPointDateanddeductionDateequal tonullleave 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.
taxReportingis required,nullgives 422notSupported. The marks go to Optima as JPK_V7 codes: the document type code (WEWforinternalDocument,ROforsalesSummary,IMPforcustomsDeclaration),documentMarker,ksefMarker,gtuandprocedures. A code Optima does not have gives 422invalidReferencewith thepathof the field it came from, for exampletaxReporting.gtu[0]ordocumentType. The VAT-7 month istaxReporting.vatDeclarationMonth.cashAccountingsets cash accounting independently of theMKcode.gtuandproceduresare sets: a repeated code gives 400, and a read returns them ordered by code.- The document’s type and marker must read back unchanged.
salesSummaryandFPexist only on sales, andcustomsDeclaration,MKandVAT_RRonly on purchases.FP,MKandVAT_RRdo not combine withinternalDocumentor withsalesSummary, because JPK_V7 has one field for them. Any other combination gives 422notSupportedwithpath: "documentType"orpath: "taxReporting.documentMarker". - The API does not skip what Optima’s VAT register will not accept. The answer is 422
notSupportedwithpath:documentTypecreditNote,debitNoteandother,precedingInvoice,lines[].account(accounts go in the proposed journal entry), non-emptylines[].dimensions,eInvoicewith asystemother thanksef, andgtuandprocedurescodes 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, andsubjectholds 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. proposedJournalEntryis the journal entry you approved, stored in Optima as the entry’s predekretacja: a journal (journalIdfromjournals.list, from the fiscal year that containsbookingDate), 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 422notDoubleEntryorledgerNotLicensed), a fiscal year that contains the day ofbookingDate(noFiscalYear) and accounts you can post to (invalidReference,ledgerAccountNotPostable). In a company on KPiR or ryczałt sendproposedJournalEntry: 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.
documentTypeis the type of the document:invoice,creditNoteordebitNote(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 codeWEW),salesSummary(ROon sales),customsDeclaration(IMPon purchases) orother.otheris 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 orderFP,RO,WEWon sales andMK,VAT_RR,WEWon purchases. When an entry fits several types at once, for example it is a correction with theWEWcode or a purchase with theIMPandWEWcodes,documentTypeshows one of them, and the codes of the others are inotherJpkCodes.numberis Optima’s accounting number, anddocumentNumberis the number from the invoice.positionis the position in the register.totalsBasegives the amounts in PLN. For a document in PLNexchangeRateisnull.receiptDateis the date a purchase was received,nullon sales.recordedDateis the date of the entry in the register, andtaxPointDatethe tax point date.taxReportingholds the marks for JPK_V7: the VAT-7 month (vatDeclarationMonth,nullwhen the entry does not go to JPK_V7), thegtucodes,procedures,ksefMarker(OFF,BFKorDI),documentMarker(FPon sales,MKorVAT_RRon purchases),splitPaymentandcashAccounting(the entry’s cash accounting, independent of theMKcode). A code this block has no field for, for exampleMPP, is inotherJpkCodes. 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.categoryfrom the entry’s transaction kind (transactionKind) and the line’s rate. A combination it cannot assign unambiguously hasother. deductibleon a purchase line says how much VAT can be deducted. On sales it isnull, andincludeInProRatasays whether the line enters the pro rata.accountanddimensionsare alwaysnull, because Optima books lines through the proposed journal entry.accountingDocuments.getalso returnsproposedJournalEntry, 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 invalues.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.postbooks 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,resultin the answer hasstatus: "draft"andjournalEntry.status: "draft". An entry whose journal entry the accountant has already approved hasstatus: "posted"andjournalEntry.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 injournalEntry, and writes nothing. The answer does not say whether the journal entry was created now. An entry without a proposed journal entry gives 422noProposedJournalEntry, a booking date outside the fiscal yearsnoFiscalYear, a closed periodperiodLocked, and a posting Optima did not carry outpostingFailed.postneeds double-entry books and the Księga Handlowa module (notDoubleEntry,ledgerNotLicensed).idinupdate,deleteandpost, as inaccountingDocuments.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 declarationtaxPeriodClosed. An entry exported to an accounting office givesdocumentExported, 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 in Optima
Section titled “Cash and bank in Optima”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 (
invalidReferencewithpath: "cashAccountId") and be in PLN (notSupportedwithpath: "cashAccountId"). - With
cashStatementId: nullthe transaction goes into the report that coversdate. A closed report gives 422statementClosed. A day after the last report opens a new report. A day in a gap between reports gives 422noOpenStatement, because the accountant opens such a report. documentSymbol: nulltakes the register’s default numbering scheme for the direction.party: nulltakes 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.30000000000000004as0.3, and0.010000001as0.01. An amount further from a whole grosz gives 422notSupportedwith that amount’spath, for exampleamountorsettlements[0].amount. An amount that rounds to zero or to more than 9999999999999.99 ends the same way. The same applies toamountinsettlements.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 (422settlementLinkedToLedger), nor one used on an interest note or a netting (settlementUsedByDocument).cashTransactions.deletedeletes 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).
Change tracking in Optima
Section titled “Change tracking in Optima”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.