Stock allocations and movement records
Adjust a legacy container balance
/a/Stock_containerAdd
Apply a checked legacy allocation delta while preserving its row identity and metadata.
When to use this endpoint
Use for the legacy employee, vehicle or location stock editor. amt is a signed delta, not the desired final balance. Re-read warehouse/allocation quantities after a save; select a batch explicitly through the movement workflow when consuming assigned batch stock.
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 |
|---|---|---|---|
stock_id | Integer-compatible | Yes | Positive catalogue stock ID; it must exist and be undeleted. |
container_id | String or integer | Yes | Truthy owner identifier: numeric owner ID or a real vehicle ID/legacy UUID. Existing allocation keys are retained. Vehicle aliases resolve to one logical vehicle; ambiguous/missing vehicles fail. |
container_type | Integer-compatible | Yes | Required stock-source type, integer-compatible 0–22. Ordinary editors use 1 User,2 Vehicle,3 Location; the paired owner must be nonblank. |
amt | Float-compatible delta | Yes for a meaningful adjustment | Finite signed numeric delta; omitted/zero means no change. Negative balances remain allowed when no assigned batch quantity would be consumed. Nonnumeric/nonfinite values fail. |
do_not_adjust_warehouse | Integer-compatible legacy control | No | Default 0. Nonzero changes the allocation but skips the warehouse update, warehouse alert and Stock_edit. Not a general integration bypass. |
Example request
$result = FM_api('Stock_containerAdd', ['stock_id'=>'1042', 'container_id'=>'1088', 'container_type'=>'1', 'amt'=>'2.5']);
Example response
{"ok":1}
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":"missing or invalid parameter: stock_id"} | Missing/nonpositive stock ID. |
{"error":"You must select a container to move the stock to"} | Blank/falsy owner identifier. |
{"error":"ambiguous stock allocation; reconcile duplicate rows first"} | Multiple rows match one logical allocation. |
{"error":"Select the assigned batch before reducing this allocation."} | The delta would consume assigned batch quantities. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- Acquires the tenant catalogue lock and requires an undeleted stock item. Existing allocation identity, inventory and other metadata are retained; a missing allocation is inserted. Duplicate rows for the same logical owner/type/stock require reconciliation rather than replacement. Positive/new allocations require an existing known owner; existing negative unassigned adjustments can still reconcile a retired owner.
- Warehouse becomes previous in_stock − amt unless do_not_adjust_warehouse is nonzero. This legacy bypass still skips the warehouse change and Stock_edit. Signed delta semantics and negative unassigned balances are preserved; a zero delta acknowledges without replacing a row.
- Adding unassigned stock to a legacy inventory_id allocation first freezes the batch’s previous quantity in metadata. A reduction that would consume assigned batch quantity is rejected: choose that batch through the movement workflow rather than silently losing evidence.
- Allocation, warehouse and checked audit writes commit together. Read/write/audit/commit failure returns error and rolls back. Events/mail run after commit; a warning can mean the primary save succeeded, so reload before retrying a delta.
Side effects
- Updates allocation last_edited and stock_container cache; refreshes relevant owner sync timestamps. Normally advances warehouse last_edited/edited_uuid=Stock_containerAdd, stocks cache and checked stock history/audit, then fires Stock_edit.
- Threshold mail is queued after commit on the retained crossing rule (old > threshold and new ≤ threshold), for allocation and normally warehouse thresholds. No stock_histories movement-ledger insert is implied by this legacy adjustment.
See it in Fieldmotion
CRM1
Open a User/Vehicle/Location stock tab using stockContainerEdit or the CRM1 Stock allocation dialog. The editor sends the difference from the last acknowledged balance. Legacy Quote-to-Job copies preflight batch-dependent deductions before copying data; unassigned SOR sources remain unassigned. Failed responses retain the input/row and stop dependent bulk moves; filter Network for Stock_containerAdd.
CRM2
No direct CRM2 browser caller was found. Current stock movement controls use Stock_transaction; some shared server-side Quote-to-Job flows still call this legacy route.
Related endpoints
Stock_containerList— reload allocations for the same owner.Stocks_getContainers— reload allocations by catalogue stock IDs.