Browse documentation

On this page

Build Embedded Accounting in 20 Minutes

Start with Post Your First Journal in 5 Minutes if this is your first Paprel request. This longer walkthrough connects a customer, a service item, an invoice, a recorded payment, and the resulting ledger evidence.

The downloadable example handles authentication and carries returned IDs between requests. You choose the accounting accounts and invoice posting transition once; it does not guess those company-specific settings.

Sandbox only. This creates example accounting records, not real payments. It does not send invoice emails or move money. Each new run creates new records; partial progress is not rolled back automatically.

Validation: run against a newly signed-up sandbox company on 19 November 2026. The example is also tested against the published request schemas and mocked responses.

0. Prepare credentials and download the example

You need Node.js 20 or newer, curl to download the file, and a company in sandbox.paprel.com. Create an App Connect client in that company and copy its client ID, secret and token URL. The partner domain for the sandbox is always sandbox.paprel.com.

Grant the permissions for the calls below: account list/add, payment-mode list, invoice-transition list/change, customer add, item add, invoice add/view/payment, and journal lookup. Check the required permission names on each operation in the Public API reference. Do not grant an administrative role just to make an example pass.

Download the accounting walkthrough, or save it from the terminal:

Shell
curl --fail --silent --show-error https://paprel.com/examples/accounting-walkthrough.mjs \
  --output accounting-walkthrough.mjs

Inspect the file before running it. It has no npm dependencies. Keep credentials in your local terminal environment; do not commit them or run this example in browser code. Read Authentication and tokens for production credential handling.

Shell
export APP_CONNECT_TOKEN_URL="https://api-sandbox.paprel.com/v1/app-connect/oauth/token"
export APP_CONNECT_CLIENT_ID="<your sandbox client ID>"
export APP_CONNECT_CLIENT_SECRET="<your sandbox client secret>"
export PARTNER_DOMAIN="sandbox.paprel.com"

The example exchanges these credentials for a short-lived token using client_credentials. It sends the bearer token and x-partner-domain on every subsequent Public API request. It accepts only the sandbox API host and refuses redirects; it never prints the token or secret.

1. Discover the company's accounting settings

Shell
node accounting-walkthrough.mjs --discover

This performs reads after authentication and prints:

ResultHow to use it
AccountsChoose an active revenue parent and a distinct cash/bank deposit account. Both must use your company base currency. In a new company these are salesRevenue and primaryOperatingAccount; don't choose a contra account (is_contra) such as salesDiscounts.
Payment modesChoose a configured payment method by its id, not its display label.
Invoice posting statesUse one value from invoice_posting_states as INVOICE_POSTING_STATE.

These come from GET /v1/accounting/accounts, GET /v1/company/payment-modes, GET /v1/invoices/setting/state-transition and GET /v1/invoices/setting/status.

Where the posting state comes from. If your company has a configured invoice workflow, invoice_posting_states lists the to_state of each allowed transition whose ledger_effect is post. A new company may not have a workflow configured yet: then the transitions call answers "Document state transitions not found", issuing the invoice is what posts it, and the list holds the issued status, sent.

Account subtype IDs and payment-method IDs are company configuration, not universal enum names. The example derives account_subtype and kind from the selected revenue parent rather than sending an ellipsis or inventing a classification. If no suitable account, method, or posting transition exists, configure it in the sandbox before continuing.

Shell
export COMPANY_CURRENCY="USD"
export REVENUE_PARENT_ACCOUNT_ID="<revenue parent id from discovery>"
export DEPOSIT_ACCOUNT_ID="<cash or bank account id from discovery>"
export PAYMENT_MODE_ID="<payment mode id from discovery>"
export INVOICE_POSTING_STATE="<to_state for a posting transition>"
export ACCOUNTING_DATE="$(date -u +%F)"

Replace USD if your company's base currency differs. Choose a date in an open accounting period. The script checks account membership, active state, matching currency, payment-method membership, and the posting state before creating any business records. You remain responsible for choosing accounts with the correct accounting treatment; UUID validity alone does not establish that.

2. Run the accounting workflow

Shell
node accounting-walkthrough.mjs --run

