Postman collection
Customers Read

pixiGetCustomerList

Returns up to 10,000 customers with orders, starting at a customer key, with order, turnover, return and reminder statistics plus main address data.

Builds a customer list with key figures, driven by the orders in OrderHeader.

  1. StartCustKey (NULL is treated as 0) selects the first customer. The call takes the first 10,000 distinct CustRef values from OrderHeader with CustRef >= StartCustKey, in ascending order, and counts their orders (OrderCount). Customers without any order are never listed.
  2. For each of these customers it calculates:
    • DaysSinceLastOrder / DaysSinceFirstOrder: days between today and the latest OrderDate in Orderlines of the order with the highest / lowest order number of the customer.
    • From Invoices: Turnover_all (sum of invoices with a positive total), Turnover_avgPerOrder (average of positive invoice totals), ReturnCount (number of invoices with a negative total), ReturnValue (sum of negative totals) and ReminderLevel (highest reminder level).
    • From Invlines: ItemCount_all, the sum of all positive ItemQty values.
  3. Currency handling depends on the setting MultiCurrencyEnabled:
    • not 1: amounts are summed in the original invoice currency, BaseCurrency is NULL.
    • 1: each invoice total is divided by the exchange rate of the invoice (pixi.ExchRate), and BaseCurrency holds the ISO code of the base currency.
  4. The result is joined with Customers and the customer's main address (Customers.AddrRef → Addresses) and sorted by CustKey ascending.

Paging: to read the next block, call again with StartCustKey = last returned CustKey + 1 (the filter is inclusive).

Notes

  • All permanent tables are read with NOLOCK; figures may include uncommitted data.
  • Without multi-currency, Turnover_all, Turnover_avgPerOrder and ReturnValue can mix different currencies if a customer has invoices in several currencies.
  • With multi-currency enabled, invoices without a matching exchange rate record are ignored. If a customer's invoices refer to more than one base currency, the unique index on the temporary invoice table fails and the call ends with a SQL error.
  • Turnover_avgPerOrder is the average per positive invoice, not per order.
  • Days since first/last order are based on the lowest/highest order number, not on the earliest/latest order date; they are NULL if that order has no lines.
  • The block of 10,000 is taken from OrderHeader before the join with Customers/Addresses; customers missing there are dropped, so a block can contain fewer than 10,000 rows even if more customers follow. Continue paging until an empty result is returned.
  • The address is the main address (AddrRef), not the shipping address.
  • The aggregation over all orders and invoices can be expensive on large databases.

Tables used

Settings · Read OrderHeader · Read Orderlines · Read Invoices · Read ExchRate · Read Currency · Read Invlines · Read Customers · Read Addresses · Read
SQL object:
dbo.pipiGetCustomerList
Updated at 2026-10-30