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 recordSales

Create a sales invoice

live
POST/v1/sales-invoices
Scope invoices:writeMCP tool create_sales_invoiceOperation id createSalesInvoice

Create a draft invoice, a credit note (credits_invoice_id) or an invoice from an accepted quote (from_quote_id). Nothing is numbered or posted until issue.

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
dataSalesInvoiceInputrequired

A new draft sales invoice, credit note or prepayment invoice. A credit note names the issued invoice it credits in credits_invoice_id; without lines it credits all of it. An invoice from a quote names the quote in from_quote_id and takes the quote's lines. Nothing is numbered or posted until issue.

Most used attributes of data

contact_idstring (uuid) · nullable

The customer. Its name, codes, address and e-mail are printed on the document unless party says otherwise.

datestring (date)

Document date. Required, except with from_quote_id or a credit note without lines, which are dated as the app dates them (today).

due_datestring (date)

Payment due date, on or after date; required with date.

linesarray of SalesInvoiceLineItemInputat most 500 items

The lines, in order. Optional only with credits_invoice_id or from_quote_id.

13 attributes of each item
namestringrequired1–255 characters

Line text as printed.

quantitystringrequireddecimal string

Quantity, up to 10 fraction digits. A negative quantity is a return and must name the invoice it returns against in credited_invoice_id (INVOICE_LINE_REFERENCE_REQUIRED); a price reduction keeps a positive quantity and a negative unit_price.

unitstringrequiredat most 50 characters

Unit of measure.

unit_pricestringrequireddecimal string

Net price per unit, up to 10 fraction digits. May be negative (a discount at the time of sale). A document totalling below zero is refused with INVOICE_TOTAL_NEGATIVE: it is a credit note.

tax_code_idstring (uuid)required

Tax code of the line; its rate is read on the document's date.

account_idstring (uuid)required

Revenue account of the line.

idstring (uuid)

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

item_idstring (uuid) · nullable

The item the line is made from, if any.

descriptionstring · nullableat most 1000 characters

Longer text under the name.

discount_percentstringdecimal string

Discount on the line in percent, 0-100; omitted means 0.

dimensionsarray of InvoiceLineDimension

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

2 attributes of each item
dimension_idstring (uuid)required

The dimension.

value_idstring (uuid)required

Its value on this line.

credited_invoice_idstring (uuid) · nullable

The issued sales invoice this row corrects -- a return, or a price cut of an earlier sale (KMS § 29 lg 7). Required on a row with a negative quantity (INVOICE_LINE_REFERENCE_REQUIRED); one that names no issued invoice of this organization is CREDITED_INVOICE_INVALID.

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.

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

Document currency (ISO 4217): the book currency, EUR, or another currency the company has activated. Omitted, EUR.

external_refstring · nullable1–200 characters

Your own id for the document, unique per organization; on_conflict resolves a create against it.

payment_referencestring · nullableat most 35 characters

