Choose what you allow. Your choice applies on every tracken.ee address and you can change it any time with “Cookie settings” in the footer.

Remember your cookie choice, language and theme. Without them the site doesn't work the way you chose.

A cookie with your choice (6 months); language and theme in browser storage.


The services below learn that you visited this site, whether you came from their ad and whether you then created a Tracken account. That shows us which ads work, and these companies may show you Tracken ads later. They may link the data to your account with them. For Meta, Tracken ID's server reports the new account and also sends a hash of your e-mail address, your IP address and browser details.

ServiceCookiesKept for up to
Meta (Facebook, Instagram)_fbp, _fbc90 days

Tracken's own visit counter uses no cookies, stores no IP addresses and shares nothing with anyone. Privacy policy

Skip to content
Beta
BetaThe Tracken Accounts API is in beta: it may still change before v1, and every change is announced in the changelog.
API referenceDocuments of recordBilling

Update a billing plan

live
PATCH/v1/billing-plans/{id}
Scope billing:writeOperation id updateBillingPlan

Change a plan. An edit that would alter invoiced periods needs effective_from and creates a new revision; the plan keeps its id. Only sent fields change; null clears a nullable field. Send If-Match with the ETag you last saw to refuse a lost update (412).

Parameters

headers and query and path
If-Matchheader · stringat most 1024 characters

Optional optimistic-concurrency guard for an update. Send the ETag the resource's GET returned; when the resource has changed since, the update is refused with 412 PRECONDITION_FAILED and nothing is written, so a client never overwrites a change it has not seen.

Details

* matches any current version. Weak ETags (W/"...") never match: If-Match compares strongly. Omitting the header applies the update unconditionally.

dry_runquery · booleandefault false

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.

idpath · string (uuid)required

The plan.

Tracken-On-Behalf-Ofheader · stringat most 200 characters

For an app's installation token: the person the app acts for (its own user id and name, e.g. res_123 Mari Maasikas). Recorded in the audit log beside the app; never used for access, which the app enforces.

Request body

application/json · required
dataBillingPlanPatchrequired

Fields to change; only sent fields change. lines and variables are whole lists (see BillingPlanLineInput).

Most used attributes of data

variablesarray of BillingPlanVariableInput

The whole list of variables.

11 attributes of each item
keystringrequired1–63 characters

Machine name formulas use as var.<key>.

namestringrequired1–200 characters

Name shown to people.

value_typestringrequired

number (with a unit) or boolean (reads as 1/0 in formulas).

One of number, boolean

kindstringrequired

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

idstring (uuid) · nullable

An existing variable of this plan to keep; omit for a new one.

unitstring · nullableat most 32 characters

Unit of a number, e.g. EUR/m3; null for a boolean.

formulastring · nullableat most 2000 characters

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.

invoice_formulastring · nullableat most 2000 characters

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.

guidancestring · nullableat most 500 characters

For asked variables, the hint shown at the run.

needs_reviewbooleandefault false

Set by a copy on its shifted values; send false to clear it.

segmentsarray of BillingPlanVariableSegmentdefault []

For timed variables (may be empty while drafting); empty for asked.

3 attributes of each item
start_periodstring (date)required

First period the value applies to (a first of month).

end_periodstring (date) · nullablerequired

Last period, inclusive; null means onwards.

valuestringrequireddecimal string

The value, a decimal string with at most 4 fraction digits; "1"/"0" for a boolean variable.

linesarray of BillingPlanLineInput

The whole list of lines, in invoice order.

22 attributes of each item
line_kindstringrequired

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

labelstringrequired

Line text on the invoice.

idstring (uuid) · nullable

An existing line of this plan to keep; omit for a new line (BILLING_PLAN_LINE_NOT_FOUND otherwise).

sort_orderinteger

Ignored; the line's place is its place in the list.

tax_code_idstring (uuid) · nullable

Tax code of the invoice line.

account_idstring (uuid) · nullable

Revenue account of the invoice line.

item_idstring (uuid) · nullable

The item the line bills; with price_source article its price is read at every run.

price_sourcestringdefault "manual"

fixed lines: the price from this line (manual) or from the item (article), read at every run.

One of manual, article

quantitystring · nullabledecimal string

fixed lines: quantity per recipient.

unitstring · nullable

Unit of measure.

unit_pricestring · nullabledecimal string

fixed lines with price_source manual: net price per unit; null with article.

qty_formulastring · nullableat most 2000 characters

formula lines: the quantity per recipient, e.g. consumption.kulm_vesi.

price_formulastring · nullableat most 2000 characters

formula lines: the price per unit, e.g. var.water_rate.

total_formulastring · nullableat most 2000 characters

allocation lines: the amount to split, evaluated once for the plan; may use sum_objects.

weight_formulastring · nullableat most 2000 characters

allocation lines: each recipient's weight, e.g. prop.area_m2.

is_activebooleandefault true

An inactive line stays on the plan and bills nothing.

recipient_filterBillingPlanLineRecipientFilterInput · nullable

Who the line bills; null (or omitted) = every recipient of the plan.

2 attributes of recipient_filter
modestringrequired

Every recipient of the plan, or only the listed ones.

One of all, selected

recipient_idsarray of string (uuid)default []

Required (non-empty) when mode=selected; must be empty when mode=all.

missing_reading_policystringdefault "block"

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

