Factuarea APIDevelopers

Sales orders

The commitment before the document — how an order is born, how it moves, and how it becomes delivery notes and invoices, whole or in part.

A sales order is what your customer committed to buy, recorded before any fiscal document exists. It is not an invoice and it is not a delivery note: it is the open commitment those two consume, line by line, until nothing is left pending.

Everything on this page lives under the company axis — /companies/{company}/sales-orders — and is gated by the sales_orders module, available from the Avanzado plan upwards.

The four quantities

This is the part an integration gets wrong when it is not written down. Every line carries four accumulated quantities plus one derived:

FieldWhat it means
quantity_orderedWhat the buyer committed to. The only one you set.
quantity_servedHow much has physically left, accumulated across delivery notes.
quantity_invoicedHow much has been invoiced, accumulated across invoices.
quantity_returnedHow much came back, accumulated across returns. Receiving a return whose origin is the order, one of its delivery notes or one of its invoices adds to it.
quantity_pendingDerived, never stored: ordered − served + returned, floored at zero.

Serving and invoicing are independent axes. A line can be fully served and not invoiced, fully invoiced and not served, or both at different speeds. Do not derive one from the other, and do not compute the pending amount yourself from a delivery-note count — read quantity_pending.

A return gives quantity back to the pending figure: ten ordered, ten served and two returned leave quantity_pending at two, and the derived status moves with it. So sales_order.partially_served or sales_order.served can be emitted when a return is received (see Events). A closed order records what came back without reopening.

What an order publishes

Besides its lines and quantities, the detail of an order answers the questions an integration would otherwise have to ask in a second round:

FieldWhat it tells you
editable_sectionsThe sections that admit a change in the current status, so you know before trying. See Editing a confirmed order.
related_documentsThe delivery notes, invoices and returns born from the order, in chronological order, each as {type, id, number, status, status_label, date} plus the keys of its type (see Related documents). An empty list while nothing was derived.
originWhere the order came from: {type, id, number, label, provider, external_reference, date, store_sync_mode} with type quote, proforma or store. null for an order entered by hand or through the API.
has_reservation_shortfallWhether any line has less stock reserved than it still needs. A shortfall never blocks confirming; the order is confirmed and says so here.
marketing_consentThe commercial consent the buyer answered at the checkout of a storefront, saved with the order as {granted, recorded_at, source}. null when the question was not asked.
fulfilmentHow far the order is from being served and invoiced, with the figures the application shows. See Progress and portfolio.
lifecycleWho created, confirmed, cancelled and closed the order, and when. See The life cycle.
document_holderWho the delivery notes of a buyer without a contact are issued to: {name, is_generic}. See The holder of the delivery notes.
can_confirm, can_edit_lines, can_delete, can_cancel, cancel_blocked_reasonThe manual actions the order admits now, and why a cancellation is blocked. null when the view did not compute them.
last_reversionThe last time the order went back to an earlier status because the document that had moved it forward disappeared. See Going back a status.

editable_sections, related_documents, has_reservation_shortfall, marketing_consent, lifecycle and last_reversion are computed on the detail. In the listing (sales_orders.list) they travel as null, which means "not computed", not "empty": open the order to read them. origin, fulfilment and document_holder travel in both, with the origin read in one batch for the whole page. has_reservation_shortfall is also null on a draft and on a closed or cancelled order, and false only when it was computed and everything is covered.

Each line adds to the quantities:

  • additional_description, the free second line of the concept.
  • The taxes chosen for it: vat_id, retention_id and surcharge_id, each null when only the percentage was declared.
  • The catalog selection captured when the line was added: variant_id, presentation_id, configuration_id, configuration_signature, options, price_list_id and price_source, plus commercial_unit_code and base_unit_code. It is a snapshot: a line read and sent back unchanged keeps it.
  • reservation, the live coverage of the line as {tracked, reserved, shortfall}. A line without an item, or whose item does not manage stock, is not tracked and never has a shortfall.
  • quantity_in_return, what the line has in a return that is requested or approved and not yet received, counting only the returns that name this order as their origin.
  • quantity_pending_to_invoice, what can be invoiced right now: what was served, or everything ordered for an order of a connected store or of the web shop and for a company without the delivery_notes module. It is 0.0000 on a draft and on a closed or cancelled order.
  • price_list_name, the name of the price list that set the price, captured when the line was added, and the snapshot sku and product_name of the item, so a later change of the catalog does not rewrite the order. All three are null for a line without them.

