Create a billing plan
liveCreate a draft plan, or copy one with based_on_plan_id.
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 · requiredA new billing plan with its lines, variables and recipients, or, with based_on_plan_id, a copy of another plan (then only name, start_period, end_period, recipient_mode, object_type_id, recipient_partner_ids and external_ref may be sent; change the copy with a PATCH).
Details
Validation errors carry one details[] entry per problem with its pointer (e.g. /data/lines/2/dimensions/0/dimension_value_id), and context.path and context.issues[] in this schema's shape.
Most used attributes of data
First period billed (a first of month). Null means not chosen yet. The plan then saves as a draft, approving it needs a start, and a copy (based_on_plan_id) refuses null.
Values formulas refer to as var.<key>.
11 attributes of each item
number (with a unit) or boolean (reads as 1/0 in formulas).
One of number, boolean
timed: values by period, set on the plan. asked: given at every run. formula: computed from its formula at every run.
One of timed, asked, formula
Required for kind=formula; null otherwise. Uses system values and variables earlier in the submitted variable list; self and forward references are refused. Evaluated after system values, before lines, using Decimal precision 28.
For an asked number only: how a billing run computes the value it takes from a purchase invoice's chosen lines, a formula in the invoice context (see parseBillingFormula), e.g. sum_lines(line.amount / line.quantity) for a price per unit.
Details
Null: the chosen lines' sum, sum_lines(line.amount). Stored normalised; the default written out is stored as null.
For timed variables (may be empty while drafting); empty for asked.
3 attributes of each item
Lines, in invoice order.
22 attributes of each item
fixed: a quantity and price. formula: quantity formula × price formula per recipient. allocation: a total formula split across recipients by a weight formula.
One of fixed, formula, allocation
An existing line of this plan to keep; omit for a new line (BILLING_PLAN_LINE_NOT_FOUND otherwise).
The item the line bills; with price_source article its price is read at every run.
fixed lines: the price from this line (manual) or from the item (article), read at every run.
One of manual, article
fixed lines with price_source manual: net price per unit; null with article.
formula lines: the quantity per recipient, e.g. consumption.kulm_vesi.
formula lines: the price per unit, e.g. var.water_rate.
allocation lines: the amount to split, evaluated once for the plan; may use sum_objects.
allocation lines: each recipient's weight, e.g. prop.area_m2.
Who the line bills; null (or omitted) = every recipient of the plan.
When a consumption the line uses has no reading: stop the run (block), leave the line off that recipient's invoice (skip_line), or bill the last 3 periods' average, marked as an estimate (estimate).
One of block, skip_line, estimate
Bill a negative period consumption as 0, or with a negative amount.
One of zero, negative
Bill only objects whose boolean property has this value.
Bill only in periods where the plan's boolean variable has this value.
Dimension values on the line, at most one per dimension.
Days from the invoice date to the due date (when due_day_of_next_month is null).
Due on the last day of the invoice date's month, or the next month's last day when issued on month end. Counts from the invoice date on every run, regardless of the billed period. Cannot be combined with due_day_of_next_month; payment_term_days is ignored when true.
When set, invoices fall due on this day of the month after the billed period (the month's last day if shorter). If that date is on or before the invoice date, use this day of the month after the invoice date instead. payment_term_days is then ignored.
9 more attributes
Bill every in-use object of one type (object_type) or a list of contacts (partners).
One of object_type, partners
For object_type plans: the object type's contact properties in order; the invoice goes to the first one with a value on the object. May be empty on a draft; approval requires one.
The currency (ISO 4217) of every invoice the plan bills: the book currency, EUR, or another currency the company has activated. Each invoice converts into the book currency at the European Central Bank rate of its posting date, as an invoice made by hand does.
Details
A housing association's plan is in the book currency. Omitted on a new plan: the book currency; on a change: the plan's own.
Your own id for the plan, unique among this organization's plans.
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 | BillingPlan · An existing plan with this external_ref (on_conflict return or update). |
| 201 | BillingPlan · The created plan. |
| 400 | The request fails validation. This operation's own codes: BILLING_PLAN_INVALID, BILLING_PLAN_LINE_INVALID_KIND, FORMULA_PARSE_ERROR. |
| 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 | The token lacks a scope (INSUFFICIENT_SCOPE; WWW-Authenticate names it), the user's role or membership does not allow it (PERMISSION_DENIED, OPERATION_NOT_PERMITTED, ORG_MEMBERSHIP_REQUIRED, ORGANIZATION_MISMATCH), it needs a stronger sign-in (STEP_UP_REQUIRED), the feature is off for the organization (CAPABILITY_DISABLED), the organization's plan does not include the feature (PLAN_FEATURE_NOT_INCLUDED: write operations; for an API credential without the API feature, every operation that names an organization; context.capability names the feature and context.required_plan the plan that includes it), a demo company refuses it (DEMO_ORG_ACTION_BLOCKED), or a test copy of a company refuses handing out an e-MTA file (SANDBOX_ACTION_BLOCKED, context.action); FORBIDDEN when nothing more specific applies. |
| 404 | Not found. This operation's own codes: BILLING_PLAN_NOT_FOUND. |
| 409 | Conflicts with the resource's state. This operation's own codes: DUPLICATE_BILLING_PLAN_RECIPIENT, 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 |
|---|---|---|
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_INVALID | 400 | The billing plan has invalid fields. |
BILLING_PLAN_LINE_INVALID_KIND | 400 | This line's fields don't match its kind. |
FORMULA_PARSE_ERROR | 400 | The formula could not be parsed. |
BILLING_PLAN_NOT_FOUND | 404 | This billing plan could not be found. |
DUPLICATE_BILLING_PLAN_RECIPIENT | 409 | This partner is already in the list. |
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. |
4 more codes
WORK_MONTH_CONFIRM_REQUIRED | 409 | This change starts the plan year's working month, so the working month must be confirmed first. |
BILLING_PLAN_VARIABLE_KEY_LOCKED | 409 | This variable's key is in use and can no longer change. |
BILLING_PLAN_VARIABLE_IN_USE | 409 | A line uses this variable, so it can't be removed. |
BILLING_PLAN_LINE_NOT_FOUND | 400 | data.lines[].id: An existing line of this plan to keep; omit for a new line (BILLING_PLAN_LINE_NOT_FOUND otherwise). |
Plus the general codes every operation can answer (UNAUTHENTICATED, RATE_LIMITED …): handle them once.