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.

Replace the opening state

live
PUT/v1/opening-state
Scope ledger:writeOperation id replaceOpeningState

Set where the books start, as one document. Checked as a whole before anything is stored: balances must balance and open invoices and assets must tie to their accounts.

Details

Use dry_run=true to see the check without storing. Refused with 409 once an opening row has history of its own (OPENING_STATE_INVOICE_HAS_PAYMENTS, OPENING_STATE_INVOICE_HAS_CREDIT_NOTE, OPENING_STATE_INVOICE_IN_USE: a payment batch, a sent e-mail, a settlement, an advance or a billing run names an opening invoice, each listed with what holds it in context.blocked; OPENING_STATE_PREPAYMENTS_IN_USE, OPENING_STATE_FIXED_ASSETS_IN_USE).

Parameters

headers and query
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.

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
dataOpeningStateInputrequired

The opening state to set, replacing the one held. A section left out (open_invoices, prepayments, fixed_assets) is kept as it is, so a token whose scopes reach only the balances replaces only them; a section sent, even empty, is replaced, and needs the scopes that read and create that resource (invoices, payments or assets read and write; contacts:read for invoices and advances), else 403 INSUFFICIENT_SCOPE with its pointer.

Attributes of data

datestring (date)required

The balances date: every balance is as of the end of this day, and the books continue from the next.

accountsarray of OpeningAccountBalancerequired

Account balances; debits must equal credits. Accounts left out start at zero.

6 attributes of each item
account_idstring (uuid)required

The account.

debitstringrequireddecimal string

Debit balance; 0 when the balance is a credit.

creditstringrequireddecimal string

Credit balance; 0 when the balance is a debit.

currencystring · nullablepattern ^[A-Z]{3}$

The currency (ISO 4217) the account is kept in, its currency marker. Only on an account that has one, and then only that currency (FX_ACCOUNT_CURRENCY_MISMATCH); on any other account omitted, null or the book currency. Read back as the marker, null on an account without one.

foreign_amountstring · nullabledecimal string

On an account with a currency marker, its balance in that currency, signed as the debit balance (positive for a debit, negative for a credit, the side debit or credit is on).

Details

Required there whenever debit or credit is not 0 (FX_ACCOUNT_CURRENCY_MISMATCH), so the account's balance in its currency starts from the opening and not from zero. With debit and credit both 0, the book figure is worked out as foreign_amount at exchange_rate, rounded to the cent (5 000,00 USD at 1,1750 is a debit of 4 255,32). A balance of 0 has a book figure of 0 (EXCHANGE_RATE_OVERRIDE_INVALID). Refused on an account without a marker (FX_ACCOUNT_CURRENCY_MISMATCH). Read back as stored; with as_of, the account's balance in its currency on that day. Null on an account without a marker.

exchange_ratestring · nullabledecimal stringpattern ^([1-9][0-9]{0,14}(\.[0-9]{1,10})?|0\.([1-9][0-9]{0,9}|0[1-9][0-9]{0,8}|00[1-9][0-9]{0,7}|000[1-9][0-9]{0,6}|0000[1-9][0-9]{0,5}|00000[1-9][0-9]{0,4}|000000[1-9][0-9]{0,3}|0000000[1-9][0-9]{0,2}|00000000[1-9][0-9]?|000000000[1-9]))$

The rate the balance is held at, in ExchangeRate's direction (only on an account with a currency marker). Omitted or null: with a book figure stated in debit or credit, the rate the two amounts imply; without one, the ECB rate of the balances date (the opening state's date: cash and other monetary items are carried at the closing rate), the newest rate at or before it, at most 7 days back (EXCHANGE_RATE_MISSING when the bank has none).

Details

1 is refused (OPENING_STATE_FOREIGN_RATE_OF_ONE). Read back as stored; null with as_of and on an account without a marker or with a balance of 0.

open_invoicesarray of OpeningInvoice

Receivables and payables still open at the date, which must add up to the receivable and payable account balances.

11 attributes of each item
document_typestringrequired

