Stock items and catalogue maintenance
Read a stock item
/a/Stock_get
Read the full saved stock row, with selected manufacturing metadata flattened for the legacy editor.
When to use this endpoint
Select an item ID from Stocks_list/getById or a grid. Use mapped readers when the caller needs camelCase fields or layout tax IDs.
Authentication and permissions
Authenticate with a signed API key or a logged-in CRM session on the account’s routed host. API keys act as their owner; session calls require dispatcher CSRF protection where configured. IDs address the authenticated tenant.
These stock handlers do not add a Stock page-action or CRM2 role check, and the dispatcher has no Stock/Stocks TeamAccess object mapping. CRM2 screen controls are separate from this shared API contract; their roles must not be assumed to apply to CRM1.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | Integer-compatible | Yes | Positive stock catalogue ID. It is not a stock-container row ID, category ID or supplier ID. |
Example request
$result = FM_api('Stock_get', ['id'=>'18']);
Example response
{
"id": "18",
"name": "Valve",
"code": "VALVE-1",
"average_cost": "12.5",
"in_stock": "8",
"category_ids": "[\"7\"]",
"categories": "Heating",
"price": "20.0000",
"tax_rate": "20.00",
"meta": "{\"barcode\":\"12345\"}",
"is_archived": "0",
"deleted": "0",
"location": "",
"manufacturer": "",
"barcode": "12345",
"manufacturer_part_no": "",
"supplier_part_no": ""
}
Application errors can use HTTP 200. Inspect error/warning fields; database numeric values can be strings unless this handler explicitly converts them.
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: id"} | ID is absent or integer-converts below 1. |
{"error":"stock item does not exist"} | No undeleted item matches. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- Returns the full undeleted stock row with encoded JSON columns, raw meta.location_tags under location and four flattened manufacturing keys. Archived items are included. The response example shows selected real columns.
- The legacy mismatched category-name/ID repair remains: valid category IDs win, then unmatched names use the first category ordered by parent_id. Equal-length stale names do not trigger this historical heuristic.
- A repair now locks the item under the tenant category lock, checks that its source fields have not changed concurrently, and commits checked category writes/history plus last_edited/edited_uuid=Stock_get. A concurrent change is retained and freshly read instead of overwritten.
- No direct CRM1 Stock_get caller was found: its cached Stock model uses Stocks_getById. Current mobile transport uses its separate sync routes.
Side effects
- An actual category repair can write stock, history and sync timestamps and run configured Stock_edit after commit. Ordinary matching reads do not write.
See it in Fieldmotion
CRM1
CRM1’s cached Stock model uses Stocks_getById, including the editor’s selected item. No direct current Stock_get caller was found; internal/API callers can use this full-row reader.
CRM2
Open Stocks in CRM2. Stock layouts derive Stock_createData, Stock_updateData and Stock_getLayoutDetails through the shared helpers; the grid calls Stocks_getDataTable. Inspect the exact function name in Network requests. Normal layouts use mapped readers rather than this legacy full-row contract.
Related endpoints
Stocks_getById— Read an explicit stock-ID selection using saved snake_case columns.Stock_getRequestedDetails— Return projected stock rows with optional supplier and allocation summaries.Stock_getDetails— Return four stock metadata values as a JSON string inside the API JSON response.Stock_updateData— Update stock fields, category membership and picker values through the full mapped save.