When to use this endpoint

Use to compare valuation at average cost and price; do not treat allocated quantities as excluding dispatch.

Authentication and permissions

Authenticate with a signed API-key request or a logged-in CRM session. Requires Stock view (pageStocks_view) and table export (pageMain_exportTableData) permissions through the shared export guard; denial returns permission denied.

Client administrators and the all permission satisfy the checks. Legacy users with no role use the helper’s allow fallback when no explicit permission list is loaded. This is not merely the CRM1 export-button bit check.

Queries use the authenticated tenant. No department/owner restriction or stock-tracking feature gate is added by these handlers. CRM2 features2.stockTracking changes the export choices offered, not server authorization. Session CSRF and API signing still apply.

Parameters

This endpoint has no operation-specific parameters.

Example request

$csv = FM_api('Stock_exportCosts', []);

Example response

"Item ID","Stock Item",Code,Description,Supplier,"Average Cost",Price,"Warehouse Qty","Allocated Qty","Total In Stock","Warehouse Cost","Allocated Cost","Total Cost","Warehouse Price","Allocated Price","Total Price"
1042,"Filter cartridge",FLT-01,"Replacement cartridge","Parts supplier",1.11,1.12,7,0,7,7.77,0.00,7.77,7.84,0.00,7.84

Success is raw CSV, not JSON: retain the response body instead of JSON-decoding it. The response uses text/csv and the final download filename stock-costs.csv. Column positions and blank cells are meaningful.

Errors and unusual responses

ResponseCondition
{"error":"not logged in"}No authenticated tenant context is available. Invalid signed credentials can be rejected by the dispatcher before the handler runs.
{"error":"permission denied"}Either required export permission is denied.
Header-only CSV or interrupted outputMost database reads are not checked for failure. A blank export is not proof that the database contained no matching rows; malformed stored JSON can interrupt legacy reports.
{"error":"invalid parameter: stockIDsFilter"}A supplied selected-ID list is not a string of positive decimal IDs.
{"error":"invalid parameter: search"}A supplied stock/date filter is an array or other non-scalar value; the error names that parameter.
{"error":"could not create stock export"}The per-request CSV stream cannot be created, written or rewound.

Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.

Behaviour and edge cases

  • Includes non-deleted stock, including archived rows. No name, category, selected-ID, triggered or date filtering is applied.
  • Allocated Qty sums every stock_container type, including dispatched types; NULL sum becomes zero. Total In Stock is warehouse quantity plus that aggregate.
  • Costs, prices and valuation columns are formatted to two decimals; quantities are not rounded by the exporter. Supplier labels exclude deleted suppliers.
  • No pagination or result limit is implemented. The entire result is exported; a header-only CSV is a valid empty result.
  • No stock quantity, audit, edit timestamp, notification or event is changed. Reads across multiple queries are not a transactionally frozen snapshot.
  • No direct caller for this exact endpoint was found in the current app JavaScript or m/www intermediary; these are office reporting/source-selection calls, not the app download protocol.
  • The shared guard rejects non-scalar supplied stock/date filters and validates any supplied stockIDsFilter even on reports that do not use it for selection.

Side effects

  • Builds CSV in a checked per-request php://temp stream, then streams it, closes it and exits. No shared tenant filename is written; concurrent requests generate independent files.

See it in Fieldmotion

CRM1

Open Stock and click Export Costs. Filter Network for Stock_exportCosts; the form sends CSRF only.

CRM2

Open Stocks and choose Export Costs. The form posts this exact endpoint without the selected-ID or table filters.

Related endpoints