Adding a line and updating one accept that same selection (variant_id, presentation_id, configuration_id, configuration_signature, options with at most 50 entries, price_list_id and price_source) and, for variable-weight and variable-measure lines, counted_quantity and confirmed_base_quantity. The informative keys the order publishes for each option are accepted and change nothing, so a line read can be sent back as it is.

Each entry of related_documents carries the keys of its type and null in the others:

TypeExtra keys
delivery_notewarehouse as {id, code, name}, fulfilment_status, fulfilment_status_label, packages_count and carrier_name.
invoicetotal, is_overdue and due_date.
return_orderstatus and quantity_total; its number is null while the return is only requested, because it takes one when it is approved.

number is null while the delivery note or the invoice is a draft, as it is for a return that is only requested; tell them apart by id.

The documents that come from an order point back to it: an invoice carries sales_order as {id, number}, and a quote and a pro-forma as {id, number, status, status_label}; it is null when they do not come from one. A return carries business_contact_name; its listing filters by origin_id (which requires origin_type with a single value, otherwise 422) and its search also matches the name of the customer.

VAT and withholding of a line

A line that names its VAT with vat_id and sends no vat_rate takes the rate of that tax. With a vat_rate that differs from the percentage of the tax it is 422 parameter_invalid_value with subcode tax_rate_mismatch, param lines.N.vat_rate (vat_rate on the single-line operations) and line_index, the zero-based index of the line, and nothing is saved; send only the id, or the percentage of that tax. A line with no rate, no tax and no default sales VAT in the company is 422 missing_required_param with the same param. In a bulk creation, the same answer is the row of failures[] with error_code, subcode and param, and the batch goes on.

retention_rate is sent as a magnitude, from 0 to 100 with at most two decimals. A negative value is 422 invalid_param_value with param lines.N.retention_rate and nothing is saved.

Deleting the only line of a draft and confirming an order without lines are 422 business_rule_violation with subcode sales_order_requires_lines and param lines.

Progress and portfolio

The fulfilment block says how far the order is from being served and invoiced, in the listing and on the detail:

FieldWhat it tells you
served_percent, invoiced_percentFrom 0 to 100, weighted by the amount of each line. served_percent discounts what was returned, within what was ordered per line: an order of 3 units with 3 served and 2 returned reads 33.33.
pending_to_serve{lines_count, amount}: the lines with something left to serve and their amount, VAT included. Zero for a draft, a closed or a cancelled order.
invoiceable_now{lines_count, amount}: what can be invoiced right now, VAT included.
remaining_to_invoice_amountWhat is still to be invoiced whether or not it can be invoiced yet, VAT included. On a draft it is the total of the order.
is_late, days_lateWhether the expected delivery date has passed with something left to serve, and by how many calendar days (0 when it is not late).
serve_applicablefalse when the company has no delivery_notes module.

Without the delivery_notes module there is nothing to serve, and the availability of the order is resolved live, not by plan: the invoice ceiling of each line is ordered − invoiced, pending_to_serve is zero, the order can be closed without serving, and once everything is invoiced its status is invoiced and it can be closed. In that case the pending=deliver and delivery filters return no order.

The listing narrows the portfolio with:

  • pending: deliver (something left to serve), invoice (something left to invoice) or invoiceable (something that can be invoiced right now).
  • delivery: late (overdue with something left to serve) or week (due within seven days, today included).
  • channel or channel[in] (a comma-separated list), warehouse_id (it matches the warehouse of the header or of any line), external_id and status[in].
  • search, which also matches the external reference, and sort by created, number, expected_delivery_date or buyer_name, with a - prefix to descend.

Where an order comes from

The channel field records the origin and never changes afterwards. Its values are manual, api, store, storefront, quote, proforma and assistant:

By API. Create the order with its buyer, its lines and, optionally, expected_delivery_date and warehouse_id. It is born as draft.

From a quote or a pro-forma. When the customer accepts, convert it with convert to sales order or its pro-forma counterpart. Both are irreversible.

From a connected store. An order paid on WooCommerce or Shopify is ingested and lands already confirmed, with channel: store. It emits order.received (see Events) and keeps the shop's own identifier in external_id — which is what find by external id looks up, so a replayed webhook never creates a twin. Store setup lives in Ecommerce stores.

From your own shop. An anonymous shopper checking out through the buyer lane produces an order with channel: storefront — see Storefront.

Converting a quote or a pro-forma

