Create a billing run
liveStart billing a period. Answers 202 with the run; poll it until status is final. With dry_run=true the run is computed and returned, nothing stored: review its recipients and blockers, then start it with expected_fingerprint.
Details
A run already open for the plan and period is 409 BILLING_RUN_IN_PROGRESS with existing_id; starting a finished period again re-runs it (issued invoices are kept, drafts replaced).
Parameters
headers and queryOptional replay guard for a POST (DA-065). Send a key the CLIENT generates (a uuid per user-initiated request, reused across retries of that same request). The server performs the operation at most once per (organization, key) and answers a replay with the ORIGINAL response (status, headers and body), so a double-clicked Save or a retry after an ambiguous timeout never creates or posts anything twice.
Details
A request that FAILED frees its key, so retrying after a genuine error proceeds normally. Reusing a key with a DIFFERENT body is a client bug, not a retry, and returns 409 IDEMPOTENCY_KEY_REUSED rather than the earlier response. Keys are kept for 24 hours; a retry after that is a new request. Omitting the header keeps the previous behaviour exactly.
Validate and compute without storing anything: the answer is what the real request would answer (status, errors, computed totals, assigned numbers) but nothing is saved, posted or sent, and the response carries Tracken-Dry-Run: true.
Request body
application/json · requiredBill one period of a plan.
Attributes of data
Leave draft invoices, issue them, or issue and email them. Issuing also needs permission to write sales invoices (invoices:write).
One of draft, issue, issue_send
Values for the plan's asked variables, and overrides of timed ones.
6 attributes of each item
The value, as a decimal string with at most 6 decimal places (a 7th is refused); it is stored and read back as sent, never rounded to fewer. Null with purchase_invoice_id: the variable's invoice formula over the chosen lines (invoice_formula on the plan variable; the lines' sum when it has none), computed by the server and kept to 6 places, half-even.
Details
A value sent with purchase_invoice_id must equal that result exactly.
Whether the purchase invoice lines are read with their VAT (included, the default) or without it: the line.amount of the invoice formula.
One of included, excluded
For a plan in a currency the European Central Bank publishes no rate for: the rate every draft of the run is booked at, in ExchangeRate's direction, recorded as a manual rate and kept when the draft is issued.
Details
Used only when no ECB rate exists for the day the drafts convert on (the run's posting date); where one does, or for a plan in the book currency, the run is refused (EXCHANGE_RATE_OVERRIDE_INVALID). Omitted: the ECB's rate of that day.
What a create does when a record of the same resource already holds the sent external_ref. error: 409 EXTERNAL_REF_EXISTS with existing_id. return: 200 with the existing record, unchanged.
One of error, return, update
Details
update: apply the sent fields to it as a PATCH would and answer 200; refused like a PATCH when the record is no longer editable.
Responses
errors use the error envelope| 200 | BillingRun · dry_run=true: the run as it would be made, with its recipients, totals, blockers and fingerprint. Nothing is stored. Also an existing run with this external_ref (on_conflict return). |
| 202 | BillingRun · Accepted; the run is queued and runs in the background. |
| 400 | The request fails validation. This operation's own codes: BILLING_PLAN_VARIABLE_INVOICE_FORMULA_INVALID, BILLING_RUN_BLOCKED, BILLING_RUN_DUE_BEFORE_INVOICE_DATE, BILLING_RUN_INPUT_MISSING, BILLING_RUN_PERIOD_NOT_COVERED, BILLING_RUN_PLAN_NOT_APPROVED, BILLING_RUN_POSTING_PERIOD_CLOSED, BILLING_RUN_PURCHASE_FORMULA_NO_VALUE, BILLING_RUN_PURCHASE_INVOICE_INVALID, EXCHANGE_RATE_OVERRIDE_INVALID. |
| 401 | No token, an expired token, or a token for another audience (UNAUTHENTICATED). |
| 402 | The organization's subscription is not active (SUBSCRIPTION_INACTIVE): the trial ended without a plan, a payment is overdue, the subscription was cancelled, or the accounting firm that paid for it stopped. context.reason says which (trial_ended, not_paid, cancelled, payer_stopped; accept values you do not know) and context.export_until the last day (ISO date) the organization's data can still be exported. Every operation is refused, reads included, except reading the current user and the organization and the data export. A retry unchanged fails the same way: an owner reopens the subscription in the app. |
| 403 | Not allowed. This operation's own codes: OPERATION_NOT_PUBLIC. |
| 404 | Not found. This operation's own codes: BILLING_PLAN_NOT_FOUND. |
| 409 | Conflicts with the resource's state. This operation's own codes: BILLING_RUN_IN_PROGRESS, BILLING_RUN_RESULT_CHANGED, EXTERNAL_REF_EXISTS, EXTRA_MONTH_CONFIRM_REQUIRED, WORK_MONTH_CONFIRM_REQUIRED. An API credential cannot confirm a month: a person confirms it in the app, then retry the request unchanged, with the same Idempotency-Key; context names the month, its price and currency. |
| 429 | Rate limit exceeded (RATE_LIMITED). Wait Retry-After seconds. |
Errors this operation can return
switch oncode, never on message| Code | Status | When |
|---|---|---|
BILLING_RUN_IN_PROGRESS | 409 | A run already open for the plan and period is 409 BILLING_RUN_IN_PROGRESS with existing_id; starting a finished period again re-runs it (issued invoices are kept, drafts replaced). |
IDEMPOTENCY_KEY_REUSED | 409 | Idempotency-Key: Reusing a key with a DIFFERENT body is a client bug, not a retry, and returns 409 IDEMPOTENCY_KEY_REUSED rather than the earlier response. |
BILLING_PLAN_VARIABLE_INVOICE_FORMULA_INVALID | 400 | Check the variable's formula over the invoice. |
BILLING_RUN_BLOCKED | 400 | Invoices cannot be created until the problems are fixed. |
BILLING_RUN_DUE_BEFORE_INVOICE_DATE | 400 | The due date cannot be before the invoice date. |
BILLING_RUN_INPUT_MISSING | 400 | Enter every value the billing plan asks for when creating invoices. |
BILLING_RUN_PERIOD_NOT_COVERED | 400 | The billing plan is not in force for this period. |
BILLING_RUN_PLAN_NOT_APPROVED | 400 | Invoices can only be created from an approved billing plan. |
10 more codes
BILLING_RUN_POSTING_PERIOD_CLOSED | 400 | The posting date is in a closed accounting period. |
BILLING_RUN_PURCHASE_FORMULA_NO_VALUE | 400 | The formula gives no value from the chosen purchase invoice lines, e.g. a line's quantity is zero. |
BILLING_RUN_PURCHASE_INVOICE_INVALID | 400 | The chosen purchase invoice lines do not give this amount. |
OPERATION_NOT_PUBLIC | 403 | The operation is not part of the public API: the Tracken Accounts app may call it, API keys and scope-narrowed tokens may not. |
BILLING_PLAN_NOT_FOUND | 404 | This billing plan could not be found. |
BILLING_RUN_RESULT_CHANGED | 409 | expected_fingerprint: If the result would differ now, the run is refused with BILLING_RUN_RESULT_CHANGED and creates nothing. |
EXTERNAL_REF_EXISTS | 409 | on_conflict: error: 409 EXTERNAL_REF_EXISTS with existing_id. |
EXTRA_MONTH_CONFIRM_REQUIRED | 409 | This change falls outside the working month, so this month is billed separately. |
WORK_MONTH_CONFIRM_REQUIRED | 409 | This change starts the plan year's working month, so the working month must be confirmed first. |
EXCHANGE_RATE_OVERRIDE_INVALID | 400 | data.exchange_rate: Used only when no ECB rate exists for the day the drafts convert on (the run's posting date); where one does, or for a plan in the book currency, the run is refused (EXCHANGE_RATE_OVERRIDE_INVALID). |
Plus the general codes every operation can answer (UNAUTHENTICATED, RATE_LIMITED …): handle them once.