A receivable (sales invoice) or a payable (purchase invoice).

One of sales_invoice, purchase_invoice

contact_idstring (uuid)required

Customer or supplier.

numberstringrequired1–255 characters

The invoice's original number.

datestring (date)required

Invoice date, on or before the opening date.

due_datestring (date)required

Due date.

currencystringrequiredpattern ^[A-Z]{3}$

Currency (ISO 4217): the book currency or another currency the company has activated (CURRENCY_NOT_ACTIVE). What is still open of a foreign invoice ties to the receivable or payable balance in the book currency, at its rate: the ECB rate of the balances date (EXCHANGE_RATE_MISSING when the bank has none), or the rate sent as exchange_rate.

totalstringrequireddecimal string

The invoice's original gross total.

amount_paidstringrequireddecimal string

Paid before the opening date.

external_refstring · nullable1–200 characters

Your own id for the invoice, unique among the organization's sales (or purchase) invoices; the created invoice carries it.

exchange_ratestring · nullabledecimal stringpattern ^([1-9][0-9]{0,14}(\.[0-9]{1,10})?|0\.([1-9][0-9]{0,9}|0[1-9][0-9]{0,8}|00[1-9][0-9]{0,7}|000[1-9][0-9]{0,6}|0000[1-9][0-9]{0,5}|00000[1-9][0-9]{0,4}|000000[1-9][0-9]{0,3}|0000000[1-9][0-9]{0,2}|00000000[1-9][0-9]?|000000000[1-9]))$

The rate the invoice was booked at in the source system, in ExchangeRate's direction; what is still open of it ties to the receivable or payable balance at this rate.

Details

