When to use this endpoint

Use to reconcile amounts recorded against vehicle IDs; use the dispatched counterpart for outgoing balances.

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

ParameterTypeRequiredDescription
stockIDsFilterComma-separated stringNoA string such as 1042,1088, not a JSON or native array. Omitted or blank/whitespace means no selection restriction. Tokens must be positive decimal IDs; whitespace is trimmed and duplicates are removed. Malformed, zero/negative or non-string lists return invalid parameter: stockIDsFilter.
nameStringsNoNon-empty values add lower-case contains filters on the respective stock columns. SQL LIKE wildcards remain active.
codeStringsNoNon-empty values add lower-case contains filters on the respective stock columns. SQL LIKE wildcards remain active.
descriptionStringsNoNon-empty values add lower-case contains filters on the respective stock columns. SQL LIKE wildcards remain active.
archivedInteger-compatible stringNoOnly omission disables this filter. When present, integer-converts and matches is_archived, including blank/0 as unarchived; this is not a deleted-record filter.
category_idInteger-compatible stringNoNon-zero values search the stock category_ids JSON text for a quoted integer ID. It does not use the category membership CSV used to render category names.
stock_idInteger-compatible stringNoTruthy value adds an exact integer-converted stock ID filter.
location_tagsStringNoNon-empty value adds a contains expression on meta.location_tags using a safely encoded SQL literal. SQL LIKE wildcards remain active.
searchStringNoNon-empty value searches its own text against lower-case stock name OR code. Combines with other supplied filters using AND; SQL LIKE wildcards remain active.
triggeredInteger-compatible stringNoNon-zero enables the trigger comparison described below. Omitted/0 does not filter.
last_editedDatetime stringNoForwarded implicitly to Vehicles_getReges through the shared request, filtering vehicle columns rather than stock. last_edited takes precedence; see behavior.
idsJSON array string or native arrayNoForwarded implicitly to Vehicles_getReges through the shared request, filtering vehicle columns rather than stock. last_edited takes precedence; see behavior.

Example request

$csv = FM_api('Stock_exportVehicles', ['stockIDsFilter'=>'1042']);

Example response

"Stock ID","Stock Name","Stock Code","Stock Supplier",VAN-01,TOTAL,COST,"TOTAL COST"
1042,"Filter cartridge",FLT-01,"Parts supplier",2,2,4,9

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-vehicles-allocated.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.

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

Behaviour and edge cases

  • Reads container type 2 (Vehicle). It is a current container snapshot, not a date-bounded transaction ledger.
  • Stock rows exclude deleted items but include archived items. Supplier lookup also includes retained deleted suppliers.
  • Owner columns come from the current owner lookup, so containers whose owner is absent from that lookup are not included in row totals. Owner columns are ordered by name for users/locations; vehicles have no declared order.
  • Each stock/type/owner key sums duplicate container rows. Missing cells are blank. A zero row total suppresses the row; negative totals can be exported.
  • Quantities and COST preserve float values. TOTAL COST is total × average_cost when total>0, including fractional positive totals below 1; zero/negative totals retain the legacy zero valuation.
  • triggered, when non-zero after integer conversion, filters container amounts against that container row’s amt_trigger; it does not filter warehouse stock against its trigger.
  • Vehicles_getReges normally returns every vehicle, including retained deleted ones. Truthy last_edited selects vehicles edited from that inclusive timestamp up to exclusive server now; otherwise ids selects integer-converted vehicle IDs. Neither changes stock selection.
  • Container vehicle identifiers are matched against vehicle numeric IDs; this export does not remap UUID-based container IDs.
  • 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

  • Streams CSV directly to the response, closes the output stream and exits.

See it in Fieldmotion

CRM1

Open Stock, select Vehicle in Export Stock and submit. Filter Network for Stock_exportVehicles; the legacy form sends the shared stock filters.

CRM2

Open Stocks, choose Export, select the matching report and submit. Filter Network for Stock_exportVehicles (the posted form uses php/api.php with extra=/Stock_exportVehicles). CRM2 supplies yes=really and a comma-separated stockIDsFilter for the selected export scope.

Related endpoints