The script generates a unique run ID and saves created resource IDs in paprel-walkthrough-<run-id>.json in your current directory. Keep this file to inspect partial progress after a failure. It contains IDs, not credentials. Do not restart a failed run blindly: a server may have committed a request even if the response was lost.

Extend the chart of accounts

POST /v1/accounting/accounts creates a revenue sub-account under your selected parent. Its classification comes from the discovered account_subtype_id; its parent_id is the selected parent account.

Why it matters: the chart of accounts is the spine of the reports. A dedicated account keeps this exercise's revenue recognizable without inventing a new classification.

Create a customer and service item

The example creates a fictional customer through POST /v1/clients and reads data.id from the response. That value becomes the invoice's people_id.

It creates a service item through POST /v1/items, mapping sales_account_id to the new revenue account. item_type: "service" is a published enum value. The returned data.id becomes the invoice line's item_id.

Why it matters: the item carries its accounting treatment. Your invoice workflow can reuse that mapping without asking its caller to select revenue accounts every time.

Create and post the invoice

POST /v1/invoices creates a one-unit, 100.00 service invoice in the company base currency. The example captures data.anchor_id, the stable identifier used by subsequent invoice routes; it does not confuse that with a document version ID.

Creating an invoice and posting its accounting effect are distinct workflow concerns. Unless the returned status already matches the chosen posting state, the example calls PUT /v1/invoices/{id}/state-transition with to_state; with a configured workflow it first checks that the transition is allowed from the current status. It then reads the invoice's journal and stops before the payment if there is none, so an invoice that didn't post is never paid.

For an untaxed service invoice, the posting illustrates:

AccountDebitCredit
Accounts receivable100.00
Walkthrough revenue100.00

Company tax and document settings may change the calculated amount. The example reads the current invoice's document_net_balance rather than assuming the final amount due is 100.00.

Record the sandbox payment

POST /v1/invoices/{id}/payment records that calculated balance using the selected payment-mode ID and deposit account. It captures the payment's data.id and sends an Idempotency-Key derived from the run ID.

This records a receipt; it does not charge a card or initiate a bank transfer. The returned is_payment_approved flag is included in the output. Review any required approval in the sandbox before expecting the payment's final ledger effect.

For an approved untaxed receipt, the accounting effect is:

AccountDebitCredit
Selected cash/bank account100.00
Accounts receivable100.00

The example deliberately skips email delivery. You can learn document lifecycle and mail operations separately after confirming your company's workflow.

3. Inspect the ledger and reports

The final request is GET /v1/accounting/journals/for-entity with entity_type=invoice and the created invoice anchor as entity_id. The output includes the returned invoice journals and all created IDs.

Check the journal lines and posting state rather than treating an HTTP success as proof that every expected accounting effect occurred. Open the sandbox workspace to inspect the invoice history, payment approval, general ledger, trial balance, and P&L. No screenshot or sample total substitutes for that verification.

If a request fails

  • 401: exchange credentials again; check token expiry and the copied token URL.
  • 403: inspect the operation's required permissions and partner-domain binding.
  • 400 / 409 / 422: inspect the API error, your selected accounts, transaction locks, workflow transitions, and company settings. Do not automatically retry business validation errors.
  • 429: follow the rate-limit guidance, including the response's retry instructions.
  • Timeout, lost response, or unexpected JSON: stop and inspect the saved IDs and sandbox records. Account, customer, item, and invoice creation are not automatically replayed. Payment idempotency does not make the entire script idempotent.

The example stops at the first failure. It does not delete records, roll back writes, send email, or retry requests automatically. Avoid publishing terminal output containing your company data.

Next steps

Evaluate Paprel

Build in sandbox, launch with a production trial

Use sandbox for developer testing with no billing. When you are ready for real workflows, start production on a monthly plan with a 14-day free trial.

API-First Delivery
Audit-Ready Controls
Sandbox And Guided Rollout
We use cookies to improve your experience.

We use cookies and local storage for essential settings and, with your choices, analytics and advertising. Online identifiers and activity can be personal data. You can reject optional categories or change your choices.

These cookies are necessary for the basic functionality of the website, ensuring a seamless user experience. They cannot be disabled.