quotes.convert_to_sales_order and its pro-forma counterpart carry the whole document across; they admit no partial selection of lines.

  • The buyer has to be reachable. The client of a quote and of a pro-forma publishes contact_ready: true when the customer record has an email or a phone. When it is false, send buyer_contact as {email, phone} with at least one of them; otherwise it is 422 invalid_param_value with param buyer_contact.email. It only fills an empty channel, never overwrites one, and it is written in the same transaction as the order.
  • Two addresses. client also publishes billing_address and delivery_address (null when the record has no usable one). The order is invoiced to the first and ships to the second or, without it, to the first.
  • The document points to its order. sales_order carries {id, number, status, status_label}. The quote publishes approved_at as an alias of accepted_at, and the pro-forma publishes accepted_at; both hold the instant of the last change while the document is accepted, and null in any other status, converted included.
  • What travels. The notes of the document, as the order notes; the price list of the header, as a snapshot on the lines that do not carry their own; and the actor who converted it, which the order records as performed_by in its activity.

The life cycle

draft ──confirm──> confirmed ──> partially_served ──> served
                        │                │
                        └──> partially_invoiced ──> invoiced ──close──> closed
                        │
                        └──cancel──> cancelled
  • draft is the only state that can be deleted and the only one whose lines, buyer, order date, series and external_id can change. Once confirmed, the lines are the commitment: correct them by serving less, by returning, or by cancelling the order. What a confirmed order still admits is described in Editing a confirmed order.
  • confirm is the door to everything else. It is irreversible and it is what holds stock. A draft of the web shop (channel: storefront) without a verified payment is confirmed by its payment, not by hand: confirming it is 422 sales_order_awaiting_payment with subcode confirm, and can_confirm says so beforehand. Holding never fails for lack of goods: it holds as much as there is and records the shortfall (has_reservation_shortfall, and reservation on each line), because whether to reject an order that is one unit short is your decision, not the platform's. See Inventory and warehouses. Two simultaneous confirmations of the same order consume a single number.
  • partially_served, served, partially_invoiced and invoiced are computed from the lines, not set by hand. They move as the assignments move, and they can come back: invoicing the rest of an order that was partially_invoiced leaves it invoiced.
  • close is the deliberate "this commitment is over" — a terminal state that stops the order from appearing as live work. It is available once nothing is left to serve for the first time nor to invoice against what was ordered; what was returned and not re-sent does not prevent it. With something still pending it is 422 with subcode sales_order_not_closable and nothing changes. Closing releases what was still reserved.
  • cancel is terminal and accepts an optional reason of up to 500 characters, published in lifecycle.cancelled.reason. can_cancel says whether it is available and cancel_blocked_reason why not: terminal (already closed or cancelled), served (goods were handed over) or has_invoices. An order with a net invoiced amount (its invoices minus their corrective invoices) is 422 sales_order_has_invoices: issue the corrective invoices first and cancel afterwards. In a bulk status change it appears in failures.

Who did what

lifecycle on the detail has four milestones, each null while it has not happened: created, confirmed, cancelled and closed. Each is {at, by}, with by as {id, name} of the user, or null when a credential without a user did it or no author was recorded; cancelled adds the reason. created is published only when the user who created the order is recorded, so it is null for an order that came in from a web shop or a connected store.

Going back a status

The derived statuses move backwards when the document that moved them forward disappears: a delivery note deleted or cancelled, an invoice annulled, a return removed. The order emits sales_order.status_reverted with {from, to, cause, recovered_lines, re_reserved} (see Events), and the detail publishes last_reversion while that is the last change of status and the order is still in the status it went back to. cause is {type, id, number, action} with type delivery_note, invoice or return_order and action deleted, cancelled or annulled; each entry of lines says how much was recovered (quantity_recovered), how much is reserved again (reserved_again) and how much could not be (shortfall), read live.

Read the catalog at runtime with statuses instead of hardcoding the list: it returns each value with its label and colour, and whether the status admits editing (can_edit), deleting (can_delete), invoicing (can_convert) or serving (can_serve). can_serve is true from confirmed to invoiced, both included. The catalogs of quote and pro-forma statuses label converted as «Convertido»: it means consumed by a target document, not invoiced.

The first confirmation of an order, and the first return requested, in a company that has no series for them create it (PED for orders, DEV for returns) inside the same operation, so neither depends on a series set up beforehand. Because of that, approving a return can answer 409 resource_conflict (example identity_reservation, on the series) when another request is reserving identifiers of the same kind at that moment. Confirming and updating an order declare the same code and example, on warehouses: the first order of a company can provision its main warehouse. In all three nothing is written, and the request can be sent again after a few seconds.

