Errors and limits
Every error has at least the message and code fields, whether it comes from the key, a limit, the app or the ERP:
{ "message": "Missing scope: warehouse:read", "code": "FORBIDDEN"}code is a stable error identifier, and it is the one to branch your client code on. message is in English and meant for diagnosis, and its text can change. Errors raised by a method also have a data field with extra diagnostic details. Errors from the key, the add-on and the limits happen before the method and have only message and code. Validation errors add an issues field, an array describing each invalid field. Each entry has a message and usually a path pointing to the field. This is the response to "limit": 5000 when the allowed maximum is 100:
{ "message": "Input validation failed", "code": "BAD_REQUEST", "issues": [ { "origin": "number", "code": "too_big", "maximum": 100, "inclusive": true, "path": ["limit"], "message": "Too big: expected number to be <=100" } ]}Error codes
Section titled “Error codes”| Status | code |
Meaning |
|---|---|---|
| 400 | BAD_REQUEST |
The parameters failed validation (details are in issues), the body is empty (the response then has no issues), or Sancho knows before writing that the ERP will not accept the values (details are in issues, or the reason is in message). When a connector’s schema refused the values before anything reached the ERP, data.cause has type invalidPayload and data.cause.issues lists each field (path), the kind of error (code) and the reason (message). A refusal by the ERP itself is 422. |
| 401 | UNAUTHORIZED |
No key in the Authorization header, or the key is unknown, deleted or expired. Also returned for an unknown path called without a key. |
| 402 | PAYMENT_REQUIRED |
The account does not have the API add-on enabled (for /v1/mcp: the MCP add-on). |
| 403 | FORBIDDEN |
The key lacks the scope the method requires (the scope’s name is in message), the integration does not support the operation (Integration does not grant this scope), or the person who created the key no longer belongs to the account (writes only). |
| 404 | NOT_FOUND |
There is no such document, product or method, or the integration does not belong to the key. |
| 409 | CONFLICT |
The document or card changed after your read, or someone is saving it at that moment. Writes only. |
| 413 | PAYLOAD_TOO_LARGE |
The request body is larger than 64 KiB. |
| 415 | UNSUPPORTED_MEDIA_TYPE |
The body is not JSON, or it came without a Content-Type header. |
| 422 | UNPROCESSABLE_CONTENT |
The ERP refused the write and saved nothing. If Sancho recognized the reason, it is in data.cause.reason. |
| 429 | TOO_MANY_REQUESTS |
The account’s request limit was exceeded, or the ERP is limiting requests (then without a Retry-After header, message is The integration is rate limiting requests, and data.cause has type relayedFailure). |
| 500 | INTERNAL_SERVER_ERROR |
An error on the Sancho side (message: Internal server error), or the integration failed, did not respond in time, or the connection to it broke after the request was sent (message: The integration failed to process the request or The integration did not answer in time, and data.cause has type relayedFailure). |
| 503 | SERVICE_UNAVAILABLE |
The request never reached the integration because it is unreachable, or the write did not start: the connector was busy, or Optima would not let it write (a module’s seats taken, the key not validated in Menadżer Kluczy). Nothing was written, and the next attempt may pass. |
Errors 413 and 415 are not in the OpenAPI file, because we reject such requests before they reach the method.
The API never answers 502 or 504. If you get one, a server in front of the API (a proxy, Cloudflare) answered, not Sancho. Treat it as a dropped connection.
The key (401), the add-on (402) and the request limit (429) are checked before the request body is read. Such a request reaches neither the method nor the ERP.
Errors from integrations
Section titled “Errors from integrations”When a list searches several integrations and one of them fails, the response has code 200 and the integration’s number is in failedIntegrationIds. You get an ERP error as 422, 500 or 503 from methods that query a single integration, such as *.get.
- 500: the connector failed, the ERP did not respond in time, or its answer was lost on the way back. Reads change nothing, so they can be repeated. A write may have gone through, though, so check whether the document exists before you retry.
- 503: the connector is disconnected, the ERP is unreachable or the write did not start. Nothing was written; try again in a moment.
- 422: the ERP refused for a reason you can remove, such as a closed period, a missing account or missing permissions. Nothing was written, and the same request gets the same answer.
Refusal reasons
Section titled “Refusal reasons”A 422 response to a write has in data.cause the type erpRefusal, the name of the connector call (action), the reason (reason), the value the reason concerns (subject), and the request field that caused it (path, for example vatRegisterId or proposedJournalEntry.lines[0].debitAccount; null when the refusal names no field). For an API key message is always the same, so branch your code on reason.
{ "message": "The integration refused the request", "code": "UNPROCESSABLE_CONTENT", "data": { "cause": { "type": "erpRefusal", "action": "accountingDocuments.create", "reason": "invalidReference", "subject": "7", "path": "vatRegisterId" } }}reason |
Meaning | subject |
|---|---|---|
notSupported |
The integration does not support the operation or the value in the path field, for example a cash account in a currency other than the złoty, an amount the API does not round to the grosz (the rule is on the Accounting page, in Cash and bank in Optima), or an amount above 9999999999999.99. |
The refused value (the account’s currency, an amount, documentType, a tax category, a transaction kind, an e-invoice system, documentMarker, the corrected invoice’s number, a line account), the name of the unsupported call, or null |
invalidReference |
The path field names something that does not exist or cannot be used: an account outside the chart of accounts, an inactive VAT, cash or bank register, a journal outside the fiscal year, a counterparty that does not exist, or a JPK_V7 code unknown in that period. |
The number, symbol, id or codes concerned, separated by commas |
periodLocked |
The date falls in a closed period. | The date |
documentPosted |
The document is posted: with a journal entry, in the KPiR book or in the revenue register, buffer included. You can change a VAT record after that entry is removed. | For a journal entry, its ledger number (the entry’s id when it has no number). For an entry in KPiR or in the revenue register, the number of the VAT record’s document, its documentNumber. For a cash or bank transaction, its number. null when Optima itself refuses, because the document was posted after Sancho checked it. |
documentSettled |
The cash transaction has settlements. Remove them first. | The transaction’s number |
inUse |
Something in the ERP still uses the card, so the ERP will not delete it. In Optima, an Optima rule stops the delete of a counterparty or an asset. | The code of the Optima rule, for example OPT32334 |
documentExported |
The VAT record was exported to the accounting office, and the connector’s operator has no right in Optima to change exported documents. | The number of the VAT record’s document |
noProposedJournalEntry |
The VAT record has no proposed journal entry, so the API will not post it. | null |
postingFailed |
The ERP did not post the document. | null |
subledgerParentAccount |
The account has analytic accounts from a dictionary, so a plain analytic account cannot be created under it. | The account number |
notSubledgerParentAccount |
The account has no counterparty dictionary, or it splits the dictionary into groups. | The account number |
vatRegisterKindMismatch |
The VAT register is of a different kind than the record (purchases, sales), or update changes the record’s kind. |
The register’s name; null when the kind changes |
taxPeriodClosed |
The record’s VAT-7 month is in an approved declaration. | The month, YYYY-MM |
statementClosed |
The cash or bank statement covering the record’s date is closed. | The statement’s number |
noOpenStatement |
The register has no statement for that day, and the day lies before the last statement. The given cashStatementId does not belong to the register or does not cover the day. |
The date or the statement’s number |
numberingSeriesDirectionMismatch |
The numbering scheme is for the opposite direction to the record (for example KW for a receipt). | The scheme’s symbol |
notDoubleEntry |
The company does not keep double-entry books. | The bookkeeping method: ryczalt, kpir or null |
ledgerNotLicensed |
The connector’s login lacks the general ledger module, Księga Handlowa (ledgerLicensed: false in accounting.profile), which creating accounts, proposed journal entries and accountingDocuments.post need. |
null |
noFiscalYear |
There is no fiscal year for that date. | The date |
ledgerAccountNotPostable |
You cannot post to this account: it has analytic accounts, it is inactive, or it waits for dictionary entries. | Account numbers, separated by commas |
ledgerAccountHasEntries |
The account already has entries or an opening balance, so an analytic account cannot be created under it. | The account number |
duplicateDocument |
The ERP already has a record the write would duplicate. In Optima this is a duplicate VAT record, as the company set up its duplicate check, or, on any write, a value Optima keeps only once, for example the rowId from importSource. In ERPNext, a counterparty being created whose card is already there. Sancho recognizes a value taken in Optima by SQL Server’s Polish message; when the server answers in another language, the same refusal comes as relayedFailure. |
For a duplicate VAT record, the duplicate as Optima names it; null otherwise |
settlementExceedsRemaining |
The settlement amount exceeds what is left to settle. | The document’s number; null when the settlements exceed the new record’s amount |
settlementCurrencyMismatch |
The documents being settled are in different currencies. | The document’s number |
settlementNotApplicable |
The document is not subject to settlement. | The document’s number |
settlementLinkedToLedger |
The settlement is linked to a ledger settlement in the books. The accountant removes it. | The ledger settlement’s id |
settlementUsedByDocument |
The settlement is used on an interest note or a compensation. | The settlement’s id |
invalidValue |
The ERP did not accept a value. | null; the ERP field in path, if the ERP named it |
A refusal Sancho did not recognize has in data.cause the type relayedFailure and only action.
Limits and retrying
Section titled “Limits and retrying”On 429, wait the number of seconds given in the Retry-After header and repeat the request. The RateLimit-Limit, RateLimit-Remaining and RateLimit-Reset headers tell you how many requests you have in the window and when it ends.
| Limit | Value | Result of exceeding it |
|---|---|---|
| Requests per account | 100 per second, shared by all keys and /v1/mcp |
429 with Retry-After |
| Body size | 64 KiB | 413 |
In the cloud, the request limit is counted jointly by all API processes, so the stated value is the account’s actual limit. On a self-hosted server without Redis, each API process counts it separately.
On 500, retry reads with a growing delay and cap the number of attempts. A write that got 500 or a dropped connection may have gone through, so check with a list whether the document exists before you retry it. You find an accounting document, a cash transaction, a settlement and a counterparty sent with importSource with the importAppId and importRowId filters together. You find an asset card in /assets.list by its inventory number. After 503 the write did not happen, so you can send it again. On 409, read the document again and send the change with the new expectedSavedAt and expectedModifiedAt. Do not retry 400, 401, 402, 403, 404 and 422 without changing the request or the configuration.