Your first accounting entry
This guide takes one merchant from nothing to a posted journal. It uses two kinds of token, and most first-integration errors come from mixing them up:
| Token | Get it from | Use it on | Lifetime |
|---|---|---|---|
| Partner token | POST /v1/partner/token | /v1/partner/* only | 900 seconds |
| Session token | POST /v1/partner/companies/{company_id}/sessions | The Public API, for one user in one company | 300 to 900 seconds, set on your credential |
A partner token cannot read or write accounting data, and a session token cannot manage companies.
You need:
- An approved partner credential. Ordinary sandbox signup does not issue one.
- Your partner identity domain, sent as
x-partner-domainon Public API calls. - A server with
curl,jqand Node.js 18 or later.
Working in your own language? These samples use plain HTTP. You can generate a typed Partner API client from openapi-partner.json with the same generators; see SDKs and client libraries.
The Partner API runs at https://api.paprel.com, so this guide creates a real company that counts toward your company limit. Give it an obvious test name. Clean up explains how to remove it.
export BASE="https://api.paprel.com"
export PAPREL_CLIENT_ID="<your client id>"
export PARTNER_DOMAIN="<your partner identity domain>"
1. Get a partner token
Skip to the second command if your credential uses client_secret_ip. Otherwise, save this as client-assertion.mjs. It prints a new signed assertion each time it runs:
import { createPrivateKey, randomUUID, sign } from 'node:crypto';
const b64url = value =>
Buffer.from(typeof value === 'string' ? value : JSON.stringify(value)).toString('base64url');
const key = createPrivateKey(process.env.PAPREL_PARTNER_PRIVATE_KEY_PEM);
const now = Math.floor(Date.now() / 1000);
const input =
b64url({ alg: 'EdDSA', typ: 'JWT', kid: process.env.PAPREL_PARTNER_KID }) + '.' +
b64url({
iss: process.env.PAPREL_CLIENT_ID,
sub: process.env.PAPREL_CLIENT_ID,
aud: 'https://api.paprel.com/v1/partner/token',
iat: now,
exp: now + 120,
jti: randomUUID(),
});
console.log(input + '.' + sign(null, Buffer.from(input), key).toString('base64url'));
Load PAPREL_PARTNER_PRIVATE_KEY_PEM and PAPREL_PARTNER_KID from your secret manager, then exchange an assertion for a token:
export PARTNER_TOKEN="$(curl --fail --silent --show-error "$BASE/v1/partner/token" \
--request POST \
--header 'content-type: application/json' \
--data "$(jq -n \
--arg client_id "$PAPREL_CLIENT_ID" \
--arg assertion "$(node client-assertion.mjs)" \
'{grant_type: "client_credentials", client_id: $client_id, client_assertion: $assertion}')" \
| jq -er '.data.access_token')"
With client_secret_ip, send the secret instead, from an allow-listed IP:
export PARTNER_TOKEN="$(curl --fail --silent --show-error "$BASE/v1/partner/token" \
--request POST \
--header 'content-type: application/json' \
--data "$(jq -n \
--arg client_id "$PAPREL_CLIENT_ID" \
--arg secret "$PAPREL_CLIENT_SECRET" \
'{grant_type: "client_credentials", client_id: $client_id, client_secret: $secret}')" \
| jq -er '.data.access_token')"
A 401 here does not say which check failed. See When it fails.
2. Provision the merchant company
Your own ids are the idempotency keys, so this call is safe to repeat with the same payload:
PROVISION="$(curl --fail --silent --show-error "$BASE/v1/partner/companies" \
--request POST \
--header "authorization: Bearer $PARTNER_TOKEN" \
--header 'content-type: application/json' \
--data '{
"companies": [{
"external_company_id": "test-merchant-0001",
"company_name": "TEST Corner Coffee LLC",
"country": "US",
"currency": "USD",
"locale": "en-US",
"timezone": "America/New_York",
"owner": { "external_user_id": "test-user-0001", "email": "owner@example.com", "name": "Alex Morgan" }
}]
}')"
printf '%s\n' "$PROVISION" | jq '.data[0]'
export COMPANY_ID="$(printf '%s' "$PROVISION" | jq -er '.data[0] | select(.outcome != "failed") | .company_id')"
A successful response has outcome created, or existing on a repeat:
{
"external_company_id": "test-merchant-0001",
"outcome": "created",
"company_id": "<company id>",
"owner_user_id": "<user id>"
}
The call returns 200 even when an item fails, so always read outcome. In production, store company_id and owner_user_id against your own ids.
3. Mint a session
Name the user the session acts for. There is no company-only session.
SESSION="$(curl --fail --silent --show-error "$BASE/v1/partner/companies/$COMPANY_ID/sessions" \
--request POST \
--header "authorization: Bearer $PARTNER_TOKEN" \
--header 'content-type: application/json' \
--data '{ "external_user_id": "test-user-0001" }')"
printf '%s\n' "$SESSION" | jq '.data[0] | {outcome, error, error_code, expires_in, expires_at, permissions}'
export SESSION_TOKEN="$(printf '%s' "$SESSION" | jq -er '.data[0] | select(.outcome == "minted") | .access_token')"
Now check that the session can post:
printf '%s' "$SESSION" | jq -e '.data[0].permissions
| any(. == "accounting:journal-add" or . == "accounting:journal-edit" or . == "role:admin")'
If this prints false, stop here. The user's role does not allow journal writes, or the session is read-only because the company has no subscription or is under a read-only licence. Fix the role or contact Paprel about the company's licence. Minting another session will not change the result.
If a later call returns 401, the session has probably expired. Run this step again, and repeat step 1 first if the partner token has expired too.
4. Read the chart of accounts
Every journal line needs an account UUID from this company. Account ids are not shared between companies, so never reuse one across merchants.
curl --fail --silent --show-error "$BASE/v1/accounting/accounts" \
--header "authorization: Bearer $SESSION_TOKEN" \
--header "x-partner-domain: $PARTNER_DOMAIN" \
| jq '.data[] | select(.is_archived != true) | {id, account, kind, account_subtype, currency}'
Choose an active cash or bank account and a revenue account in the company's currency. Do not use receivable or payable control accounts for a manual journal; document and payment workflows post to those.
export CASH_ACCOUNT_ID="<cash account id>"
export REVENUE_ACCOUNT_ID="<revenue account id>"
5. Post a journal
This records an $100.00 cash sale. meta_data ties the journal to the event in your system, which is how you find it again in step 6.
| Account | Debit | Credit |
|---|---|---|
| Cash | $100.00 | — |
| Sales Revenue | — | $100.00 |
JOURNAL="$(curl --fail --silent --show-error "$BASE/v1/accounting/journals" \
--request POST \
--header "authorization: Bearer $SESSION_TOKEN" \
--header "x-partner-domain: $PARTNER_DOMAIN" \
--header 'content-type: application/json' \
--data "$(jq -n \
--arg cash "$CASH_ACCOUNT_ID" \
--arg revenue "$REVENUE_ACCOUNT_ID" \
--arg date "$(date +%F)" \
'{
date: $date,
currency: "USD",
reference: "SALE-0001",
description: "Cash sale SALE-0001",
posted: true,
lines: [
{account_id: $cash, description: "Cash received", debit: "100.00"},
{account_id: $revenue, description: "Sales revenue", credit: "100.00"}
],
meta_data: {root_entity_type: "partner_sale", root_entity_id: "SALE-0001"}
}')")"
printf '%s\n' "$JOURNAL" | jq '.data.journal | {anchor_id, identifier, is_posted}'
export JOURNAL_ANCHOR_ID="$(printf '%s' "$JOURNAL" | jq -er '.data.journal.anchor_id')"
Run this once. Paprel does not deduplicate journals, so running it again posts a second entry.
Keep anchor_id. It is the journal's stable identity across versions. An unbalanced journal, or an accounting date blocked by a transaction lock, is rejected without reaching the ledger.
6. Verify the result
Read the journal back by its anchor:
curl --fail --silent --show-error "$BASE/v1/accounting/journals/$JOURNAL_ANCHOR_ID" \
--header "authorization: Bearer $SESSION_TOKEN" \
--header "x-partner-domain: $PARTNER_DOMAIN" \
| jq '.data | {anchor_id, identifier, is_posted, is_voided, lines: [.lines[] | {account_id, type, amount}]}'
is_posted should be true, with one debit line and one credit line of 100.00. You can also find the journal from your own event id:
curl --fail --silent --show-error --get "$BASE/v1/accounting/journals/for-entity" \
--data-urlencode 'entity_type=partner_sale' \
--data-urlencode 'entity_id=SALE-0001' \
--header "authorization: Bearer $SESSION_TOKEN" \
--header "x-partner-domain: $PARTNER_DOMAIN" \
| jq '.data[] | {anchor_id, identifier, is_posted}'
7. Clean up test companies
De-provisioning is permanent, so run it only on a company you created for testing. It frees the place in your limit, and the company's data is retained for the statutory period. The company must be suspended first:
curl --fail --silent --show-error "$BASE/v1/partner/companies/$COMPANY_ID/suspend" \
--request POST \
--header "authorization: Bearer $PARTNER_TOKEN"
curl --fail --silent --show-error "$BASE/v1/partner/companies/$COMPANY_ID/deprovision" \
--request POST \
--header "authorization: Bearer $PARTNER_TOKEN"
Before you run this in production
Tokens. Create a new assertion for each partner token request. Cache a partner token and renew it before 900 seconds. Renew a session from its expires_at, and keep your credential's private key or secret in a secret manager, on the server only.
Company isolation. Cache sessions by company and user together, never by user alone or in one shared slot. Load company_id, user_id and account ids from the merchant record you are processing. Test that one merchant's token cannot reach another merchant's records.
Retries. Not every POST behaves the same way after a timeout:
| Call | After a timeout |
|---|---|
| Partner token, session | Request a new one |
| Provision company, add user | Repeat with the same payload and external id |
| Suspend, resume, de-provision, deactivate | Repeat |
| Invoice or bill payment | Repeat with the same Idempotency-Key |
| Journal | Do not resend automatically. See below. |
For journals, keep at most one request in flight per event, using a durable per-event record or lock. Treat the journal as posted if you get a response or find it through GET /v1/accounting/journals/for-entity. A timeout followed by an empty lookup does not prove the write failed, because the first request may still be running. Send that event to manual reconciliation. root_entity_id is a join key, not a uniqueness constraint.
Errors.
| Response | What to do |
|---|---|
401 on a Public API call | Mint a new session and try once more, unless the request was a journal write that may have reached Paprel |
403 on a Public API call | Check the session's permissions. Do not retry. |
400 missing x-partner-domain, or 404 PARTNER_DOMAIN_NOT_ALLOWED | Fix your configuration |
403 PARTNER_OWNERSHIP_DENIED | The company or user is not yours, or the company was de-provisioned. Do not retry. |
PARTNER_COMPANY_SUSPENDED | Resume the company, then mint a new session |
409 PARTNER_LIMIT_REACHED, PARTNER_CONTACT_LIMIT_REACHED | Treat as a business outcome. Do not retry. |
429 | Wait as described in rate limits, then retry with a bound |
See API errors for the full catalogue, then work through the production checklist.
Next: sales, fees and settlements.