Stock inventory, storage and bundles
Page and filter inventory rows for CRM2 lists
/a/StockInventories_getDataTable
Page and filter inventory rows for CRM2 lists.
When to use this endpoint
Use for the CRM2 Stock Inventory table or picker. For an unpaged stored-record lookup, use the singular getRequestedDetails endpoint.
Authentication and permissions
Authenticate with signed API-key fields or a logged-in CRM session. These handlers perform no additional stock, finance, page-role, department or owner check; UI button permissions are not server authorization.
Data is scoped to the authenticated tenant. Session CSRF, signed-request checks and account routing still apply. No stockTracking feature gate is enforced in these handlers.
Requires tenant upgrade 796: stock bundle, storage and inventory tables must have deleted/ddate columns before deploying these handlers.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
fields | Native array of field-name strings | Yes | Mapped projections: id, name, stockID, supplierID, supplier, storageID, storage, goodReceivedID, qty, cost, price, reference, receivedDate, lastEdited, cdate. Unknown names are ignored; id is always added. No JSON-text decoding. |
isTable | Integer-compatible scalar | No | Defaults to table mode. Integer 0 returns only {data:[...]} and disables paging/counts. |
start | Integer-compatible scalar | No | Non-negative integer offset, default 0. |
length | Integer-compatible scalar | No | Positive integer page size, default 10. -1 is rejected; use isTable=0 for an unpaged result. |
draw | Integer-compatible scalar | No | Table-mode draw echo, default 0. |
limit | Integer-compatible scalar | No | Non-negative integer limit in unpaged mode; omitted/0 means no result limit. |
searchValue | String | No | Trimmed lower-case contains search. Blank/falsey trimmed text disables it; LIKE wildcards remain active. |
searchField | String or native array | No | Search names or All (default). Invalid names contribute no search predicate; search is against mapped columns, not automatically related display names. |
Mapped field filters | Scalars or native arrays | No | Text scalar values are case-insensitive contains; arrays use IN. Numeric scalar filters integer-convert. Combines with search and endpoint filters. |
orderBy / orderDesc | Mapped name / direction text | No | Supply both for explicit order. orderBy matches a mapped name case-insensitively, with unknown names falling back to a valid projected field. orderDesc must be asc/desc and is normalized to lower case. |
order | DataTables order array | No | Without explicit order pair, order[0].column is converted then reduced by one; default mapped first field ascending. dir=desc reverses it. |
groupBy | Native field-name array | No | Native mapped field-name array for ordinary lists. A non-empty groupBy is rejected with container availability. |
referenceDate | Mapped date/timestamp field name | No | Activates date/hour controls for that field. |
dateFrom / dateTo | Integer-compatible day offsets | No | Both present: inclusive start-day 00:00:00 through end-day 23:59:59 relative to today's tenant date (timezone setting, UTC fallback). These are relative offsets, not YYYY-MM-DD dates. |
offsetFrom / offsetTo | Objects with hour,minute | No | Hour offsets are negated and minute offsets added to their respective date boundaries. |
timeRangeFrom / timeRangeTo | Integer-compatible hours | No | Hour filter starts only when timeRangeFrom is present; a lone timeRangeTo is ignored. Default ending hour 23, reversed bounds swap. Uses tenant timezone with Europe/London fallback. |
advanceSearch | Native condition array | No | Native structured conditions on mapped columns: column/id, condition and scalar/native-array value, with optional AND/OR connector and bracket marker. Raw where clauses are rejected. Supported conditions: equal, notEqual, contains, greaterThan, greaterThanOrEqual, lesserThan, lesserThanOrEqual. |
isAll | Boolean-compatible scalar | No | Omitted/PHP-falsey restricts stored main.qty>0. Truthy removes that predicate. |
supplierParams | Native array | No | Native array of positive integer supplier IDs. Uses exact supplier_id IN membership, not regex substring matching; [] selects no rows. |
statusParams | Native array | No | Native array containing only 0 (active) and/or 1 (archived). Non-empty input joins the catalog and filters is_archived; [] adds no archive restriction. This does not exclude deleted catalog references. |
container | Object {id,type} | No | Object with id and a supported EnumStockSource type. Owner IDs are bounded scalar text, preserving UUIDs. type=0 subtracts positive non-dispatched allocations; other types return that owner/type's allocation quantities. Adds stockID and qty to output. |
Example request
$page = FM_api('StockInventories_getDataTable', ['fields'=>['id','name'], 'start'=>'0', 'length'=>'10', 'draw'=>'1']);
Example response
{"data":[{"id":"1042","name":"Filter cartridge"}],"draw":1,"recordsTotal":"1","recordsFiltered":"1"}
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"} | fields omitted. |
{"error":"error in database query"} | The main list query fails, including invalid SQL from unsafe legacy controls. |
{"error":"unsupported raw advanced search"} | advanceSearch contains a raw where key. |
{"error":"missing or invalid parameter: orderDesc"} | Explicit order direction is not asc/desc. |
{"error":"groupBy is not supported with container"} | Availability request also asks for grouping. |
{"error":"invalid saved inventory allocations"} | Saved structured allocations contain malformed entries. |
{"error":"inventory read failed"} | Allocation lookup fails. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- Table mode returns data, integer draw, recordsTotal and recordsFiltered. Total counts active rows in the tenant table. Without container, filtered counts reflect SQL predicates; with container, recordsFiltered is an integer count after availability exclusion, before final pagination.
- isTable=0 returns only data and has no default limit. It orders by referenceDate ascending when that mapped field is supplied; otherwise no default order is imposed. Table mode defaults to first valid projected field ascending. Unknown fields are skipped; id is always included.
- An active-only deleted=0 filter is applied to the main table. Unix timestamp fields render through database FROM_UNIXTIME.
- supplier/storage requested fields join their tables and add nested {id,name} objects, unlike the singular detail endpoint. Temporary flattened aliases can remain alongside these objects. Joined suppliers and storage rows exclude soft-deleted rows.
- No exact caller was found in current app JavaScript or m/www for this office endpoint; app stock quantities use the separate mobile sync/transaction paths.
- container forces stockID and qty into output, preserving fractional quantities. Structured meta.inventory allocations take precedence over the legacy inventory_id/amt representation; duplicate structured entries are summed once each. Non-empty container owner IDs are not integer-converted, so UUID owners remain addressable.
- Availability is computed while scanning stable 500-row SQL batches. Non-positive adjusted rows are excluded before the final offset/length or unpaged limit; recordsFiltered counts available matching rows, while recordsTotal still counts all active inventory rows.
- This availability scan must inspect all SQL-matching rows to compute an accurate count. It keeps only the requested page (unless unpaged without a limit) but may take longer on a large inventory. Ordering remains based on stored mapped fields, with inventory ID as a stable tie-breaker.
- Invalid structured allocation quantities/types return an error rather than being silently ignored. Query and allocation read failures are reported.
- recordsTotal counts only active main inventory rows; isAll includes active zero/negative balances, never deleted rows. Supplier/storage joins also exclude deleted linked rows.
Side effects
- Read-only: no default storage creation, stock movement, history, edit timestamp or configured event.
See it in Fieldmotion
CRM1
No direct CRM1 caller was found for this exact endpoint; the legacy Stock page uses its separate catalog/container APIs.
CRM2
Open Stock Inventory or a Stock Location's inventory table. The table uses StockInventories_getDataTable through the StockInventory/StockInventories prefixes; mapped detail helpers read StockInventory_getRequestedDetails. Filter Network for StockInventories_getDataTable.
Related endpoints
StockInventory_getRequestedDetailsreads stored mapped values; an omitted ID can retrieve all active tenant rows.StockInventory_createDatacreates a new inventory row rather than changing physical warehouse stock.