Books by finzkoDevelopers

Payroll posting

For a separate payroll system to book its pay runs. You send the per-run totals as semantic lines (salary_expense, pf_payable, …); FinzBooks maps each to a ledger, creates the standard ones that are missing, and posts one balanced journal. You never need the organization's account ids.

Posting and requesting ledgers use AIBooks.journals.CREATE; reading uses AIBooks.journals.READ. There is no separate payroll scope. These routes do not require an Idempotency-Key: idempotency comes from the reference you send (below).

How a run is booked

  1. POST /payroll/runswith the run's lines. Costs (debits) must equal payables (credits).
  2. Later, POST /payroll/settlements when the payables are paid out of a bank or cash account.
GET/payroll/ledger-mapLine-type vocabularytoken only (no scope check)

Returns each standard line type with the ledger it maps to, its account type and its natural side. Needs a valid token for an organization but no particular scope.

200 OK
{
  "code": 0,
  "message": "success",
  "payroll_ledger_map": {
    "types": [
      { "type": "salary_expense",  "ledger": "Salaries & Wages", "account_type": "EXPENSE",             "side": "debit"  },
      { "type": "net_pay_payable", "ledger": "Net Salary Payable", "account_type": "CURRENT_LIABILITIES", "side": "credit" },
      …
    ],
    "note": "Unknown types must supply ledger + ledger_type + side to map a custom head."
  }
}

The standard types:

  • Debit (cost): salary_expense, wages_expense, bonus_expense, overtime_expense, employer_pf_expense, employer_esi_expense, gratuity_expense, staff_welfare_expense, reimbursement_expense
  • Credit (payable): net_pay_payable, reimbursement_payable, pf_payable, esi_payable, pt_payable, tds_payable, lwf_payable, gratuity_payable
  • Credit (recovery against an asset): loan_recovery, salary_advance_recovery
POST/payroll/runsPost a payroll runAIBooks.journals.CREATE
FieldTypeNotes
periodstringRequired. Label, e.g. 2026-06.
pay_datedateRequired. Posting date of the journal.
referencestringRequired, 1 – 120 characters. Your unique pay-run reference. See idempotency below.
lines[]arrayRequired, at least one.
memostring?

Line

FieldTypeNotes
typestringRequired. A standard type, or a custom head (then ledger, ledger_type and side are required).
amountfloatRequired, greater than 0.
sidestring?debit or credit. Defaults from the type.
ledgerstring?Post to this ledger name instead of the standard one.
ledger_typestring?Account type for an overridden or new ledger, e.g. EXPENSE.
partystring?Per-person sub-ledger, e.g. an employee owed a reimbursement. Appends “— name” to the ledger name.
notestring?Line description.

Extra fields on the body or on a line are ignored, not rejected.

POST /payroll/runs
Authorization: Bearer aibk_pat_…
Content-Type: application/json

{
  "period": "2026-06",
  "pay_date": "2026-06-30",
  "reference": "PAYRUN-2026-06",
  "lines": [
    { "type": "salary_expense",      "amount": 500000 },
    { "type": "employer_pf_expense", "amount": 30000 },
    { "type": "net_pay_payable",     "amount": 440000 },
    { "type": "pf_payable",          "amount": 60000 },
    { "type": "tds_payable",         "amount": 30000 }
  ]
}

200 OK
{
  "code": 0,
  "message": "success",
  "payroll_run": {
    "reference": "PAYRUN-2026-06",
    "journal_id": "je_…",
    "period": "2026-06",
    "posted": true,
    "idempotent_replay": false,
    "total_debit": 530000.0,
    "total_credit": 530000.0,
    "line_count": 5,
    "created_ledgers": []
  }
}

Behaviour

  • Idempotent per reference. Posting the same reference again does not post twice; it returns the existing run with idempotent_replay: true. The reference is stored on the journal, so use one that is unique per run, and do not reuse a run's reference as a settlement reference.
  • Standard ledgers are created automatically (listed in created_ledgers).
  • Custom heads need approval. A line that overrides the ledger, uses party, or has an unknown type points at a ledger that may not exist. If it does not, a ledger request is filed and the run is not posted: you get posted: false, journal_id: null, a pending_ledgers list (name, request_id, status) and a message. After an admin approves in the app, post the same reference again and it goes through.
  • Debits must equal credits to the paisa.

Notable errors

  • 400 payroll.invalid — unknown type with no override; unbalanced run (the message gives both totals); no postable lines.
GET/payroll/runs/{reference}Get a posted runAIBooks.journals.READ
200 OK
{
  "code": 0,
  "message": "success",
  "payroll_run": {
    "reference": "PAYRUN-2026-06",
    "journal_id": "je_…",
    "posted": true,
    "date": "2026-06-30T00:00:00",
    "memo": null,
    "total_debit": 530000.0,
    "total_credit": 530000.0,
    "line_count": 5
  }
}

Unknown reference: 404 payroll.not_found. A run that is still waiting for ledger approval has no journal and returns this 404.

POST/payroll/settlementsSettle payables to bank or cashAIBooks.journals.CREATE

Debits the payable ledgers and credits the paid-through account in one journal.

FieldTypeNotes
datedateRequired.
paid_throughstringRequired. Bank or cash ledger, by name or id.
lines[]arrayRequired. Each has type (the payable being settled), amount (greater than 0), and optional ledger, party, note.
referencestring?Optional. When sent, posting it again returns the existing journal with idempotent_replay: true. Without it, every call posts a new journal.
memostring?
200 OK
{
  "code": 0,
  "message": "success",
  "payroll_settlement": {
    "reference": "PAYRUN-2026-06-PAID",
    "journal_id": "je_…",
    "posted": true,
    "idempotent_replay": false,
    "total": 440000.0,
    "created_ledgers": []
  }
}

Errors: 400 payroll.invalid if the paid-through account is not found, a line type is unknown with no ledger, or there is nothing to post.

Ledger requests

Ask the accounting admin to create a ledger ahead of time, then poll until it is approved.

POST/payroll/ledger-requestsRequest a new ledgerAIBooks.journals.CREATE
FieldTypeNotes
namestringRequired. Ledger name, e.g. Fuel & Petrol.
typestringRequired. Account type, e.g. EXPENSE, CURRENT_LIABILITIES, CURRENT_ASSETS.
external_refstring?Your own reference; a repeat with the same value returns the earlier request.
parentstring?Parent ledger name to nest under.
notestring?
200 OK
{
  "code": 0,
  "message": "success",
  "ledger_request": {
    "request_id": "lr_…",
    "status": "PENDING",            // PENDING until an admin approves; APPROVED at once if the ledger exists
    "name": "Fuel & Petrol",
    "type": "EXPENSE",
    "external_ref": "fuel-head",
    "account_id": null,             // set on approval
    "reject_reason": null,
    "created_at": "2026-06-30T09:00:00",
    "reviewed_at": null
  }
}

An unknown account type returns 400 ledger_request.invalid.

GET/payroll/ledger-requestsList ledger requestsAIBooks.journals.READ

Optional status filter. Lists the requests that came from payroll. Not paginated, and the response is { "data": { "ledger_requests": [ … ] } } (no code or message).

GET/payroll/ledger-requests/{request_id}Get one ledger requestAIBooks.journals.READ

Returns { code: 0, ledger_request: {…} }. Poll it for account_id. Unknown id: 404 ledger_request.not_found.