Stock allocations and movement records
Page recorded stock returns
/a/StockReturneds_getDataTable
Read the return ledger with stock, source, actor and date filters.
When to use this endpoint
Use to verify the returned stock and its inventory ID after a save. This is a ledger read; reload the allocation and warehouse for their current balances.
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, containerID, containerType, container, qty, type, description, userID, inventoryID and cdate. 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('StockReturneds_getDataTable', ['fields'=>['id','stockID','container','qty','inventoryID','cdate'],'stockID'=>'1042','start'=>'0','length'=>'10','draw'=>'1']);
Example response
{"data":[{"id":"5081","stockID":"1042","container":{"id":"1088","type":"1"},"qty":"2.5","inventoryID":"3088","cdate":"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":"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.
- Default order is cdate descending when orderBy is omitted. cdate formats the saved epoch in the database session timezone. container is the recorded source owner/type pair.
- No inventory/stock reconciliation or active-owner validation occurs on read. Current checked returns store the actual inventory ID even for an unassigned/default return. Older historical records can still retain0.
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
In CRM2 open Stock Returned. pageStockReturned uses StockReturned/StockReturneds displayTable prefixes; filter Network for StockReturneds_getDataTable and use stockID to check a particular item.
Related endpoints
StockReturned_createData— perform a checked return and understand acknowledgement/retry handling.