Stock allocations and movement records
Choose contextual stock sources
/a/Stock_getContainer
Build a source-picker list from warehouse stock and allocations related to a Job, Quote, user or customer.
When to use this endpoint
Use this picker before selecting a source for a Job/Quote stock line. It presents context-specific sources, not an exhaustive allocation list and not an availability reservation.
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 | Integer-compatible | Yes | Catalogue stock ID. Presence is checked; missing/deleted stock is not explicitly rejected. |
job / quote | Integer-compatible | No | Job context supplies assigned user/customer and, when quote is not positive, its first Job-to-Quote link. Quote context adds its allocations and linked order quantities. |
user / customer | Integer-compatible | No | Explicitly supplied values override context-derived user/customer, including zero. The user’s current vehicle is looked up. |
Example request
$sources = FM_api('Stock_getContainer', ['id'=>'1042', 'job'=>'2088']);
Example response
{"ok":1,"container":[{"id":0,"type":0,"qty":2.5,"name":""}]}
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: id"} | No id key supplied. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- Warehouse is always first as {id:0,type:0,qty,name:""}; a negative or missing warehouse balance displays as 0. Nonwarehouse rows require amt>0 and a supported matching context.
- Source types include 0 Warehouse, 1 User, 2 Vehicle, 3 Location, 6 Customer, 7 Job, 10 Stock Storage, 11 Asset, 12 Quote, 14 dispatched User, 15 Requisition, 16 Purchase Order, 18 dispatched Job and 20 dispatched Vehicle. A container row ID identifies one saved allocation; container.id identifies its owner and requires the paired type. Neither is a catalogue stock ID or a batch/inventory ID.
- User/dispatched-user sources must match the selected user; Vehicle/dispatched-Vehicle sources match that user’s current vehicle; Customer and Quote sources match their selected context. Ordinary type-7 Job allocations are skipped. Rows with unresolved names are normally omitted (user types are an exception).
- Adds positive quantities from linked Requisition/Purchase Order allocations as type 1003 LinkRequisition or 1004 LinkPurchase. Quote requisitions require Open/Approved, Quote purchase orders have no status restriction; Job purchase orders require Open. A linked Quote changes the order-container matching path.
- No paging or sort is added. Context and stock lookups do not consistently filter deleted/archived rows. There is no account feature gate in this handler.
- Vehicle allocations stored under a numeric ID or legacy UUID resolve to the user’s current numeric vehicle ID. Those numeric picker IDs are accepted by the movement and threshold writers without changing the stored allocation key. Missing/ambiguous vehicle resolution returns an error.
- When Job and linked Quote context coexist, the existing linked-order matching path continues to prefer Quote allocations; this legacy precedence is unchanged.
Side effects
- Database reads only; no reservation, movement, alert or history entry is created.
See it in Fieldmotion
CRM1
No direct CRM1 caller for Stock_getContainer was found; the legacy stock-source controls use Stock_containers and related list routes.
CRM2
Open a Job/Quote stock editor in CRM2 and change a stock line. widgetStock and widgetTableStock call Stock_getContainer with id and available Job/Quote/user/customer context; inspect the source dropdown request.
Related endpoints
Stocks_getContainers— inspect all raw rows when diagnosing a missing source.Stocks_checkAvailable— preview quantities for chosen sources.