An Estonian reference (7-3-1 check digit) or an RF creditor reference (400 PAYMENT_REFERENCE_INVALID otherwise). With status: issued, the reference the invoice was issued with, so a later bank payment citing it is matched to it: several open invoices of the same contact may share one (a customer's own reference), and an open invoice of another contact carrying it is 409 PAYMENT_REFERENCE_TAKEN with its existing_id.

Details

On a draft it is the draft's typed reference, unique in the organization (409 PAYMENT_REFERENCE_TAKEN) and printed when the draft is issued; a credit note carries none.

notesstring · nullableat most 5000 characters

The note to the customer printed above the rows.

14 more attributes
kindstring

Document kind; omitted means invoice (or credit_note with credits_invoice_id).

One of invoice, credit_note

posting_datestring (date) · nullable

The date the document is booked at -- its ledger entry, the period checked and the VAT return. Omitted or null books at date.

supply_datestring (date) · nullable

Date of supply for VAT, when it differs from date.

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 to book a foreign-currency document at, in ExchangeRate's direction. Omitted: the European Central Bank's rate of the supply date, else the posting date, else the invoice date.

Details

Sent: used as given and recorded as a manual rate. A credit note takes its invoice's rate, and a document in the book currency has the rate 1; any other value is refused (EXCHANGE_RATE_OVERRIDE_INVALID), as is a rate that is not positive. 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.

partyInvoicePartyInput · nullable

The customer as printed, for a one-off customer or to override the contact's details.

5 attributes of party
namestringrequired1–255 characters

Name.

registry_codestring · nullableat most 100 characters

Register code (a company), or a person's personal code.

vat_numberstring · nullableat most 100 characters

VAT number, with country prefix.

addressstring · nullableat most 500 characters

Address as one printed line.

emailstring · nullableat most 255 characters

E-mail the document is sent to.

footer_notesstring · nullableat most 5000 characters

The note to the customer printed below the totals.

rounding_amountstring · nullabledecimal string

Whole-cent rounding added to the total, outside every VAT figure (ROUNDING_AMOUNT_INVALID otherwise). Omitted or null is 0.

credits_invoice_idstring (uuid) · nullable

Create a credit note for this issued invoice. Without lines the credit note copies all of it, at its frozen rates.

from_quote_idstring (uuid) · nullable

Make the invoice from this accepted quote; the quote's lines are taken and lines may not be sent. Edit the draft afterwards.

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

numberstring · nullable1–50 characters

With status: issued, required: the document's own number. Unique among the organization's sales documents (409 DOCUMENT_NUMBER_TAKEN). A number in the organization's own format for its date takes its place in that series, so the next issued invoice continues after it.

co_recipientsarray of InvoiceCoRecipientInputat most 50 items

The invoice's other recipients besides the payer (co-owners), in print order: each is printed under the customer, e-mailed the invoice and reached by reminders, and the receivable stays on contact_id. Each a contact of the organization, listed once, not the customer. Their printed details are taken from the contact.

1 attribute of each item
contact_idstring (uuid)required

The co-recipient.

object_idsarray of string (uuid)at most 50 items

The objects the invoice bills (an apartment, parking spaces), e.g. a migration carrying a billing system's invoices. The invoice is then found by the objects' object_id filter and their payments.

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
200SalesInvoice · An existing sales invoice with this external_ref (on_conflict return or update).
201SalesInvoice · The created draft.
400The request fails validation. This operation's own codes: CREDITED_INVOICE_INVALID, EXCHANGE_RATE_FROZEN, INVOICE_LINE_REFERENCE_REQUIRED, INVOICE_TOTAL_NEGATIVE, INVOICE_TRANSACTION_NOT_LINKABLE, PAYMENT_REFERENCE_INVALID, 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.
404No such resource in this organization; the code names the resource. NOT_FOUND for a path that names nothing.
409Conflicts with the resource's state. This operation's own codes: BUSINESS_PARTNER_ARCHIVED, CREDIT_NOTE_SOURCE_NOT_CREDITABLE, DOCUMENT_NUMBER_TAKEN, EXTERNAL_REF_EXISTS, EXTRA_MONTH_CONFIRM_REQUIRED, INVOICE_TRANSACTION_VAT_PERIOD_FILED, PARTNER_ARCHIVED_MATCH, PAYMENT_REFERENCE_TAKEN, PERIOD_CONFIRM_REQUIRED, PREPAYMENT_ALREADY_DEDUCTED, QUOTE_ALREADY_CONVERTED, QUOTE_EXPIRED, QUOTE_NOT_ACCEPTED, 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.
EXCHANGE_RATE_FROZEN400The exchange rate of this document can no longer be changed.
TAX_CODE_NOT_FOUND400That tax code no longer exists for this organization.
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.
PARTNER_ARCHIVED_MATCH409This customer is an archived business partner.
19 more codes
PREPAYMENT_ALREADY_DEDUCTED409That prepayment is already deducted on another invoice.
QUOTE_ALREADY_CONVERTED409This quote has already been converted into an invoice.
QUOTE_EXPIRED409This quote has expired.
QUOTE_NOT_ACCEPTED409Only an accepted quote can be converted into an invoice.
WORK_MONTH_CONFIRM_REQUIRED409This change starts the plan year's working month, so the working month must be confirmed first.
CREDITED_INVOICE_INVALID400data.lines[].credited_invoice_id: Required on a row with a negative quantity (INVOICE_LINE_REFERENCE_REQUIRED); one that names no issued invoice of this organization is CREDITED_INVOICE_INVALID.
INVOICE_LINE_REFERENCE_REQUIRED400data.lines[].quantity: A negative quantity is a return and must name the invoice it returns against in credited_invoice_id (INVOICE_LINE_REFERENCE_REQUIRED); a price reduction keeps a positive quantity and a negative unit_price.
INVOICE_TOTAL_NEGATIVE400data.lines[].unit_price: A document totalling below zero is refused with INVOICE_TOTAL_NEGATIVE: it is a credit note.
PAYMENT_REFERENCE_INVALID400data.payment_reference: An Estonian reference (7-3-1 check digit) or an RF creditor reference (400 PAYMENT_REFERENCE_INVALID otherwise).
PAYMENT_REFERENCE_TAKEN409data.payment_reference: With status: issued, the reference the invoice was issued with, so a later bank payment citing it is matched to it: several open invoices of the same contact may share one (a customer's own reference), and an open invoice of another contact carrying it is 409 PAYMENT_REFERENCE_TAKEN with its existing_id.
INVOICE_LINE_NOT_FOUND400data.lines[].id: An existing line of this document to keep; omit for a new line (INVOICE_LINE_NOT_FOUND otherwise).
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.
DOCUMENT_NUMBER_TAKEN409data.number: Unique among the organization's sales documents (409 DOCUMENT_NUMBER_TAKEN).
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.
EXCHANGE_RATE_OVERRIDE_INVALID400data.exchange_rate: A credit note takes its invoice's rate, and a document in the book currency has the rate 1; any other value is refused (EXCHANGE_RATE_OVERRIDE_INVALID), as is a rate that is not positive.
ROUNDING_AMOUNT_INVALID400data.rounding_amount: Whole-cent rounding added to the total, outside every VAT figure (ROUNDING_AMOUNT_INVALID otherwise).
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.