Omitted or null: the ECB rate of the balances date (the opening state's date, the end of that day: the previous year-end closing rate, RTJ 1 p 94), the newest rate at or before it, at most 7 days back; never the invoice's own date nor the day before the balances date. On an invoice in the book currency only 1 is accepted (EXCHANGE_RATE_OVERRIDE_INVALID); on a foreign invoice 1 is refused (OPENING_STATE_FOREIGN_RATE_OF_ONE: it would book the amounts unconverted). Read back as the invoice's stored rate, 1 in the book currency, null on a foreign invoice that has none yet.

book_outstandingstring · nullabledecimal string

What is still open of it in the book currency, the figure that ties to the receivable or payable balance. Omitted or null: total less amount_paid, each converted at exchange_rate.

Details

Stated on an invoice in another currency: the source books' own figure, stored as it is, so later payments release exactly it (a cut-over of books where each payment released its own part can be a cent away from converting the open amount once). On an invoice in the book currency only total less amount_paid is accepted (EXCHANGE_RATE_OVERRIDE_INVALID); negative is refused (OPENING_STATE_NEGATIVE_AMOUNT). Read back as stored; with as_of, what the ledger holds open on that day (the book total less what each payment and credit note released), so the document ties to the cent. Null on an invoice in another currency that has no rate yet.

prepaymentsarray of OpeningPrepayment

Advances held at the date, which must add up, per account, to that account's balance.

9 attributes of each item
directionstringrequired

Received from a customer, or paid to a supplier.

One of received, paid

contact_idstring (uuid)required

Customer or supplier.

datestring (date)required

When it was paid, on or before the opening date.

amountstringrequireddecimal string

The amount still held at the opening date, in currency; greater than zero.

account_idstring (uuid)required

The account that holds it (received advances, paid advances); not the receivable or payable account.

external_refstring · nullable1–200 characters

Your own id for the advance.

currencystringpattern ^[A-Z]{3}$

Currency (ISO 4217) of amount: the book currency or another currency the company has activated (CURRENCY_NOT_ACTIVE). Omitted: the book currency.

exchange_ratestring · nullabledecimal stringpattern ^([1-9][0-9]{0,14}(\.[0-9]{1,10})?|0\.([1-9][0-9]{0,9}|0[1-9][0-9]{0,8}|00[1-9][0-9]{0,7}|000[1-9][0-9]{0,6}|0000[1-9][0-9]{0,5}|00000[1-9][0-9]{0,4}|000000[1-9][0-9]{0,3}|0000000[1-9][0-9]{0,2}|00000000[1-9][0-9]?|000000000[1-9]))$

The rate the advance is held at, in ExchangeRate's direction. Omitted or null: the ECB rate of the advance's own date, the day it was paid (it is never revalued, so the source books hold it at that day's euros), the newest rate at or before it, at most 7 days back (EXCHANGE_RATE_MISSING when the bank has none).

Details

On an advance in the book currency only 1 is accepted (EXCHANGE_RATE_OVERRIDE_INVALID); on one in another currency 1 is refused (OPENING_STATE_FOREIGN_RATE_OF_ONE). Read back as stored, 1 in the book currency.

book_amountstring · nullabledecimal string

What it is held at in the book currency, the figure that ties to its account's balance. Omitted or null: amount at exchange_rate. Stated on an advance in another currency: the source books' own figure, stored as it is (an advance part used before the cut-over holds the book value its uses left, not its remaining amount at the rate); greater than zero (OPENING_STATE_PREPAYMENT_INVALID).

Details

On an advance in the book currency only amount is accepted (EXCHANGE_RATE_OVERRIDE_INVALID). Read back as stored; with as_of, what the ledger holds of it on that day. Null on an advance in another currency that has no book value yet.

fixed_assetsarray of OpeningAssetInput

The asset register, which must add up to the asset and accumulated-depreciation account balances.

15 attributes of each item
group_idstring (uuid)required

The fixed-asset group. It supplies the depreciation and expense accounts and the method and life the asset leaves out.

namestringrequiredat least 1 character

Name.

acquisition_datestring (date)required

Date acquired, on or before the opening date.

acquisition_coststringrequireddecimal string

Cost basis.

opening_accumulated_depreciationstringrequireddecimal string

Depreciation charged before the opening date.

external_refstring · nullable1–200 characters

Your own id for the asset; the created asset carries it.

inventory_numberstring · nullable

Inventory tag, unique within the organization.

available_fromstring (date) · nullable

Ready for use from, when later than the acquisition.

methodstring · nullable

Depreciation method; the group's when left out. none is never depreciated (land).

One of straight_line, declining_balance, none

useful_life_monthsinteger · nullableat least 1

Useful life in months; the group's when left out.

residual_valuestring · nullabledecimal string

Value left at the end of the useful life.

annual_ratestring · nullabledecimal string

Yearly rate in percent for declining_balance, e.g. 40; the group's when left out.

asset_account_idstring (uuid) · nullable

Balance-sheet account of the asset; the group's when left out.

opening_depreciation_throughstring (date) · nullable

The last day the brought-forward depreciation covers, between the start of depreciation and the opening date; the months after it are charged by the runs here. Left out, the opening date (the earlier books charged every month up to it). Not for an asset whose depreciation starts after the opening date.

dimensionsarray of DimensionAssignment

Dimension values on its depreciation postings.

2 attributes of each item
dimension_idstring (uuid)required

The dimension.

value_idstring (uuid)required

The value within that dimension.

Responses

errors use the error envelope
200OpeningState · The stored opening state.
400The request fails validation. This operation's own codes: CURRENCY_NOT_ACTIVE, EXCHANGE_RATE_MISSING, EXCHANGE_RATE_OVERRIDE_INVALID, FX_ACCOUNT_CURRENCY_MISMATCH, OPENING_STATE_AS_OF_DATE_INVALID, OPENING_STATE_CONTROL_ACCOUNT_UNRESOLVED, OPENING_STATE_DUPLICATE_ENTRY, OPENING_STATE_FIXED_ASSET_INVALID, OPENING_STATE_FOREIGN_RATE_OF_ONE, OPENING_STATE_INVALID_ACCOUNT_TYPE, OPENING_STATE_LINES_TOTAL_MISMATCH, OPENING_STATE_NEGATIVE_AMOUNT, OPENING_STATE_NO_ZERO_TAX_CODE, OPENING_STATE_PREPAYMENT_INVALID, OPENING_STATE_RECEIVED_PREPAYMENT_VAT, OPENING_STATE_SUBLEDGER_MISMATCH, OPENING_STATE_UNBALANCED, OPENING_STATE_UNRESOLVED_REF.
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.
409Conflicts with the resource's state. This operation's own codes: EXTERNAL_REF_EXISTS, EXTRA_MONTH_CONFIRM_REQUIRED, OPENING_STATE_BOOKS_BEFORE_OPENING, OPENING_STATE_FIXED_ASSETS_IN_USE, OPENING_STATE_IMPORTED, OPENING_STATE_INVOICE_HAS_CREDIT_NOTE, OPENING_STATE_INVOICE_HAS_PAYMENTS, OPENING_STATE_INVOICE_IN_USE, OPENING_STATE_INVOICE_NUMBER_COLLISION, OPENING_STATE_PREPAYMENTS_IN_USE, 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
OPENING_STATE_INVOICE_HAS_PAYMENTS409Refused with 409 once an opening row has history of its own (OPENING_STATE_INVOICE_HAS_PAYMENTS, OPENING_STATE_INVOICE_HAS_CREDIT_NOTE, OPENING_STATE_INVOICE_IN_USE: a payment batch, a sent e-mail, a settlement, an advance or a billing run names an opening invoice, each listed with what holds it in context.blocked; OPENING_STATE_PREPAYMENTS_IN_USE, OPENING_STATE_FIXED_ASSETS_IN_USE).
OPENING_STATE_INVOICE_HAS_CREDIT_NOTE409Refused with 409 once an opening row has history of its own (OPENING_STATE_INVOICE_HAS_PAYMENTS, OPENING_STATE_INVOICE_HAS_CREDIT_NOTE, OPENING_STATE_INVOICE_IN_USE: a payment batch, a sent e-mail, a settlement, an advance or a billing run names an opening invoice, each listed with what holds it in context.blocked; OPENING_STATE_PREPAYMENTS_IN_USE, OPENING_STATE_FIXED_ASSETS_IN_USE).
OPENING_STATE_INVOICE_IN_USE409Refused with 409 once an opening row has history of its own (OPENING_STATE_INVOICE_HAS_PAYMENTS, OPENING_STATE_INVOICE_HAS_CREDIT_NOTE, OPENING_STATE_INVOICE_IN_USE: a payment batch, a sent e-mail, a settlement, an advance or a billing run names an opening invoice, each listed with what holds it in context.blocked; OPENING_STATE_PREPAYMENTS_IN_USE, OPENING_STATE_FIXED_ASSETS_IN_USE).
OPENING_STATE_PREPAYMENTS_IN_USE409Refused with 409 once an opening row has history of its own (OPENING_STATE_INVOICE_HAS_PAYMENTS, OPENING_STATE_INVOICE_HAS_CREDIT_NOTE, OPENING_STATE_INVOICE_IN_USE: a payment batch, a sent e-mail, a settlement, an advance or a billing run names an opening invoice, each listed with what holds it in context.blocked; OPENING_STATE_PREPAYMENTS_IN_USE, OPENING_STATE_FIXED_ASSETS_IN_USE).
OPENING_STATE_FIXED_ASSETS_IN_USE409Refused with 409 once an opening row has history of its own (OPENING_STATE_INVOICE_HAS_PAYMENTS, OPENING_STATE_INVOICE_HAS_CREDIT_NOTE, OPENING_STATE_INVOICE_IN_USE: a payment batch, a sent e-mail, a settlement, an advance or a billing run names an opening invoice, each listed with what holds it in context.blocked; OPENING_STATE_PREPAYMENTS_IN_USE, OPENING_STATE_FIXED_ASSETS_IN_USE).
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.
OPENING_STATE_AS_OF_DATE_INVALID400Check the as-of date — it's missing, or an invoice date falls after it.
OPENING_STATE_CONTROL_ACCOUNT_UNRESOLVED400A default receivable/payable account must be configured before importing open invoices.
23 more codes
OPENING_STATE_DUPLICATE_ENTRY400The import contains duplicate rows — each account, partner, and invoice may appear only once.
OPENING_STATE_FIXED_ASSET_INVALID400A fixed-asset card is incomplete or invalid — check its details.
OPENING_STATE_INVALID_ACCOUNT_TYPE400One of the accounts has an invalid account type.
OPENING_STATE_LINES_TOTAL_MISMATCH400An invoice's line amounts don't add up to its total.
OPENING_STATE_NO_ZERO_TAX_CODE400No zero/exempt tax code is configured for this organization.
OPENING_STATE_RECEIVED_PREPAYMENT_VAT400An advance received by a VAT-registered company cannot be carried into the opening balances yet — its final invoice would declare the VAT again.
OPENING_STATE_SUBLEDGER_MISMATCH400Open invoice totals don't tie to the control account's opening balance.
OPENING_STATE_UNBALANCED400The trial balance doesn't balance — debits and credits must be equal.
OPENING_STATE_UNRESOLVED_REF400Some accounts or partners referenced in this import couldn't be resolved.
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.
OPENING_STATE_BOOKS_BEFORE_OPENING409The books already hold entries, a closed period or a filed VAT return on or before the opening date — the opening balances would count twice.
OPENING_STATE_IMPORTED409The imported ledger already contains the opening balances — entered again they would count twice.
OPENING_STATE_INVOICE_NUMBER_COLLISION409Some opening invoice numbers already exist on this organization's invoices — rename or remove them first.
WORK_MONTH_CONFIRM_REQUIRED409This change starts the plan year's working month, so the working month must be confirmed first.
CURRENCY_NOT_ACTIVE400data.open_invoices[].currency: Currency (ISO 4217): the book currency or another currency the company has activated (CURRENCY_NOT_ACTIVE).
EXCHANGE_RATE_MISSING400data.accounts[].exchange_rate: Omitted or null: with a book figure stated in debit or credit, the rate the two amounts imply; without one, the ECB rate of the balances date (the opening state's date: cash and other monetary items are carried at the closing rate), the newest rate at or before it, at most 7 days back (EXCHANGE_RATE_MISSING when the bank has none).
EXCHANGE_RATE_OVERRIDE_INVALID400data.accounts[].foreign_amount: A balance of 0 has a book figure of 0 (EXCHANGE_RATE_OVERRIDE_INVALID).
FX_ACCOUNT_CURRENCY_MISMATCH400data.accounts[].currency: Only on an account that has one, and then only that currency (FX_ACCOUNT_CURRENCY_MISMATCH); on any other account omitted, null or the book currency.
OPENING_STATE_FOREIGN_RATE_OF_ONE400data.accounts[].exchange_rate: 1 is refused (OPENING_STATE_FOREIGN_RATE_OF_ONE).
OPENING_STATE_NEGATIVE_AMOUNT400data.open_invoices[].book_outstanding: On an invoice in the book currency only total less amount_paid is accepted (EXCHANGE_RATE_OVERRIDE_INVALID); negative is refused (OPENING_STATE_NEGATIVE_AMOUNT).
OPENING_STATE_PREPAYMENT_INVALID400data.prepayments[].book_amount: Stated on an advance in another currency: the source books' own figure, stored as it is (an advance part used before the cut-over holds the book value its uses left, not its remaining amount at the rate); greater than zero (OPENING_STATE_PREPAYMENT_INVALID).
INSUFFICIENT_SCOPE403data: A section left out (open_invoices, prepayments, fixed_assets) is kept as it is, so a token whose scopes reach only the balances replaces only them; a section sent, even empty, is replaced, and needs the scopes that read and create that resource (invoices, payments or assets read and write; contacts:read for invoices and advances), else 403 INSUFFICIENT_SCOPE with its pointer.

Plus the general codes every operation can answer (UNAUTHENTICATED, RATE_LIMITED …): handle them once.