Editing a confirmed order

A draft admits every change. A confirmed order keeps the lines, the buyer, the order date, the series and the external_id as the commitment, and admits the rest while it is live:

Section (editable_sections)A confirmed order admits it
shipping_address, expected_delivery_date, warehouse, line_warehouseWhile something is still pending to serve
business_contactWhile something is still pending to serve, through buyer (see below)
notesUntil the order is closed or cancelled

closed and cancelled admit none (an empty list). Read editable_sections before editing instead of trying. A locked section is 422 sales_order_not_editable with the section in param and the reason in subcode: section_locked when the status does not admit it, nothing_pending_to_serve when the order is live but has nothing left to serve. The same rejection, with param and subcode, comes from every editing operation: the update, the shipping address, the buyer and the three line operations (param lines). Edits that are allowed after confirming emit sales_order.updated with the sections touched, as they do on a draft.

The identity of the buyer is fixed once confirmed. PATCH …/buyer then only links a real contact: send the identity identical to the stored one together with business_contact_id, while something is pending to serve. Another identity is 422 sales_order_not_editable with param buyer; a terminal order, or one with nothing left to serve, is 422 sales_order_not_editable with param business_contact.

A draft admits the buyer and both addresses in the same update: send buyer_name, buyer_email, buyer_phone, buyer_tax_id, the billing_* fields and the shipping_* fields together with the rest, and they are written in a single transaction.

A web shop draft that is awaiting its payment keeps its lines: editing them is 422 sales_order_awaiting_payment with subcode edit_lines and param lines, and can_edit_lines says so beforehand. Deleting it by hand is the same code with subcode delete, and can_delete is false. Deleting is also guarded when the payment is already verified: it would leave money collected without a visible order, so it is 422 sales_order_not_editable with subcode storefront_payment_verified. In a bulk delete the order appears in failures. Retry its invoice or cancel it instead.

link-contact links the order to a contact record in one transaction, without touching the identity of the buyer saved on the order:

  • mode existing with business_contact_id links a customer contact of the company.
  • mode create creates the contact from the buyer of the order and forbids business_contact_id. When the buyer has no tax ID the contact is born as a person with alternative_id_type not_registered, which is always explicit and never implied by the absence of a tax ID.
  • create on an order that already has a contact is 422 contact_already_linked; a tax ID that already exists in the company is 409 resource_already_exists with subcode tax_id_already_exists and details.existing_resource_id: link that contact with existing. A cancelled or fully served order is 422 sales_order_not_editable, and the generic buyer of a channel is 422 contact_is_channel_holder.

The generic buyer of a channel

An order from a web shop or a connected store whose buyer has no contact is served to a generic buyer of the channel, an internal contact the platform creates the first time it is needed. It is never a contact you can pick, link or edit:

  • Creating or updating an order, linking it through PATCH …/buyer, and creating or updating a quote, a pro-forma, a delivery note or a recurring invoice with that contact as the client (an invoice only with type: F2), is 422 business_rule_violation with subcode contact_is_channel_holder, in any status of the order.
  • Every operation on the contact itself —edit, customer and supplier profiles, bank accounts, roles and their status, archive, restore and delete— answers the same. In the three bulk operations (archive, delete and role status) it appears in failures with error_code business_rule_violation and no subcode; in the bulk creation of orders and invoices it is a failure of that row.
  • The contact does not appear in listings, searches, pickers or exports of contacts and customers, and does not count towards plan limits. Its creation does not publish contact.created or contact.role.assigned and starts no automation.
  • The prefix channel-holder: (in any letter case) is reserved in the external_id of a contact. Creating, updating, creating in bulk or importing a contact with an external_id that starts with it is 422 validation_failed with param external_id (in a bulk operation or an import, the rejection is that of the row and the other rows go on).

The holder of the delivery notes

document_holder on the order says who its delivery notes are issued to: {name, is_generic}. is_generic is true when it is a generic holder and not a contact of the buyer. Reading it creates nothing. An order entered by hand, through the API or converted from a quote or a pro-forma, whose buyer has no contact, is served to a generic contact «Clientes particulares», one per company, created the first time it is needed and handled like the generic buyer of a channel (see above).

Serving: the delivery note comes from the order

Convert to delivery note takes the lines and the quantities you want to serve now. Send a subset and you get a partial delivery note; the order moves to partially_served and the lines keep the rest in quantity_pending. Call it again for the next shipment.

