Orders

Overview

Orders imported from marketplaces: status, totals and buyer data.

An order is a sale made on a marketplace. marketapi imports the orders of each Connection, keeps the exact amounts the marketplace reported, and tells you by webhook.

The whole journey, from sale to shipping: The order lifecycle.

Endpoints

MethodPathWhat it does
GET/v1/ordersList orders
GET/v1/orders/{orderId}Get order
GET/v1/orders/{orderId}/buyerGet buyer
POST/v1/connections/{id}/order-importsImport orders
POST/v1/connections/{id}/order-reconciliationsReconcile orders
POST/v1/orders/{orderId}/actionsRun order action

All of them need Authorization: Bearer mk_your_api_key. See Authentication.

The order is born on the marketplace

The API only reads. There is no POST, PATCH or DELETE for an order. An order arrives in three ways, and all three end up in the same place:

  • the marketplace notification, the normal path;
  • the import, to bring in a period;
  • the reconciliation, to recover what a lost notification left behind.

Receiving the same order again does not duplicate it or send an event. A notice older than what is already stored is ignored.

Status on axes

An order does not have a single status. Each axis moves on its own:

FieldWhat it says
statusopen, completed or cancelled
paymentStatusfrom pending to paid, or partially_refunded, refunded
fulfillmentStatusfrom pending to shipped and delivered, or not_delivered
invoiceStatusthe invoice: not_required, pending, submitted, accepted, rejected

invoiceStatus only leaves not_required or pending when the invoice routes move it.

Totals

Totals come in components, in cents, and nothing is recomputed. totalInCents is the total the marketplace reported. The gap to the sum of the components stays in roundingAdjustmentInCents:

roundingAdjustmentInCents = totalInCents
  − (subtotalInCents + shippingPaidByBuyerInCents + taxesInCents − order discounts)

It is 0 when the components add up, and negative when they exceed the total. Fees (feesInCents) stay out of the sum: they are what the marketplace withholds from the seller. netInCents is what the seller receives and is null when the marketplace does not say. marketapi does not compute it.

Unlinked line

Each line has linkState:

  • linked: marketapi found the binding of the listing sold. listingId, variantBindingId and variantId are set.
  • unlinked: it did not (a listing created outside marketapi, for example). Those three fields are null, and the line keeps the external identity (externalListingId, externalVariantId) and the externalSku.

The order is imported either way: an unlinked line breaks nothing. When the binding comes to exist (created by PUT …/variant-bindings, changed, imported or published), the line links soon after and an order.updated goes out. If the order is paid, the line reserves stock when it links; if it already shipped, reserve and write-off go out together (Stock). The order can be in any status. If the link does not happen right away, the order reconciliation links the line within 6 h. If more than one binding of the connection matches the line (the same SKU on two bindings, for example), it stays unlinked; once only one is left, it links at the next read of the order or at the reconciliation, within 6 h.

Stock

The Connection order policy decides whether an order moves stock. It is born on, with the seller's default warehouse. Each order line has an inventoryState:

inventoryStateMeans
nonenothing moved yet, or the policy leaves the line out
reservedunits held by a paid order
soldthe order shipped and the units left (final state)
releasedthe order was cancelled: the reservation went back, or the line closed without ever reserving (final state)
shortagethere was not enough stock to reserve; the next order update tries again

When a line takes part. A line with no reservation (none or shortage) takes part with all four together: the policy is on; the line is linked; the Variant has inventoryAuthority: marketapi; and the order was placed (placedAt) at or after enabledSince. Otherwise the line does not change state.

A reserved line always finishes: write-off on shipment, release on cancellation, even with the policy off, enabledSince moved or the binding removed. Turning the policy off only affects new reservations. The exception is a Variant that left marketapi: its stock is no longer marketapi's, so nothing moves and the line stays reserved.

What each order does:

OrderMovement
paid (paymentStatus paid or partially_refunded), not yet shipped or cancelledreservation: the line goes to reserved
shipped (fulfillmentStatus shipped, delivered or not_delivered, or status completed)sale: the line goes to sold. With no reservation yet, reserve and write-off go out together
cancelled (status cancelled)release, if the line was reserved: goes to released. With no reservation (none or shortage), the line goes to released with no movement

Details that change the outcome:

  • Reprocessing the same order does not duplicate a movement: the line state prevents it.
  • reserved only leaves with the shipment or the cancellation. If the payment goes back to unpaid, the reservation stays; only status: cancelled releases it.
  • A sold line that is cancelled later stays sold. Returned goods go through the return.
  • A line linked late on an already cancelled order goes to released with no movement. The same goes for a shortage line of a cancelled order, even outside the stock rules.
  • Quantity changed. If the marketplace changes the quantity of a reserved line, the reservation settles the difference (reserves or releases) in the warehouse and Variant of the reservation; on shipment, it settles and writes off the final quantity; on cancellation, it releases what was reserved. With no balance for the difference, the reservation stays as it is and the order shows inventory_shortage.
  • Variant goes back to marketapi. Reservations stuck on it finish on the Variant PATCH that returns it to marketapi: write-off if the order shipped, release if it was cancelled, nothing if it is still paid.
  • Not enough balance. The order is stored normally, the line goes to shortage, and the order gets inventory_shortage in statusReasons. The other movements of the order go on. The reason describes the last attempt to reserve. The line is tried again when the order is read from the marketplace (import, notification or reconciliation) while it is paid, shipped or cancelled, even with no change; with balance, it reserves and the reason goes away. A line outside the rules (Variant not in marketapi, policy off, binding removed or order placed before enabledSince) is not tried: the reason stays until it is back inside the rules or the order is cancelled.
  • A derived, managed_externally or disabled Variant is not touched.

The stock movement. A new reservation uses the policy warehouse (or the seller's default). Write-off and release use the warehouse and Variant where the reservation was made, even if the policy changes later. Each movement carries reference: { "type": "order", "id": "<orderId>" } and a reason: Order paid: stock reserved, Order shipped: stock reserved (the reservation of an order first seen already shipped, which goes out with the write-off), Order shipped: stock sold, Order cancelled: reservation released, Order quantity increased: stock reserved or Order quantity decreased: reservation released. It fires inventory.movement_created and the automatic publication of the quantity, like any movement of yours. If a line changed inventoryState, the order gets an order.updated.

GET/PATCH of the policy: Get and Update order policy.

Buyer data

The order and the webhook carry no personal data: only hasBuyerContact. Name, CPF or CNPJ, e-mail, phone and addresses come out only through Get buyer. Every access is logged, and the data goes away at the end of the retention period. Each field comes with a state:

StateWhat it says
availablethe value is in value
maskedthe marketplace only shows the masked text, in value
withheldthe marketplace does not show this field
purgederased at the end of retention; the order stays

Webhooks

  • order.created: the order appeared in marketapi, even if it arrives already cancelled.
  • order.updated: a status, total, line, payment, the link or the inventoryState of a line changed.
  • order.cancelled: the order was cancelled. It goes out alone, without order.updated.

The data is { order }, the same order as Get order, with only IDs and fields with no personal data. The reasons in statusReasons come without message (free text from the marketplace): use the code. Invoices and shipments have their own events: Invoices and Shipments.