Postman collection
Returns Write

pixiCreateReturn

Creates a return credit note for selected lines of an invoice, sets the order lines to returned and books the credit to the customer account.

The API counterpart of the returns wizard in Customer Service. It prepares the values and then calls the internal procedure Pixi_CreateReturn.

Input lists

  • InvoiceLines, Quantities and Prices are parallel lists separated by ; (a trailing ; is added if missing). Entry n of each list belongs to the same invoice line.
  • Prices are gross unit prices. The net price is calculated per line as Price / (1 + TaxRate/100) using the tax rate of the invoice line.
  • Each invoice line key is translated into its order line (Invlines.OrderLineRef).

Steps

  1. The first invoice line in InvoiceLines determines the shipping country and the settings VATinShipCost / ChargeHighVATInShipCost of the original invoice.
  2. If no VAT rate is valid today for this country: with Force Country VAT enabled the call fails; otherwise a default VAT rate is inserted for the country (Pixi_InsertDefaultVATRateForCountry).
  3. The invoice header is read by InvoiceNr: customer, billing and shipping address, voucher, currency (the return is always done in the order currency).
  4. Defaults: ShipCost = minus the shipping cost of the invoice (full shipping refund); Voucher_Amount = voucher sum of the invoice (gross for B2C, otherwise net).
  5. Total: minus the sum of quantity × price, plus ShipCost, minus Voucher_Amount, plus ReturnCostsAmount. If the return costs would make the total positive, they are reduced so that the total becomes 0.
  6. Pixi_CreateReturn creates the credit note: only lines that belong to the referenced invoice and whose order line has status AUS are credited. With a smaller quantity the order line is split first. The credited order lines get status RET, the credit is booked to the customer account, lines of the return case ReturnCaseID are closed and a history entry is written, matching pixi.Return records in status Received are set to Credited, and the event InvoiceCreated is published.
  7. If MarkReturnDocumentForPrinting = 1, TimesPrinted of the new credit note is set to 0 so it is printed again.

The call returns the header of the new credit note as one row.

Notes

  • Runs in its own transaction (or a savepoint if a transaction is already open). Errors are caught, the transaction is rolled back and the error is logged with log.InsertError (not attached); whether the error is passed to the caller is not visible in the code. A failed call can therefore look like a call with an empty result.
  • Use . as decimal separator in Prices; values are cast to money.
  • The list parser removes the processed key with REPLACE. Duplicate keys or a key that is the ending of a later key (e.g. 23;123;) break the parsing. Pass each invoice line only once.
  • Lines whose order line is not in status AUS or that do not belong to the invoice InvoiceNr are silently skipped, but are still included in the calculated total.
  • CreateDate and InvoiceDate have no effect: the credit note date is always the current date.
  • DoNotRefund = 1 forces CreateDTAUS to 0.
  • TimesPrinted in the returned row shows the value before MarkReturnDocumentForPrinting is applied.
  • The column 1SS is not a valid XML element name; use OneSS instead.
  • Reads use NOLOCK.

Tables used

Invlines · Read Invoices · Write Addresses · Read Countries · Read VATs · Read Currency · Read
SQL object:
dbo.pipiCreateReturn
Updated at 2026-10-30