Accountflow Developer prod

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

  1. Create the company in Accountflow (https://ajour.accountflow.com).
  2. 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.
  3. Create a system API client with imports:write (quickstart). Add ledger:read to 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

  1. POST /v1/companies/{companyId}/imports/<kind> with an Idempotency-Key.
  2. The whole request is validated. Nothing is accepted if any line fails:
    • malformed input (no year, period outside 1–12) is 400 validation_failed;
    • a broken rule is 422 unprocessable with errors items {field, message, index} (index 0-based, up to 100 items).
  3. 202 Accepted with an import: id, status: "QUEUED", jobId.
  4. Poll GET /v1/companies/{companyId}/imports/{importId} until SUCCEEDED or FAILED, or subscribe to job.succeeded / job.failed webhooks. GET /v1/jobs lists 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_too_large.
Concurrency One import per kind and company at a time. Another is 409, reason: job_in_flight, 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_error The job crashed. Re-send with a new Idempotency-Key.
job_expired The job was not picked up within 30 minutes. Re-send with a new Idempotency-Key.
api_client_inactive, company_unavailable, company_not_api_managed 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_in_use, … A correction's refusal (corrections).

Values

Names when reading back

You send You read On
accountCode accountNumber GET …/general-ledger/lines, GET …/accounts
accountDescription name GET …/accounts
accountCategory category GET …/accounts
id (a general-ledger line) sourceLineId; lineId is Accountflow's id for the line GET …/general-ledger/lines
voucherNo, voucherKey voucherNo, voucherKey GET …/general-ledger/lines, GET …/vouchers
transactionCurrencyCode transactionCurrency GET …/general-ledger/lines

Order

# Kind Endpoint Per
1 Chart of accounts POST …/imports/accounts Accounting year
2 Dimension values (optional) POST …/imports/dimensions Company
3 Sub-ledgers (optional) POST …/imports/sub-ledgers Company
4 Opening balances POST …/imports/opening-balances Accounting year
5 General-ledger lines POST …/imports/general-ledger-lines Accounting year
6 Open items (optional) POST …/imports/open-items 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" }
    ]
  }'

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"] } ] }

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" } ] } ] }

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}'

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" } ] }

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.