Stock inventory, storage and bundles
Create an inventory row without recording a stock movement
/a/StockInventory_createData
Create an inventory row without recording a stock movement.
When to use this endpoint
Use for a new inventory row. This is a metadata/row insertion, not a goods-received or stock movement transaction.
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 |
|---|---|---|---|
stockID | Integer-compatible scalar | No | Maps to stock_id. Creation looks up stock costing defaults, including retained deleted/archived stock. Missing or invalid catalog IDs are not rejected as foreign-key errors by the handler. |
name | String | No | Omitted creation derives the stock name, possibly overridden by a stock_suppliers row. Explicit blank is retained. |
supplierID | Integer-compatible scalar | No | Saved supplier_id if supplied. Creation uses the stock scalar supplier only for defaults lookup; it does not copy that derived ID into the request. |
supplier | Object | No | Legacy layout-value input with id/name; its id expands to request.id, not supplierID. Do not use it to assign a supplier; prefer supplierID. Its name expands to request.name and can overwrite the row name; the composite field itself is not persisted. Creation ignores that expanded id. |
storageID | Integer-compatible scalar | No | Saved storage_id; 0 is allowed. No storage existence check. |
storage | Object | No | Legacy layout input with id/name; its id expands to request.id rather than storageID. Use storageID for assignment. Its name expands to request.name and can overwrite the row name; the composite field itself is not persisted. Creation ignores that expanded id. |
goodReceivedID | Integer-compatible scalar | No | Saved goods-received linkage; no linked-record validation. |
qty | Number-compatible scalar | No | Float-converts, including negative or fractional input; no minimum or inventory/warehouse consistency guard. |
cost | Number-compatible scalar | No | Float-converts. Omitted creation derives stock average cost, with stock_suppliers override if found; explicit 0 is retained. |
price | Number-compatible scalar | No | Float-converts. Omitted creation derives stock price, with supplier override if found; explicit 0 is retained. |
reference | String | No | Saved batch/serial text. No uniqueness or generation is performed. |
receivedDate | YYYY-MM-DD or blank | No | Must round-trip as a real SQL date or be blank. Blank becomes SQL NULL; it is not the creation date. |
cdate | Unix seconds or date/time string | No | Defaults to now on creation; supplied values are accepted. |
lastEdited | Unix seconds or date/time string | No | On creation omitted gets server Unix seconds; changed mapped updates also set server time. |
Example request
$saved = FM_api('StockInventory_createData', ['stockID'=>'2042', 'storageID'=>'1', 'qty'=>'2.5']);
Example response
{"ok":1,"id":1042}
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 date parameter: receivedDate"} | Invalid non-blank SQL date. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- UI readonly/hidden field metadata is not a write-access guard. Values integer-/float-convert according to the map; no minimum, finite-value or foreign-object validation is supplied here.
- Creation is not atomic with history, and the insert result is not checked for a positive ID before returning ok. Re-read saved values before replaying an uncertain response.
- Stock lookup supplies name/cost/price defaults and a scalar supplier for the stock_suppliers lookup; no deleted filter is applied. Only supplied supplierID is persisted. A stock_suppliers record can override name/cost/price, while explicit request values win.
- Creates inventory data only; creating qty does not reconcile stock.in_stock or write stock_histories. It is not a replacement for the stock transaction workflow.
- 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.
Side effects
- Writes stock_inventories and invalidates its cache. Records mapped-field Core_log creation history.
- Does not update warehouse in_stock, allocate stock, create movement history, send emails, call an external service or fire a 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
No direct createData action was found in the current Stock Inventory page. Its table uses StockInventories_getDataTable, while goods-received screens have their own receipt workflow. Do not substitute this row insertion for receiving or moving stock.
Related endpoints
StockInventory_getRequestedDetailsreads stored mapped values; an omitted ID can retrieve all active tenant rows.