Stock inventory, storage and bundles
Set one mapped bundle field on selected records
/a/StockBundle_updateField
Set one mapped bundle field on selected records.
When to use this endpoint
Use for a narrow edit instead of replacing a full layout payload. Choose a mapped field; this route does not translate bundle widget rows.
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 |
|---|---|---|---|
field | String | Yes | Allowed mapped names: id, name, stocks, meta, cdate, lastEdited. UI readonly does not prevent writes; avoid field=id because it can rewrite a primary ID. |
val | Scalar or JSON/native structure as mapped | Yes | Converted to the selected map type. Missing/null val is rejected. Blank stocks/meta becomes SQL NULL; other text values remain strings. No required-name validation on this narrow setter. |
id | Scalar or native array | One of id/ids | Integer-converted target IDs. Takes precedence over ids. |
ids | Scalar or native array | One of id/ids | Alias when id is absent. Empty arrays are not explicitly rejected; SQL can fail and be treated as no-change. |
Example request
$saved = FM_api('StockBundle_updateField', ['id'=>'1042','field'=>'name','val'=>'Service kit']);
Example response
{"ok":1,"oldData":[{"id":"1042","name":"Old name"}]}
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: field"} | field omitted. |
{"error":"missing or invalid parameter: val"} | val omitted/null. |
{"error":"missing or invalid field"} | Unknown field. |
{"error":"missing or invalid parameter: id/ids"} | Neither target key supplied. |
{"ok":"1","warning":"no change required"} | No differing rows, missing targets or failed row read. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- A changed response includes raw prior id/column values in oldData. No-change uses string ok='1' and a warning, whereas a changed save uses numeric ok=1.
- Required/readonly map metadata is not enforced here; name can be blank and id can be reassigned. Strict comparison before conversion can touch/log a logically unchanged numeric value.
- Write success is not checked. The operation is not atomic with Core_log history, and there is no compare-and-swap/version guard.
- The mobile intermediary m/www/php/functions/syncDownloads.php reads stock_bundles as stockBundles. Current app code expands those locally synchronized components; it does not directly call this office endpoint.
Side effects
- Writes the selected mapped column, server last_edited, invalidates stock_bundles cache and records one Core_log entry. No stock movement or configured event is performed.
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
The generic mapped autosave helpers can build StockBundle_updateField; no dedicated Stock Bundles page action was found for this narrow route. Those pages use updateData for their normal saves.
Related endpoints
StockBundle_getRequestedDetailsreads stored mapped values; an omitted ID can retrieve all active tenant rows.StockBundle_createDatacreates a new bundle rather than changing physical warehouse stock.