Stock allocations and movement records
Update one allocation field
/a/StockContainer_updateField
Write a mapped allocation column directly, without balancing warehouse or batch stock.
When to use this endpoint
Use only when maintaining allocation data itself. Changing qty here is not a Stock_transaction and does not update warehouse, stock inventories or stock movement history.
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 |
|---|---|---|---|
id / ids | Scalar/native allocation ID list | Yes | id takes precedence. Native, JSON-encoded and comma-separated lists select multiple allocation rows. Empty lists are rejected. |
field | Mapped field name | Yes | Writable map fields: qty,amtTrigger,inventoryID,meta,metaInventory. Primary/stock/owner identity and unsupported fields are rejected. |
val | Non-null mapped value | Yes | Non-null mapped value. qty is finite numeric and preserves fractions, including explicit zero. amtTrigger is finite amount|valid-email; inventory IDs are nonnegative and positive references must be active and stock-owned. Native/encoded JSON metadata is supported. |
Example request
$result = FM_api('StockContainer_updateField', ['id'=>'2081','field'=>'qty','val'=>'2']);
Example response
{"ok":1,"oldData":[{"id":"2081","amt":"3"}]}
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":"Unable to find stock container"} | One or more selected allocation rows are absent. |
{"error":"allocation identity is not editable"} | Full save contains a protected stock/owner field. |
{"error":"missing or invalid field"} | Inline field is not in the write allowlist. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- Checks every selected allocation and its active catalogue stock inside one checked transaction. Quantity edits retain decimal values; nonnumeric/nonfinite input is rejected. These remain data corrections and do not balance warehouse or stock inventory.
- Only quantity,threshold and inventory metadata are editable. IDs and owner/stock relationships cannot be reassigned through these routes. Full-save display timestamps/transport metadata are ignored; inline unsupported field names are rejected.
- Positive inventory references must be active and belong to the allocation’s stock. Structured batch quantities must be finite,nonnegative and fit the resulting allocation quantity. Explicit zero inventoryID means unbatched; supplied metadata replaces that metadata value rather than merging arbitrary keys.
- All bulk targets and checked audit writes commit together. Any failed target/read/write/audit/commit rolls back the entire save. Empty or malformed ID selections return controlled errors; unchanged valid values acknowledge ok:1.
- Inline success includes oldData with the prior storage column (qty uses amt); an unchanged valid edit also returns ok:1. JSON-path bulk changes are inside the same transaction.
Side effects
- Writes changed allocation columns and server last_edited, invalidates stock_container cache and records checked allocation audit evidence. Does not update warehouse/batch balances, owner timestamps or fire Stock_edit.
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
No direct CRM2 quantity-edit caller was found for this route. User/Vehicle stock tables are read-only except for the dedicated threshold action; movement controls use Stock_transaction. Tests and shared helpers use raw allocation updates for metadata.
Related endpoints
StockContainer_getRequestedDetails— read the persisted allocation after a correction.StockContainer_updateOneField— use the checked identity-based threshold route.