negative_consumptionstringdefault "zero"

Bill a negative period consumption as 0, or with a negative amount.

One of zero, negative

condition_propertyBillingPlanLinePropertyCondition · nullable

Bill only objects whose boolean property has this value.

2 attributes of condition_property
property_keystringrequired

A boolean property of the plan's object type.

equalsbooleanrequired

The value that bills the line.

condition_variableBillingPlanLineVariableCondition · nullable

Bill only in periods where the plan's boolean variable has this value.

2 attributes of condition_variable
variable_keystringrequired

A boolean variable of the plan.

equalsbooleanrequired

The value that bills the line.

dimensionsarray of BillingPlanLineDimensiondefault []

Dimension values on the line, at most one per dimension.

2 attributes of each item
dimension_idstring (uuid)required

The dimension.

dimension_value_idstring (uuid) · nullablerequired

Its value on the line; null only for the object type's own dimension (each recipient's object).

namestring

Name.

cadencestring

How often a run bills.

One of monthly, quarterly, yearly

payment_term_daysintegerat least 0

Days from the invoice date to the due date.

due_end_of_monthboolean

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.

due_day_of_next_monthinteger · nullable1–31

Due on this day of the next month instead; null to use payment_term_days.

start_periodstring (date) · nullable

First period billed (a first of month); null only on a draft.

8 more attributes
end_periodstring (date) · nullable

Last period billed; null means open-ended.

recipient_modestring

object_type or partners.

One of object_type, partners

object_type_idstring (uuid) · nullable

For object_type plans, the object type.

recipient_partner_idsarray of string (uuid)

For partners plans, the contacts billed.

bill_to_property_keysarray of string

For object_type plans, the contact properties that name the payer, in order.

zero_linesstring

Whether lines that come to zero appear on invoices.

One of hide, show

currencystringat most 3 characterspattern ^[A-Z]{3}$

The currency (ISO 4217) of the invoices the plan bills from now on: the book currency or another currency the company has activated. On a plan with issued invoices the change is a new revision (effective_from), like any change to what is billed.

external_refstring · nullable1–200 characters

Your own id for the plan; null removes it.

effective_fromstring (date) · nullable

When the change would alter periods already invoiced (an approved plan with issued invoices): the first period the new revision bills, a first of month at or after next_revision_from.

Details

Without it such a change is refused with BILLING_PLAN_REVISION_REQUIRED. On an approved plan without that need it starts a new revision from that period.

Responses

errors use the error envelope
200BillingPlan · The plan as saved, in its current revision.
400The request fails validation. This operation's own codes: BILLING_PLAN_INVALID, BILLING_PLAN_LINE_NOT_FOUND, FORMULA_PARSE_ERROR.
401No token, an expired token, or a token for another audience (UNAUTHENTICATED).
402The 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.
403The 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.
404Not found. This operation's own codes: BILLING_PLAN_NOT_FOUND.
409Conflicts with the resource's state. This operation's own codes: BILLING_PLAN_CURRENCY_LOCKED, BILLING_PLAN_LINE_NOT_DELETABLE, BILLING_PLAN_REVISION_REQUIRED, BILLING_PLAN_VARIABLE_IN_USE, BILLING_PLAN_VARIABLE_KEY_LOCKED, DUPLICATE_BILLING_PLAN_RECIPIENT, EXTERNAL_REF_EXISTS, EXTRA_MONTH_CONFIRM_REQUIRED, PLAN_REVISION_SUPERSEDED, 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.
412If-Match did not match: the record changed since you read it (PRECONDITION_FAILED).
429Rate limit exceeded (RATE_LIMITED). Wait Retry-After seconds.

Errors this operation can return

switch on code, never on message
CodeStatusWhen
PRECONDITION_FAILED412If-Match: Send the ETag the resource's GET returned; when the resource has changed since, the update is refused with 412 PRECONDITION_FAILED and nothing is written, so a client never overwrites a change it has not seen.
BILLING_PLAN_INVALID400The billing plan has invalid fields.
FORMULA_PARSE_ERROR400The formula could not be parsed.
BILLING_PLAN_NOT_FOUND404This billing plan could not be found.
BILLING_PLAN_CURRENCY_LOCKED409Invoices have been issued from this plan, so its currency can no longer change.
BILLING_PLAN_LINE_NOT_DELETABLE409Invoices have been created from this plan, so a line can no longer be deleted.
BILLING_PLAN_REVISION_REQUIRED409effective_from: Without it such a change is refused with BILLING_PLAN_REVISION_REQUIRED.
BILLING_PLAN_VARIABLE_IN_USE409A line uses this variable, so it can't be removed.
7 more codes
BILLING_PLAN_VARIABLE_KEY_LOCKED409This variable's key is in use and can no longer change.
DUPLICATE_BILLING_PLAN_RECIPIENT409This partner is already in the list.
EXTERNAL_REF_EXISTS409A record of this resource already carries the external_ref you sent.
EXTRA_MONTH_CONFIRM_REQUIRED409This change falls outside the working month, so this month is billed separately.
PLAN_REVISION_SUPERSEDED409This plan revision has been superseded by a newer one and can no longer be edited.
WORK_MONTH_CONFIRM_REQUIRED409This change starts the plan year's working month, so the working month must be confirmed first.
BILLING_PLAN_LINE_NOT_FOUND400data.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.