The delivery note it produces is an ordinary delivery note: it has its own series, its own PDF and its own physical cycle — picking, carrier, tracking — described in Fulfilment and returns.

Three rules of serving are worth knowing:

  • It serves what was already invoiced. An order of a channel that is invoiced when it is paid (web shop, connected store) reaches invoiced with the goods still in the warehouse. Converting it to a delivery note is allowed, the goods are not invoiced a second time and the stock moves once. That is what can_serve says in the catalog of statuses. With nothing left to serve it is 422 business_rule_violation with subcode sales_order_not_convertible; more than pending is 422.
  • Serving short is accepted. Serving an order that was confirmed with less stock than it needed, or re-sending what was returned, consumes as much as the line still holds.
  • The buyer may be the generic buyer of the channel. When the buyer of a web shop or store order has no contact, the delivery note is issued to the generic buyer of the channel, and consignee_name on the delivery note carries the name of the person it is really delivered to. It is read-only, always present and null on a delivery note with a real customer; it is not the person who signs (received_by). The first time that buyer is needed the contact is created, so this operation can also answer 409 resource_conflict (example identity_reservation), which is safe to retry.

Serving from several warehouses

convert-to-delivery-notes serves an order from several warehouses at once. Send groups, from 1 to 10; each is {warehouse_id, series_id, lines}, where lines maps an order line id to the quantity served from that warehouse, and each group creates one delivery note. It is atomic: all the notes are created or none. The response is 201 with data, one {id, number, warehouse_id} per group in the same order, and sales_order_status.

  • A warehouse appears in one group only, and a line can be split between groups while the sum does not exceed what it has pending.
  • Serving from a warehouse other than the one of the line releases the reservation of the line in its own warehouse.
  • A group that is not valid is 422 business_rule_violation with subcode sales_order_serving_groups_invalid (a repeated warehouse, an empty group, a line that is not of the order). A quantity above what is pending is 422 with subcode sales_order_line_quantity_exceeded, with param groups.N.lines.<id> and details {group_index, line_id, pending, requested}.
  • The single convert-to-delivery-note takes one note: lines that come from different warehouses are 422 with subcode sales_order_serving_groups_invalid and param lines.

The serving plan

serving-plan is a read that says what to serve and from where, and with which invoice. Nothing is reserved, numbered or written. Per line, in the order of the lines:

FieldWhat it tells you
line_id, presentation_nameThe key of the line in the serving and invoicing requests, and its presentation.
pending_to_serve, pending_to_invoiceWhat is left of each axis.
reservation{warehouse_id, reserved, shortfall}.
availability[]Per warehouse, from the point of view of this order: free (after everything committed, this order included), reserved_own, in_delivery_notes_own (what is in delivery notes of this order not yet delivered), in_transit and in_transit_transfers.
incoming[]What is expected from confirmed purchase orders: warehouse_id, purchase_order, quantity, expected_date, is_late.
suggested_sources[]The warehouses whose free quantity covers the shortfall, from most to least free.
purchase_suggestionWhat is still missing after adding every warehouse, for the supplier of the preferred offer of the item; null when nothing is missing or there is no preferred offer.

A quantity that sits in in_delivery_notes_own is already out of free, and reserved_own does not overlap free: the figure of availability discounts what is reserved and what is in delivery notes not yet delivered, and both add up to what the stock reads publish as committed_quantity (reserved_quantity plus in_delivery_notes_quantity). The stock side is described in Inventory and warehouses.

The plan also carries holder (the holder of the delivery notes) and invoice_preview, the invoice that converting the order would produce now, computed by the same rules as the conversion:

  • type: F1 (full invoice), F2 (simplified invoice) or blocked, with blocked_reason as {code, subcode, param} — the same values the conversion would answer.
  • series, next_number (a projection that consumes nothing) and last_issued.
  • effective_date, the date the invoice draft would carry (the requested date, or today).
  • total, recurring_overlap and, for the served goods, pending_by_month and oldest_month (see Invoicing).

invoice_lines[<line id>], invoice_series_id, invoice_date and buyer_tax_id simulate the invoice; the tax ID is never stored. A series that is not for invoices or belongs to another company is 404 series_not_found.

Editing the lines of a draft delivery note that comes from an order resyncs what the order counts as served in the same operation; serving more than the order line has pending is 422 business_rule_violation with subcode sales_order_line_quantity_exceeded and nothing changes.

Invoicing: whole or in part

