Update a sales invoice
liveChange some fields of a sales invoice. 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 pathOptional 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.
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 · requiredFields to change. A draft takes any of them. An issued invoice takes the changes its period allows (an issued edit rebuilds its entry); its customer, co-recipients and prepayment deductions are fixed. Sending lines replaces the lines: a line with an id keeps that line, one without is new, one left out is removed.
Most used attributes of data
The customer as printed.
5 attributes of party
Register code (a company), or a person's personal code.
The whole line list, in order.
13 attributes of each item
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.
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.
An existing line of this document to keep; omit for a new line (INVOICE_LINE_NOT_FOUND otherwise).
Dimension values on the line, at most one per dimension.
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.
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.
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.
Details
Each a contact of the organization, listed once, not the customer. Their printed details are taken from the contact. Sent as a whole list; editable on a draft only (409 INVOICE_NOT_DRAFT for a different set on an issued invoice).
The date the document is booked at. Null follows date while the two are equal and keeps the stored date once they were set apart.
Document currency (ISO 4217); changing it on an issued invoice is refused when either currency is foreign (EXCHANGE_RATE_FROZEN).
7 more attributes
Sent: books the document at this rate (a manual rate). null: back to the European Central Bank's rate of the document's dates. Omitted: the rate stays as it is, a manual one included. An issued invoice's rate is frozen: another value is refused (EXCHANGE_RATE_FROZEN).
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. Sent as a whole list ([] removes all); editable on a draft only.
Responses
errors use the error envelope| 200 | SalesInvoice · The updated sales invoice. |
| 400 | The request fails validation. This operation's own codes: CREDITED_INVOICE_INVALID, EXCHANGE_RATE_FROZEN, INVOICE_LINE_NOT_FOUND. |
| 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: INVOICE_NOT_FOUND. |
| 409 | Conflicts with the resource's state. This operation's own codes: BUSINESS_PARTNER_ARCHIVED, EXTERNAL_REF_EXISTS, EXTRA_MONTH_CONFIRM_REQUIRED, IMPORTED_INVOICE_CREDIT_NOTE_REQUIRED, IMPORTED_INVOICE_RATE_SET_SEPARATELY, INVOICE_LINES_PENDING, INVOICE_NOT_DRAFT, OPENING_INVOICE_EDIT_IN_OPENING_STATE, PARTNER_ARCHIVED_MATCH, PERIOD_CONFIRM_REQUIRED, PREPAYMENT_ALREADY_DEDUCTED, PREPAYMENT_INVOICE_NOT_EDITABLE, 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. |
| 412 | If-Match did not match: the record changed since you read it (PRECONDITION_FAILED). |
| 429 | Rate limit exceeded (RATE_LIMITED). Wait Retry-After seconds. |
Errors this operation can return
switch oncode, never on message| Code | Status | When |
|---|---|---|
PRECONDITION_FAILED | 412 | If-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. |
INVOICE_NOT_FOUND | 404 | That invoice no longer exists. |
BUSINESS_PARTNER_ARCHIVED | 409 | That business partner is archived. |
EXTERNAL_REF_EXISTS | 409 | A record of this resource already carries the external_ref you sent. |
EXTRA_MONTH_CONFIRM_REQUIRED | 409 | This change falls outside the working month, so this month is billed separately. |
IMPORTED_INVOICE_CREDIT_NOTE_REQUIRED | 409 | This invoice was brought over from another accounting system together with its ledger entry. |
IMPORTED_INVOICE_RATE_SET_SEPARATELY | 409 | An imported invoice's rate is not changed by editing the invoice. |
INVOICE_LINES_PENDING | 409 | This imported invoice's lines are still being fetched from Merit. |
13 more codes
OPENING_INVOICE_EDIT_IN_OPENING_STATE | 409 | This invoice is an open item of the opening balances. |
PARTNER_ARCHIVED_MATCH | 409 | This customer is an archived business partner. |
PERIOD_CONFIRM_REQUIRED | 409 | This changes figures already marked done for this period. |
PREPAYMENT_ALREADY_DEDUCTED | 409 | That prepayment is already deducted on another invoice. |
PREPAYMENT_INVOICE_NOT_EDITABLE | 409 | A prepayment invoice can't be edited. |
WORK_MONTH_CONFIRM_REQUIRED | 409 | This change starts the plan year's working month, so the working month must be confirmed first. |
CREDITED_INVOICE_INVALID | 400 | data.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. |
EXCHANGE_RATE_FROZEN | 400 | data.currency: Document currency (ISO 4217); changing it on an issued invoice is refused when either currency is foreign (EXCHANGE_RATE_FROZEN). |
INVOICE_LINE_NOT_FOUND | 400 | data.lines[].id: An existing line of this document to keep; omit for a new line (INVOICE_LINE_NOT_FOUND otherwise). |
INVOICE_NOT_DRAFT | 409 | data.co_recipients: Sent as a whole list; editable on a draft only (409 INVOICE_NOT_DRAFT for a different set on an issued invoice). |
INVOICE_LINE_REFERENCE_REQUIRED | 400 | data.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_NEGATIVE | 400 | data.lines[].unit_price: A document totalling below zero is refused with INVOICE_TOTAL_NEGATIVE: it is a credit note. |
VALIDATION_ERROR | 400 | data.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. |
Plus the general codes every operation can answer (UNAUTHENTICATED, RATE_LIMITED …): handle them once.