Stock allocations and movement records
Page dispatch records
/a/StockDispatches_getDataTable
Query recorded dispatch rows by stock, linked source or customer fields.
When to use this endpoint
Use for ledger reporting, not to calculate what can still be dispatched. Available stock belongs to allocation/warehouse readers.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
fields | Native field-name array | Yes | Mapped names: id, stockID, linkID, linkType, link, customerID, customerType, customer, qty and createdDate. Use a nonempty native list, not JSON text. |
start / length / draw | Integer-compatible | No | Defaults 0/10/0. No wrapper page-size maximum. |
orderBy / orderDesc / order | Mapped name/direction or native DataTables order | No | Explicit mapped name and asc/desc, or DataTables column/direction. Equal sort values have no guaranteed order. |
isTable / limit / groupBy | Integer-compatible / native field list | No | isTable=0 returns unpaged {data}; positive limit caps that mode. groupBy changes SQL grouping, not aggregate sums. |
Mapped filters / searchField / searchValue / advanceSearch | Scalars/native arrays | No | Use mapped fields and typed rules. Raw SQL where rules are refused. |
referenceDate / dateFrom / dateTo | Mapped date field / relative day offsets | No | Paired day offsets use account-local today and inclusive bounds; omission leaves the date window unset. |
offsetFrom / offsetTo / timeRangeFrom / timeRangeTo | Native offset objects / hours | No | Offsets use hour/minute keys. The optional hourly filter needs timeRangeFrom; see the legacy behavior below. |
Example request
$page = FM_api('StockDispatches_getDataTable', ['fields'=>['id','stockID','qty','createdDate'],'stockID'=>'1042','start'=>'0','length'=>'10','draw'=>'1']);
Example response
{"data":[{"id":"3081","stockID":"1042","qty":"2.5","createdDate":"2026-11-23 10:00:00"}],"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
| Response | Condition |
|---|---|
{"error":"not logged in"} | No authenticated tenant context is available. Invalid signed credentials can be rejected by the dispatcher before the handler runs. |
{"error":"missing or invalid parameter: fields"} | No fields supplied to shared table reader. |
{"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.
- No endpoint-specific sort is supplied: the shared first-projected-field fallback determines order unless explicitly requested. createdDate formats the stored epoch; link/customer project id/type pairs.
- No stock-availability, active customer/Job or completed-receipt interpretation is added to these historical rows. Counts describe dispatch records, not current allocation balances.
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 in the source search. CRM1 uses its legacy Stock grid and stockContainerEdit allocation editor instead.
CRM2
No direct CRM2 dispatch-ledger table screen was found in the caller search. Current Dispatch dialogs use StockContainer_getDispatch; this remains the generic reporting route.
Related endpoints
StockDispatch_getRequestedDetails— hydrate selected dispatch record IDs.