Convert to invoice works the same way and on the same lines. Because the two axes are independent:

  • Invoicing in advance of serving is legitimate — a deposit, a subscription charged up front — and leaves the order invoiced with lines still pending to serve.
  • Serving without invoicing is equally legitimate: the goods left, the invoice comes at the end of the month.

An order can produce several invoices. The link is one-to-many by design, so do not assume that reading "the invoice" of an order returns a single document.

The conversion takes these inputs, all optional:

  • lines, a map of order line id to quantity; omitted, everything pending is invoiced. target_series_id and mode (draft by default, issue or issue_and_send) with send_to for the email.
  • date, the invoice date: today or earlier, and today when omitted; a later one is 422 business_rule_violation with subcode invoice_date_in_future and param date. With mode issue or issue_and_send the invoice is dated the day of issue, and an earlier date becomes its operation date when it has none. operation_date is the operation date when it differs, never later than date; omitted, it is the date of the last delivery note included. The response is {data, meta}: data is the invoice with the issued_on and operation_on it carries, and meta has requested_date.
  • buyer_tax_id and billing_address as {line1, city, province, postal_code, country} (all required when sent; country is a two-letter ISO code) complete the fiscal identity while something is left to invoice, in the same transaction. A tax ID different from the one the order already has is 422 subcode sales_order_buyer_tax_id_conflict, with the two values masked in details.
  • save_send_to_contact: when true, the email typed in send_to is saved in the contact record of the buyer.

Three rules decide what the invoice can be:

  • Identity. A buyer without a tax ID gets a simplified invoice (F2) only when the identity allows it. A buyer from outside Spain without an identifier, or an operation under an intra-community, reverse-charge or export regime, needs a full invoice: 422 buyer_identity_incomplete_for_full_invoice until the identity is complete.
  • One calendar month. An invoice does not mix delivery notes of different calendar months: 422 business_rule_violation with subcode invoice_spans_several_months, param lines and details.months (YYYY-MM). Invoice them one by one, oldest first; pending_by_month of the serving plan lists them.
  • Recurring invoices. An invoice that would overlap the period of an active recurring invoice of the buyer is 422 business_rule_violation with subcode sales_order_recurring_invoice_overlap and details.recurring_invoice {id, name, next_run_date, period}. A period that was skipped does not overlap: skip the next generation with skip, and take that skipped period back with unskip (200 with the recurring invoice; 422 recurring_invoice_cannot_be_unskipped when the last event was not a skip or something was generated afterwards).

A quantity above what is pending is 422 with details {line_id, pending}, the same on REST and MCP.

An invoice can also be born from a delivery note (convert). When that delivery note serves an order, the conversion invoices the order in the same operation: the invoice keeps it as sales_order, and the order moves to partially_invoiced or invoiced (emitting sales_order.partially_invoiced or sales_order.invoiced). If those units were already invoiced it is 422 business_rule_violation with subcode sales_order_line_quantity_exceeded. If the delivery note serves an order of a channel that is invoiced when it is paid (web shop or connected store) it is 422 business_rule_violation with subcode delivery_note_order_invoiced_at_payment: that order was already invoiced when it was paid, and what is left is to serve it.

The PDF and its presentation

The PDF of an order is the confirmation of the commitment, with the brand and the template of the company's template library. Its presentation (which template, which brand, which paper format) travels with the order and never changes its content, its numbering or its totals. Four operations read and move it; {sales_order} is the id of the order:

OperationRouteWhat it doesScope
sales_orders.get_presentationGET /v1/companies/{company}/sales-orders/{sales_order}/presentationReads the state: the template the order would use now and why, and the retained capture. Returns an ETag.sales_orders:read
sales_orders.assign_presentationPATCH /v1/companies/{company}/sales-orders/{sales_order}/presentationChooses the template of a draft, or null to inherit it. Takes expected_version, If-Match or both.sales_orders:write
sales_orders.list_presentationsGET /v1/companies/{company}/sales-orders/{sales_order}/presentation-historyLists the retained captures from the newest to the oldest, paginated with page and per_page.sales_orders:read
sales_orders.revise_presentationPOST /v1/companies/{company}/sales-orders/{sales_order}/presentation-revisionsAppends a revision to the capture of a confirmed order, from a preview of that revision.sales_orders:write

Reading and writing use the scopes the order already has, sales_orders:read and sales_orders:write; the presentation adds none. The MCP server exposes the four as get_sales_order_presentation, assign_sales_order_presentation, list_sales_order_presentations and revise_sales_order_presentation, with the same scopes. None of them generates a PDF. The state, the preconditions (ETag, If-Match, expected_version) and the revisions work as in Document presentations.

