Importing data
Push a company's books through the API: accounts, master data, balances, lines, open items.
For a company whose books live in your system rather than in an ERP Accountflow fetches from. To fix or remove what you pushed, see corrections.
Before you start
- Create the company in Accountflow (https://ajour.accountflow.com).
- In its accounting-system settings, choose Api. Until then every import is
409,reason: company_not_api_managed. A year whose ledger came from another accounting system is refused the same way, even after the switch. - Create a system API client with
imports:write(quickstart). Addledger:readto read the data back.
GET /v1/companies/{companyId}/imports/readiness says where the company stands:
{
"apiManaged": true,
"accountingSystem": "Api",
"currentYear": 2025,
"years": [
{ "year": 2025, "current": true, "accounts": 0, "mappedAccounts": 0,
"openingBalances": 0, "generalLedgerLines": 0, "lastImportAt": null }
],
"dimensions": 0,
"subLedgers": 0,
"blockers": ["no_accounts"],
"warnings": [],
"nextStep": "import_accounts"
}
blockers stop an import; nextStep is what to do next.
How every import works
POST /v1/companies/{companyId}/imports/<kind>with anIdempotency-Key.- The whole request is validated. Nothing is accepted if any line fails:
- malformed input (no
year,periodoutside 1–12) is400 validation_failed; - a broken rule is
422 unprocessablewitherrorsitems{field, message, index}(index0-based, up to 100 items).
- malformed input (no
202 Acceptedwith an import:id,status: "QUEUED",jobId.- Poll
GET /v1/companies/{companyId}/imports/{importId}untilSUCCEEDEDorFAILED, or subscribe tojob.succeeded/job.failedwebhooks.GET /v1/jobslists your client's jobs.
{
"id": "0b8f…", "kind": "GENERAL_LEDGER_LINES", "year": 2025, "mode": "MERGE",
"status": "SUCCEEDED", "jobId": "6d1c…", "datasetId": "0b8f…", "lineCount": 9800,
"rowsDiscovered": 9800, "rowsValid": 9795, "rowsFailed": 5,
"rowsInserted": 9700, "rowsUpdated": 95, "rowsDeleted": null,
"sampleErrors": ["line 12: missing required field: amount"],
"failureReason": null
}
| Rule | Detail |
|---|---|
| Size | At most 10 000 lines and 8 MiB per request; more is 413 payload_. |
| Concurrency | One import per kind and company at a time. Another is 409, reason: job_, with the jobId to wait for. Send batches one after another. |
| Retries | The same Idempotency-Key returns the same import. |
| Partial success | SUCCEEDED may carry rowsFailed. sampleErrors (up to 100, line N: message, N from 1) names them. Fix and re-send those lines; re-sending the rest is harmless. |
| Ids in errors | sampleErrors, inUse and failureReason name only your ids, never internal ones. |
| History | datasetId is stamped on every row the import touched. Quote it to support. The payload is kept 24 hours; the import record stays. |
failureReason on a FAILED import:
failureReason |
Meaning | Do |
|---|---|---|
internal_ |
The job crashed. | Re-send with a new Idempotency-Key. |
job_ |
The job was not picked up within 30 minutes. | Re-send with a new Idempotency-Key. |
api_, company_, company_ |
Checked again when the job starts: the client was suspended or revoked, the company was deleted or left your organization, or its ledger left the Api system. Nothing was uploaded. | Fix the cause first. |
lines_, … |
A correction's refusal (corrections). |
Values
- Amounts are decimal strings (
"-1250.00", at most four decimals); JSON numbers are accepted. - Dates are ISO (
2025-03-14). - Your ids, keys and codes (
id,key,parentKey,partyKey,parentPartyKey,itemKey,matchKey,accountCode,voucherKey,erpDocumentId, …) may not contain:,/,{,}or whitespace, and are length-bounded. A violation is422with the line inerrors.
Names when reading back
| You send | You read | On |
|---|---|---|
accountCode |
accountNumber |
GET …/, GET …/ |
accountDescription |
name |
GET …/ |
accountCategory |
category |
GET …/ |
id (a general-ledger line) |
sourceLineId; lineId is Accountflow's id for the line |
GET …/ |
voucherNo, voucherKey |
voucherNo, voucherKey |
GET …/, GET …/ |
transactionCurrencyCode |
transactionCurrency |
GET …/ |
Order
| # | Kind | Endpoint | Per |
|---|---|---|---|
| 1 | Chart of accounts | POST …/ |
Accounting year |
| 2 | Dimension values (optional) | POST …/ |
Company |
| 3 | Sub-ledgers (optional) | POST …/ |
Company |
| 4 | Opening balances | POST …/ |
Accounting year |
| 5 | General-ledger lines | POST …/ |
Accounting year |
| 6 | Open items (optional) | POST …/ |
Customers or suppliers |
Opening balances and lines naming an account code missing from that year's chart are
422, reason: unknown_account_codes. A line may name a dimension or sub-ledger key you
haven't pushed; it is created as a plain value. Push them first to give them names, types
and hierarchy.
1. Chart of accounts
curl -s -X POST https://api.prod.accountflow.com/v1/companies/$COMPANY/imports/accounts \
-H "Authorization: Bearer $TOKEN" -H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" -d '{
"year": 2025,
"accounts": [
{ "accountCode": "1920", "accountDescription": "Bankinnskudd",
"accountCategory": "Balance", "currencyCode": "NOK" },
{ "accountCode": "3000", "accountDescription": "Salgsinntekt",
"accountCategory": "Result" }
]
}'
- An existing
accountCodeis updated in place. - An import never touches the standard-account mapping. Map in Accountflow; while some are
unmapped,
readiness.warningshasunmapped_accounts. hidden: truehides the account in the application; omithiddento keep the flag.- Each accounting year has its own chart: push accounts for every year you load.
2–3. Dimensions and sub-ledgers
{ "dimensions": [
{ "key": "DEPT", "value": "Departments", "type": "department" },
{ "key": "DEPT-10", "value": "Sales", "type": "department", "parentKey": "DEPT" } ] }
{ "subLedgers": [ { "partyKey": "C-1001", "value": "Kunde AS", "type": "customer" } ] }
Keys are yours, stable and unique per company (not per year). Read them back with
GET …/dimensions (key, parentKey) and GET …/sub-ledgers (partyKey,
parentPartyKey). A sub-ledger party is a partyKey everywhere: open items, the
sub-ledger reconciliation, and partyKeys on lines and opening balances.
4. Opening balances
{ "year": 2025, "lines": [
{ "id": "OB-1920", "accountCode": "1920", "amount": "125000.00" },
{ "id": "OB-1500", "accountCode": "1500", "amount": "48200.00",
"partyKeys": ["C-1001"] } ] }
id is your stable row id; re-sending it updates the row. The trial balance's opening
column follows.
5. General-ledger lines
{ "year": 2025, "lines": [
{ "id": "INV-2025-000123-1", "accountCode": "3000", "amount": "-1250.00",
"period": 3, "voucherKey": "V-2025-0456", "voucherNo": "456",
"description": "Salg mars", "transactionDate": "2025-03-14",
"taxCode": "3", "taxAmount": "-312.50", "taxPercentage": "25",
"dimensionKeys": ["DEPT-10"], "partyKeys": ["C-1001"] } ] }
idis the line's identity. The sameidupdates the line in place and keeps the previous version in history; a newidis a new line. There is no fuzzy matching.- You supply
period(1–12) andyear. Nothing is derived from dates. voucherKeygroups a voucher's lines and is what a document'sVOUCHERassociation takes.voucherNois the number accountants see.- Lines are merged, never replaced: a line you don't re-send stays. Delete to remove one.
6. Open items
Customer or supplier open items with their matches. erpDocumentId is your text key, not
a /v1/documents id. They read back at GET …/sub-ledgers/open-items.
{ "subLedgerType": "CUSTOMER", "mode": "INCREMENTAL", "items": [
{ "itemKey": "inv-1001", "partyKey": "C-1001", "subLedgerType": "CUSTOMER",
"accountCode": "1500", "erpDocumentId": "inv-1001", "entryCategory": "invoice",
"documentDate": "2025-03-14", "dueDate": "2025-04-13",
"amount": "1250.00", "amountOpen": "250.00", "settlementStatus": "PARTIAL",
"matches": [ { "matchKey": "pay-77", "matchDate": "2025-04-01", "amount": "1000.00" } ] } ] }
INCREMENTALtouches only what you send.FULL,FULL_REFRESHandBASELINEare snapshots: items and matches not in the snapshot are retired.- One invalid item fails the whole import.
Moving a company from another accounting system
The company keeps the other system's ledgers. Give each year you will push its own Api ledger (years 2000 to next year):
curl -s -X POST https://api.prod.accountflow.com/v1/companies/$COMPANY/ledgers \
-H "Authorization: Bearer $TOKEN" -H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" -d '{"year": 2026, "setCurrent": true}'
201with the ledger. The year's fiscal-year row is created if missing.- The new ledger becomes current with
"setCurrent": true, or when the company has no current ledger or its current ledger holds no GL lines. Otherwise it sits beside the current one ("current": false), as for a backfill year. - Imports need the current ledger on Api, so send
setCurrentfor the year you switch. - A year with an Api ledger already is
409,reason: ledger_exists, withledgerId. - During a fetch from the other system:
409,reason: fetch_in_progress. Wait for it. - Once a year's Api ledger is current, Accountflow stops fetching that year from the other system. The company's accounting-system setting may still name it until someone chooses Api.
GET …/ledgers (?year= to filter) lists the ledgers. Both calls need imports:write.
{ "data": [
{ "id": "…", "companyId": "…", "year": 2026, "accountingSystem": "Api",
"apiManaged": true, "current": true, "createdAt": "2026-11-25T09:00:00Z" },
{ "id": "…", "companyId": "…", "year": 2026, "accountingSystem": "Tripletex",
"apiManaged": false, "current": false, "createdAt": "2026-01-02T06:00:00Z" } ],
"pagination": { "nextCursor": null, "hasMore": false } }
History as a monthly trial balance
When the old system gives you a trial balance rather than vouchers, push one row per account and month with the closing balance at month end (balance-sheet accounts include the opening balance; result accounts are year to date):
{ "year": 2025, "rows": [
{ "accountCode": "1920", "accountDescription": "Bankinnskudd", "period": 1,
"closingBalance": "125000.00", "openingBalance": "100000.00" },
{ "accountCode": "3000", "accountDescription": "Salgsinntekt", "period": 1,
"closingBalance": "-48200.00" } ] }
POST …/imports/trial-balanceanswers202with an import of kindTRIAL_BALANCE.- Missing accounts are created, named
accountDescription. - Balance-sheet accounts (classes 1 and 2) get the year's opening balance: from the row, else last year's closing, else 0.
- Each month with a closing gets one line with the month's movement, dated the month's last day. Re-sending a month updates it and leaves later closings as they were.
- Two different closings for one account and month, or two different opening balances for
one account, are
422. - A year takes a trial balance or vouchers, not both. A trial balance into a year holding
lines or opening balances you pushed is
409,reason: foreign_gl_lines; lines or opening balances into a trial-balance year are409,reason: trial_balance_year. - Corrections can't remove a trial balance; re-send the months with the right closings.
- Until it is switched on for your environment, it answers
409,reason: trial_balance_import_unavailable, and imports nothing.
What an import starts
General-ledger lines, opening balances and trial balances finish like an accounting-system
fetch: the company's last-updated time moves, the post-fetch processing runs, and
erp_fetch.completed is announced. result.fetchCompletion says how that
went; it never fails the import. Other kinds start nothing.