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 recordPurchases

Create a purchase invoice

live
POST/v1/purchase-invoices
Scope invoices:writeMCP tool create_purchase_invoiceOperation id createPurchaseInvoice

Register a supplier's invoice or credit note as a draft. A credit note naming the invoice it credits (kind: credit_note, credits_invoice_id) copies that invoice's lines unless lines is sent. Nothing is booked until :post.

Parameters

headers and query
Idempotency-Keyheader · stringat most 255 characters

Optional 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.

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

The record.

Most used attributes of data

datestring (date)required

Document date, as printed.

due_datestring (date)required

Payment due date; not before date.

partyPurchaseInvoiceParty · nullable

The supplier as the invoice names it, when not as the contact has it.

5 attributes of party
namestringrequired

Name.

registry_codestring · nullable

Register code.

vat_numberstring · nullable

VAT number.

addressstring · nullable

Address as one line of text.

emailstring · nullable

Email.

linesarray of PurchaseInvoiceLineInputat most 500 items

The lines, in order.

11 attributes of each item
namestringrequired1–255 characters

Line text, as printed.

quantitystringrequireddecimal string

Quantity; negative for a supplier's return row.

unitstringrequiredat most 50 characters

Unit of measure.

unit_pricestringrequireddecimal string

Net price per unit, as the supplier printed it; may be negative (a discount row). A document whose total is below zero is refused (INVOICE_TOTAL_NEGATIVE); register it as a credit note.

tax_code_idstring (uuid)required

The line's VAT code; its rate on the invoice date is frozen on the line.

account_idstring (uuid)required

The expense or asset account. Never the organization's accounts payable or receivable control account (400 PURCHASE_LINE_CONTROL_ACCOUNT at the line), except a kept line that stays on the account it already has.

idstring (uuid)

Keep the line with this id (from the invoice's lines); omit it for a new line.

item_idstring (uuid) · nullable

The item the line is for, if any.

descriptionstring · nullableat most 1000 characters

Longer text under the name.

dimensionsarray of DimensionAssignmentat most 50 items

Dimension values on the line.

2 attributes of each item
dimension_idstring (uuid)required

The dimension.

value_idstring (uuid)required

The value within that dimension.

tax_amountstring · nullabledecimal string

The line's VAT as the document states it. Kept only on a historical create -- one that links its imported transaction_id, or is dated before the organization's opening date; the document's VAT is then these figures, not the ones its codes derive.

Details

On any other write it may only repeat the VAT the line derives (a read sent back), and is not stored; another figure is 400 VALIDATION_ERROR by pointer. A line with no VAT rate states none; the VAT sits on the line value's side of zero.

posting_datestring (date) · nullable

The date to book the invoice at (its ledger entry, period and VAT return), when not date. Omitted or null: date.

currencystring3–3 characters

Document currency (ISO 4217). Omitted means EUR.

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]))$

State the rate instead of the European Central Bank's. Omitted keeps a stated rate; null returns to the bank's. Refused on a document in the book currency and on a credit note, which uses its invoice's rate (EXCHANGE_RATE_OVERRIDE_INVALID).

Details

With no bank rate for the date and none stated, 400 EXCHANGE_RATE_MISSING. On an issued create linked to an imported transaction (transaction_id) it is the source system's rate: the document ties to that journal at it, within a cent per VAT group, and keeps it as an imported rate; omitted there, the rate is the one the journal was booked at.

book_tax_totalstring · nullabledecimal string

The VAT in the book currency as the seller states it, of the supply: a prepayment deduction keeps its prepayment's VAT, so the invoice's stored book_tax_total is this figure less the deducted VAT.

Details

Between 0 and twice the supply's converted VAT, else 400 BOOK_TAX_TOTAL_OUT_OF_RANGE. Omitted keeps a stated figure while the document's VAT is unchanged; null returns to the converted figure.

10 more attributes
contact_idstring (uuid) · nullable

The supplier. Its name and identifiers are copied onto the invoice unless party gives them. Required to post.

supplier_invoice_numberstring · nullableat most 50 characters

The number printed on the supplier's invoice; required to post.

notesstring · nullableat most 5000 characters

Free-text notes.

payment_referencestring · nullableat most 140 characters

The supplier's reference to pay with. An Estonian 7-3-1 or RF reference is stored without spaces; anything else is kept as sent.

kindstring

Document kind. Omitted means invoice.

One of invoice, credit_note

credits_invoice_idstring (uuid) · nullable

Only with kind: credit_note: the posted invoice of this supplier that the credit note credits. Without lines it credits all of it; the lines keep that invoice's VAT rates either way.

rounding_amountstring · nullabledecimal string

A VAT-free rounding added to the total so it equals the printed one, e.g. -0.02; whole cents. Omitted or null means none.

external_refstring · nullable1–200 characters

Your id for this invoice, unique among the organization's purchase invoices.

statusstring

draft (the default) registers a draft; issued creates a historical document a migration brings over: it links the imported transaction that booked it (transaction_id, required), keeps its number, dates and stated line VAT, posts and sends nothing, and reads origin: import.

One of draft, issued

transaction_idstring (uuid) · nullable

With status: issued: the imported transaction (origin: import, posted by no document) that booked this document, dated on its posting date, whose receivable (sales) or payable (purchases) lines name this contact or none and move exactly its total in its direction (an invoice debits a receivable and credits a payable, a credit note the reverse).

Details