When it is captured. While the order is a draft, choose its template with assign_presentation or let it be inherited. confirm takes no presentation field: in the same operation that confirms the order it captures the presentation the order resolves at that moment, once per order. From then on the capture changes only by appending a revision, and the earlier ones stay in list_presentations. An order that a connected store ingests already confirmed (channel: store) captures it the first time its PDF is produced, by download or by email.

What it retains and what stays live. The capture retains the template and its revision, the commercial identity and its revision, the plan policy, the paper format, the purpose (complete) and the language. The content stays live: lines, quantities, addresses, notes and status are read from the order each time the PDF is produced. An edit to a section a confirmed order still admits (the shipping address, the expected delivery date, the warehouse or the notes; see Editing a confirmed order) shows in the next PDF while the design stays the captured one, and publishing a new revision of the template, or choosing another main template, does not change an order already captured.

Drafts. A draft is never captured: its PDF follows the presentation the order resolves each time and carries a draft watermark. The same applies to an order cancelled before it was ever confirmed, whose PDF carries a cancelled watermark; one cancelled after confirming keeps its capture. Both watermarks are automatic and follow the language of the document.

Which template. The order resolves its template down the ladder of Which template a document uses: the manual choice, the template of its series, the one its customer prefers, the company default for sales-order, the company default and, last, the PDF settings of the company. Its series is the one the order carries or, without one, the default series for sales orders of the company, which numbers it when it is confirmed. Give a template to a series of type sales_order with series.assign_pdf_template (it must declare sales-order with the complete purpose in A4) and to a customer with pdf_templates.contact_default_set, with document_type sales-order and purpose complete (the contact must be a customer).

The PDF. sales_orders.pdf answers 200 with the document in the response itself, as application/pdf inline or, with ?download=1, as an attachment: the PDF is produced inside the request, with no 202 and nothing to poll. The PDF of a confirmed order is retained. Confirming prepares its original in the background without making the confirmation wait; each download returns the retained PDF of the current content or, when there is none yet, produces it within the request, retains it and returns it. After an edit that the order admits, the next download carries the new content and is retained as well, and the original of the confirmation is kept. The PDF of a draft, and of an order cancelled before it was confirmed, is produced each time and retains nothing.

An order that is neither a draft nor cancelled, and whose public link is active, prints, where an invoice prints its payment block, the QR of that link with the caption «Track your order» (in the language of the document) and its address without the scheme. A draft, a cancelled order and an order whose public link was revoked or has expired print neither. Next to it, the references strip lists, when each one has a value, the reference of the order, the channel, the method and status of the payment collected in the online store, the warehouse it ships from and the carrier of its delivery notes. All of it is read live, not from the capture. The PDF carries no fiscal block: no VeriFactu QR, no legal mentions and no payment details.

While the revisioned presentation is not active for the company (render_activation legacy), nothing is captured: the read returns the inherited state with can_select and can_revise false, assign_presentation and revise_presentation answer 422 pdf_presentation_not_ready, and the PDF is produced from the PDF settings of the company, as it is for an order confirmed before the presentation was activated. When another request captures or retains the presentation of the same order at the same moment, the confirmation and the PDF download answer 409 pdf_presentation_conflict or pdf_presentation_context_changed; nothing changes, so send the request again.

Sending it to the customer

Send emails the order with its PDF attached, and is available on every state except draft and the two terminals. It is irreversible in the only sense that matters: the mail leaves. It emits sales_order.email_sent or sales_order.email_failed, so a delivery failure is something you can subscribe to instead of discovering by phone. The attached PDF carries the design captured when the order was confirmed (see The PDF and its presentation). The PDF on its own is a separate read.

include_public_link (true by default) set to false sends the PDF without the public link and its button.

Reading the link returns {url, enabled, expires_at, max_days, views_count, last_viewed_at}: enabled says whether it opens now, expires_at is null when it does not expire, max_days is the plan cap when extending it, views_count counts the times the page was opened and last_viewed_at is null if it never was. Revoking the link does not erase its visits.

PATCH …/public-link takes action — revoke, activate, extend or reset — and extend_days with extend, and returns the resulting state with the same shape as the read. Extending beyond the plan cap is 400 parameter_invalid_range with subcode public_link_expires_at_exceeds_max_days and param extend_days, naming the maximum. Each action is recorded in the activity as sales_order.public_link_revoked, sales_order.public_link_activated or sales_order.public_link_extended.

