If your product issues invoices or captures spend, every one of those events is already an accounting event. This post shows how an invoice and an expense each compile into balanced journals, and what your product has to store to keep them traceable.
The pattern is the same on both sides. Your product creates a document (an invoice, an expense or a vendor bill). The document's status decides when it touches the ledger. The ledger posts a balanced journal from the document, using the accounts mapped on its items. Reports read those journals live. Your product never writes the journal itself.
All calls below run against the sandbox. They follow Build Embedded Accounting in 20 Minutes for the revenue side and Expense Management: Capture, Approve, Pay, Account for the spend side. Every request sends authorization: Bearer <token> and x-partner-domain. See Authentication and tokens for the token exchange.
Flow 1: Invoice to Cash
Map the item once
Revenue lands in the right account because the item carries the mapping, not the invoice. Create the item with a sales_account_id pointing at a revenue account in the company's chart:
curl -X POST $BASE/v1/items -H "$AUTH" -H "$PARTNER" -H "$CT" \
-d '{
"item_name": "Brand identity package",
"item_type": "service",
"sales_price": "4800.00",
"sales_currency": "USD",
"sales_account_id": "<Design Services Revenue account id>"
}'
Whoever understands the books decides this mapping once. After that, anyone (or any agent) invoicing the item can't put revenue in the wrong place.
Create and post the invoice
curl -X POST $BASE/v1/invoices -H "$AUTH" -H "$PARTNER" -H "$CT" \
-d '{
"people_id": "<customer people_id>",
"currency": "USD",
"document_number": "INV-00042",
"document_issue_date": "2026-06-12",
"document_due_date": "2026-07-12",
"external_source": "yourproduct",
"external_id": "job_8812",
"items": [
{ "item_id": "<item id>", "item_name": "Brand identity package",
"item_quantity": "1", "item_cost": "4800.00" }
]
}'
When the invoice posts, the ledger generates this journal:
| Account | Debit | Credit |
|---|---|---|
| Accounts Receivable | 4,800.00 | |
| Design Services Revenue | 4,800.00 |
Debits must equal credits or the write is rejected. There is no "post now, fix later" mode.
Record the payment
The route parameter is the invoice's anchor_id. Send an Idempotency-Key so a retry after a timeout can't pay the invoice twice:
curl -X POST $BASE/v1/invoices/<anchor_id>/payment \
-H "$AUTH" -H "$PARTNER" -H "$CT" \
-H "Idempotency-Key: pay-job_8812-001" \
-d '{
"payment_amount": "4800.00",
"payment_date": "2026-06-12",
"payment_mode": "…",
"deposit_account": "<bank account id>",
"reference_number": "WIRE-20260612-001"
}'
A second journal posts:
| Account | Debit | Credit |
|---|---|---|
| Cash · Operating | 4,800.00 | |
| Accounts Receivable | 4,800.00 |
Receivables for the customer return to zero, cash rises, and revenue stays where it was posted. Revenue was earned when the invoice posted, not when the money arrived. That is accrual accounting, and your product got it without writing a journal.
Payment fields also include bank_charge and exchange_rate. The spec says the payment and any required settlement or FX effects commit together. Use them for fees and cross-currency receipts rather than posting correcting journals afterwards.
Flow 2: Spend to Payables
Spend comes in two shapes, and most products need both.
Direct expense: the money already moved
A card swipe or cash purchase is a fact, not a request. Record it with POST /v1/expenses, naming the account the money left in paid_account_id, with one expense_account_id per line so a single receipt can split across categories:
curl -X POST $BASE/v1/expenses -H "$AUTH" -H "$PARTNER" -H "$CT" \
-d '{
"expense_date": "2026-06-12",
"currency": "USD",
"vendor_id": "<vendor people_id>",
"paid_account_id": "<bank/cash account id>",
"is_itemize": true,
"reference_number": "CARD-20260612-014",
"items": [
{ "expense_account_id": "<expense account id>", "amount": "89.00",
"description": "Figma seat, monthly" }
]
}'
| Account | Debit | Credit |
|---|---|---|
| Software & Subscriptions | 89.00 | |
| Cash · Operating | 89.00 |
GET /v1/accounting/expense-accounts returns the accounts a cost can post to. That is the list behind your category-mapping screen.
Vendor bill: approve now, pay later
A contractor's monthly invoice is an obligation. It should be recognized in the right period and paid only after sign-off. That is a bill: the same document model as an invoice, pointed the other way.
curl -X POST $BASE/v1/bills -H "$AUTH" -H "$PARTNER" -H "$CT" \
-d '{
"people_id": "<vendor people_id>",
"currency": "USD",
"document_issue_date": "2026-06-12",
"document_due_date": "2026-07-12",
"items": [
{ "item_id": "<item id>", "item_name": "Contract engineering — June",
"item_quantity": "1", "item_cost": "5200.00" }
]
}'
Posting the bill accrues the cost and the payable together:
| Account | Debit | Credit |
|---|---|---|
| Contract Services Expense | 5,200.00 | |
| Accounts Payable | 5,200.00 |
Paying it with POST /v1/bills/{id}/payment (same Idempotency-Key rule) clears the obligation:
| Account | Debit | Credit |
|---|---|---|
| Accounts Payable | 5,200.00 | |
| Cash · Operating | 5,200.00 |
The expense stays in June even if the cash leaves in July. Accounts payable always equals the open bills, because it is built from them.
Status Gates Decide When the Ledger Moves
"When does this document post?" is a per-company setting, not code in your product.
- Invoices and bills have configurable statuses per company:
GET/POST /v1/invoices/setting/statusand/v1/bills/setting/status. Each status carries astatus_category(draft,open,settledorvoid). - Transitions between statuses are listed at
GET /v1/invoices/setting/state-transition(and the bills equivalent). Each has afrom_state, ato_stateand aledger_effect. - The available effects come from
GET /v1/invoices/setting/state-transition/ledger-effectsandGET /v1/bills/setting/state-transition/ledger-effects:none,post,voidorpayment. Load your workflow dropdown from this list rather than hard-coding it. - Moving a document is
PUT /v1/invoices/{id}/state-transition(or/v1/bills/{id}/state-transition) withto_stateand an optionalreason. - Expenses follow a fixed path,
draft→submitted→approved, viaPOST /v1/expenses/state-transition. Per the spec, the ledger entry posts onapproved.
Your approval UI is then a thin layer. Show the document, call the transition, and let the transition's ledger_effect decide whether a journal posts. Every status change lands in the document's activity history, so "who approved this and when" is a query, not a Slack search.
What Your Product Should Store
To trace any journal back to the event in your product that caused it, keep these on your side:
| Store | Why |
|---|---|
anchor_id of each document | The stable ID across edits. Every edit creates a new version (version_number increases) while the anchor stays constant. Use it in payment routes and links. |
Your own document_number | A second create with the same number is rejected with DUPLICATE_DOCUMENT_NUMBER, so a retried create can't make a duplicate invoice. Read the document back on that error. |
external_source + external_id | Ties the document to your record (job_8812). Unique per source and document type. |
The Idempotency-Key you sent per payment | An exact retry returns the recorded payment. The same key with different details returns 409. |
reference_number on payments and expenses | The value finance will search for when matching the bank. |
One caution: journals and other writes are not deduplicated by key. If a direct journal post times out, check the ledger before you retry. The full retry model is in Webhooks and idempotency.
Where Paprel Fits
- Documents compile to journals. Invoices, bills, expenses and payments generate balanced entries from item and account mappings. See embedded invoicing and expenses and payables.
- Versioned documents. Edits create new versions under one
anchor_id, so the history of what was billed is never overwritten. - Safe retries where money moves.
Idempotency-Keyon invoice and bill payments. Duplicatedocument_numberrejected on create. - Reports derived live. P&L, balance sheet and trial balance are read from the same journals. There is no sync job and no second copy to reconcile.
- API-first documents. Invoices, bills and expenses have no Web Component. You build the form in your product. The ledger, reports and reconciliation components ship as embeddable UI.
The alternative is syncing your invoices into a customer's QuickBooks or Xero over their APIs. Then your product's events land in someone else's ledger after the fact, and you spend your time reconciling two systems. Embedding the ledger keeps one record of truth inside your product. The trade-offs are laid out in QuickBooks API alternative.
Read Next
- For the subledger mechanics behind AR and AP, read Why Subledgers Matter in Embedded Accounting.
- For matching these payments to the bank, read Bank Reconciliation for Embedded Accounting.
- For agents that draft invoices and bills for human review, read the Accounts Receivable AI Agent Playbook.
Building the spend side? Follow the expense management flow.