When to use this endpoint

Use the Stock History screen to inspect recorded movements. These are snapshots and references, not a reconstructed current stock balance.

Authentication and permissions

Authenticate with a signed API key or a logged-in CRM session on the account’s routed host. Signed requests act as the key owner. Session requests must include the dispatcher CSRF value when configured. All record identifiers belong to the authenticated tenant.

The dispatcher and these handlers do not impose an additional CRM2 Stock role or Stock TeamAccess record scope. CRM2 screen permissions are separate controls and must not be assumed to apply to CRM1. These routes do not become public because an individual legacy handler checks only the tenant context.

Parameters

ParameterTypeRequiredDescription
fieldsNative field-name arrayYesMapped names: id, stockID, stockReport, stock, type, fromID, fromType, fromQTY, froms, toID, toType, toQTY, tos, cdate, qty, lastEdited, userID, meta, metaReference, metaInventoryID, metaInventory and metaReason. Use a nonempty native list, not JSON text.
start / length / drawInteger-compatibleNoDefaults 0/10/0. No wrapper page-size maximum.
orderBy / orderDesc / orderMapped name/direction or native DataTables orderNoExplicit mapped name and asc/desc, or DataTables column/direction. Equal sort values have no guaranteed order.
isTable / limit / groupByInteger-compatible / native field listNoisTable=0 returns unpaged {data}; positive limit caps that mode. groupBy changes SQL grouping, not aggregate sums.
Mapped filters / searchField / searchValue / advanceSearchScalars/native arraysNoUse mapped fields and typed rules. Raw SQL where rules are refused.
referenceDate / dateFrom / dateToMapped date field / relative day offsetsNoPaired day offsets use account-local today and inclusive bounds; omission leaves the date window unset.
offsetFrom / offsetTo / timeRangeFrom / timeRangeToNative offset objects / hoursNoOffsets use hour/minute keys. The optional hourly filter needs timeRangeFrom; see the legacy behavior below.
froms / tosNative list of {id,type}NoComposite source/destination picker filters. User type1 expands to14, Vehicle2 to20 and Job7 to18 as additional choices.
metaReferenceProjection field inside fieldsNoRequesting this field also appends metaInventory; supporting metadata remains in the response.

Example request

$page = FM_api('StockHistories_getDataTable', ['fields'=>['id','stockID','type','qty','cdate','metaReference'],'stockID'=>'1042','start'=>'0','length'=>'10','draw'=>'1']);

Example response

{"data":[{"id":"4081","stockID":"1042","type":"2","qty":"2.5","cdate":"2026-11-23 10:00:00","metaReference":null,"metaInventory":null}],"draw":1,"recordsTotal":"12","recordsFiltered":"1"}

Examples show one representative result; database numeric scalars can be JSON strings. Application errors can use HTTP 200: inspect error and warning in the decoded response.

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":"invalid advanced search"}Raw where SQL in advanceSearch.

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

Behaviour and edge cases

  • The default response is {data,draw,recordsTotal,recordsFiltered}. data contains named mapped fields; database numeric values normally remain strings. draw is integer-converted. There is no automatic active-stock/owner filter on these ledger tables.
  • Table mode defaults to start=0,length=10; there is no wrapper maximum. isTable=0 removes table paging and count/draw fields, leaving {data}; positive limit then caps rows. Use native arrays for fields, groupBy, picker filters and advanceSearch.
  • orderBy plus orderDesc selects a mapped sort field; otherwise the DataTables order column is interpreted with the shared leading-column offset. No unique-ID tie-breaker is added. groupBy groups SQL rows rather than summing balances; counts are row counts and do not become group counts.
  • Mapped filters, searchField/searchValue and typed advanceSearch combine with endpoint filters. Use mapped names (or the shared table_column advanced-search IDs), never SQL fragments; a rule with raw where SQL returns invalid advanced search.
  • referenceDate selects a mapped date field. Paired dateFrom/dateTo are integer day offsets from today in the account timezone setting (UTC fallback), with inclusive start/end-of-day bounds. Optional offsetFrom/offsetTo contain hour/minute adjustments: hours are negated, minutes added. These are relative-day controls, not literal date strings.
  • Legacy hourly filtering is activated by timeRangeFrom (default range ends at 23; timeRangeTo alone does not activate it). It uses the selected date field and timezone setting, with Europe/London as that branch’s fallback. Prefer explicit typed date rules when reproducible absolute boundaries are required.
  • Defaults orderBy=cdate,orderDesc=desc only when orderBy is absent. Explicit cDate ordering resolves case-insensitively in the shared reader, but exact map names remain preferable for other controls.
  • cdate/lastEdited are formatted from saved epochs in mapped output. userID is the recorded actor. froms/tos contain id/type, and stock can hydrate id/name/code through the current stock join.
  • Adding a normal User/Vehicle/Job filter automatically includes the corresponding dispatched variant; this broadens that picker to both allocated and dispatched history. It does not rewrite recorded type codes.
  • metaReference is saved text, not newly regenerated from inventory on this read. Missing linked records remain historical evidence; no balance repair is performed.

Side effects

  • Database reads only; no reservation, movement, alert or history entry is created.

See it in Fieldmotion

CRM1

No direct CRM1 caller was found. Its older stock views use legacy exports and allocation readers.

CRM2

In CRM2 open Stocks, then History on an item. pageStockHistory uses StockHistory/StockHistories displayTable prefixes and filters by the selected stock. Filter Network for StockHistories_getDataTable.

Related endpoints