400 INVOICE_TRANSACTION_NOT_LINKABLE otherwise. The transaction is only linked, never changed. Refused (400 INVOICE_TRANSACTION_NOT_LINKABLE) as well: a transaction any lines of which carry a VAT code (the return would count them beside the invoice), whose VAT accounts do not move the invoice's VAT, that an imported payment already holds, or a document with no total. A document in another currency than the book currency ties in book figures: at the rate sent as exchange_rate (the source system's), its receivable or payable and VAT legs within a cent per VAT group of the converted total and VAT; without one, at the rate the journal booked (its receivable or payable over the total), its VAT legs likewise. Its rate and book figures are then read off that journal. A link into a period marked done is 409 PERIOD_CONFIRM_REQUIRED, and into a filed VAT return's period 409 INVOICE_TRANSACTION_VAT_PERIOD_FILED. Needs the ledger:write scope besides invoices:write (403 INSUFFICIENT_SCOPE).

on_conflictOnConflictdefault "error"

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
200PurchaseInvoice · An existing purchase invoice with this external_ref (on_conflict return or update).
201PurchaseInvoice · The created draft.
400The request fails validation. This operation's own codes: BOOK_TAX_TOTAL_OUT_OF_RANGE, CREDITED_INVOICE_INVALID, CREDIT_NOTE_SOURCE_NOT_INVOICE, INVOICE_TOTAL_NEGATIVE, INVOICE_TRANSACTION_NOT_LINKABLE, PURCHASE_LINE_CONTROL_ACCOUNT, ROUNDING_AMOUNT_INVALID, STATED_VAT_GROUP_MISMATCH, SUPPLIER_INVOICE_NUMBER_REQUIRED, TAX_CODE_NOT_FOUND.
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: INVOICE_NOT_FOUND.
409Conflicts with the resource's state. This operation's own codes: BUSINESS_PARTNER_ARCHIVED, CREDIT_NOTE_SOURCE_NOT_CREDITABLE, EXTERNAL_REF_EXISTS, EXTRA_MONTH_CONFIRM_REQUIRED, INVOICE_TRANSACTION_VAT_PERIOD_FILED, PERIOD_CONFIRM_REQUIRED, SUPPLIER_INVOICE_NUMBER_TAKEN, 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.
429Rate limit exceeded (RATE_LIMITED). Wait Retry-After seconds.

Errors this operation can return

switch on code, never on message
CodeStatusWhen
IDEMPOTENCY_KEY_REUSED409Idempotency-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.
CREDITED_INVOICE_INVALID400The referenced invoice is not an issued invoice of this organization.
CREDIT_NOTE_SOURCE_NOT_INVOICE400You can't create a credit note from another credit note.
ROUNDING_AMOUNT_INVALID400A rounding must be in whole cents and may not take a line amount below zero.
STATED_VAT_GROUP_MISMATCH400The document's VAT figures no longer match the invoice lines.
SUPPLIER_INVOICE_NUMBER_REQUIRED400A supplier invoice number is required to confirm this invoice.
TAX_CODE_NOT_FOUND400That tax code no longer exists for this organization.
INVOICE_NOT_FOUND404That invoice no longer exists.
16 more codes
BUSINESS_PARTNER_ARCHIVED409That business partner is archived.
CREDIT_NOTE_SOURCE_NOT_CREDITABLE409This invoice can't be credited.
EXTERNAL_REF_EXISTS409on_conflict: error: 409 EXTERNAL_REF_EXISTS with existing_id.
EXTRA_MONTH_CONFIRM_REQUIRED409This change falls outside the working month, so this month is billed separately.
SUPPLIER_INVOICE_NUMBER_TAKEN409This supplier already has an invoice with this number.
WORK_MONTH_CONFIRM_REQUIRED409This change starts the plan year's working month, so the working month must be confirmed first.
BOOK_TAX_TOTAL_OUT_OF_RANGE400data.book_tax_total: Between 0 and twice the supply's converted VAT, else 400 BOOK_TAX_TOTAL_OUT_OF_RANGE.
INVOICE_TOTAL_NEGATIVE400data.lines[].unit_price: A document whose total is below zero is refused (INVOICE_TOTAL_NEGATIVE); register it as a credit note.
PURCHASE_LINE_CONTROL_ACCOUNT400data.lines[].account_id: Never the organization's accounts payable or receivable control account (400 PURCHASE_LINE_CONTROL_ACCOUNT at the line), except a kept line that stays on the account it already has.
EXCHANGE_RATE_OVERRIDE_INVALID400data.exchange_rate: Refused on a document in the book currency and on a credit note, which uses its invoice's rate (EXCHANGE_RATE_OVERRIDE_INVALID).
EXCHANGE_RATE_MISSING400data.exchange_rate: With no bank rate for the date and none stated, 400 EXCHANGE_RATE_MISSING.
VALIDATION_ERROR400data.lines[].tax_amount: On any other write it may only repeat the VAT the line derives (a read sent back), and is not stored; another figure is 400 VALIDATION_ERROR by pointer.
INVOICE_TRANSACTION_NOT_LINKABLE400data.transaction_id: 400 INVOICE_TRANSACTION_NOT_LINKABLE otherwise.
INVOICE_TRANSACTION_VAT_PERIOD_FILED409data.transaction_id: A link into a period marked done is 409 PERIOD_CONFIRM_REQUIRED, and into a filed VAT return's period 409 INVOICE_TRANSACTION_VAT_PERIOD_FILED.
PERIOD_CONFIRM_REQUIRED409data.transaction_id: A link into a period marked done is 409 PERIOD_CONFIRM_REQUIRED, and into a filed VAT return's period 409 INVOICE_TRANSACTION_VAT_PERIOD_FILED.
INSUFFICIENT_SCOPE403data.transaction_id: Needs the ledger:write scope besides invoices:write (403 INSUFFICIENT_SCOPE).

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