What the buyer reads at that address depends on the order. The public page of a cancelled order (status cancelled) keeps answering 200: it shows the status, the lines and the total, without fulfilment, payment or download, and of the recipient it publishes only the name, so the tax ID and the billing address of a cancelled order are not part of it. A link that was revoked or has expired answers 410 link_revoked or link_expired, with document_type sales-order and the issuer.

Activity

activities lists, newest first and with a cursor, the events of the order and those of its delivery notes, invoices, returns and stock reservations. Each entry is {event_type, description, metadata, performed_by, created_at}: metadata is stable per event_type and never carries internal ids (documents are named by their public id and number, and a deleted one keeps its number), and performed_by is null when the system did it.

  • delivery_note.* carries delivery_note_id, number, warehouse, lines, carrier and packages_count; delivery_note.updated adds changed_sections and changed_lines ({line_id, position, description, unit_code, from, to}, with from null for an added line).
  • invoice.* carries invoice_id, number, total and type; return.*, the return_id, number and lines.
  • stock_reservation.created and sales_order.reservations_released (reason manual) carry what was reserved or released.
  • sales_order.status_reverted carries from, to, cause and recovered_lines.
  • The payment of a web order is read from the payment saved with it, as web_payment in sales_order.confirmed; a failure of its automatic invoice is sales_order.payment_invoice_failed with code and message.

Errors worth branching on

CodeWhen
sales_order_not_foundThe id is not yours, or does not exist.
sales_order_not_editableYou tried to change a section the current status does not admit, or to delete an order past draft. param names the section; subcode is section_locked, nothing_pending_to_serve or storefront_payment_verified.
sales_order_awaiting_paymentA web shop draft that is awaiting its payment: it is not confirmed, its lines are not edited and it is not deleted by hand. subcode is confirm, edit_lines (param lines) or delete; in a bulk operation it is a row of failures.
sales_order_has_invoicesYou tried to cancel an order with a net invoiced amount. Issue the corrective invoices first.
sales_order_line_already_servedYou tried to remove or shrink a line that has already left.
sales_orders_monthly_limit_exceededThe plan of the company has a monthly allowance of sales orders and it is spent.
business_rule_violationA rule of the order holds, named in subcode: contact_is_channel_holder, sales_order_not_closable, sales_order_not_convertible, sales_order_line_quantity_exceeded, delivery_note_order_invoiced_at_payment, sales_order_serving_groups_invalid, sales_order_buyer_tax_id_conflict, invoice_spans_several_months, invoice_date_in_future, operation_date_after_issue_date, sales_order_series_not_found, sales_order_requires_lines, delivery_note_service_backed_by_invoice or sales_order_recurring_invoice_overlap.
buyer_identity_incomplete_for_full_invoiceThe invoice has to be a full one and the identity of the buyer is not complete.
validation_failedThe external_id of a contact starts with the reserved prefix channel-holder: (param external_id).
resource_conflictAnother request was reserving identifiers at that moment (identity_reservation). Nothing was written; send it again after a few seconds.
pdf_presentation_conflict409 of POST …/confirm or GET …/pdf: another request captured the presentation of the order at the same time. Nothing changed; read the presentation again and repeat the request.
pdf_presentation_context_changed409 of the same two operations when the presentation context changed in the meantime. Nothing changed; repeat the request.
pdf_presentation_invalid422 of GET …/pdf: the PDF cannot be produced with the template that applies to the order. param names what does not fit, such as configuration.columns, and subcode is columns_exceed_page_width or required_document_content_hidden.

Branch on code, never on message: the message is Spanish text for humans. The full list for this family is the sales order error index.

Where to go next

  • Purchasing and receiving — the mirror flow on the supplier side.
  • Inventory and warehouses — what confirming an order does to your stock.
  • Fulfilment and returns — the physical cycle after the delivery note exists.
  • Document presentations — choosing, reading and revising the template of an order, with its preconditions and its history.
  • The ERP section of the CLI — the same cycle from a terminal.
  • Sales order tools in MCP — the same cycle for an agent: update_sales_order_buyer, update_sales_order_shipping_address, get_sales_order_statuses and convert_sales_order_to_delivery_note among them, with convert_sales_order_to_delivery_notes, get_sales_order_serving_plan, link_sales_order_contact, get_sales_order_public_link, update_sales_order_public_link, list_sales_order_activities and unskip_recurring_invoice.
  • Storefront — the shopper lane whose orders arrive as channel: storefront.

On this page

Need a hand?Contact support