When to use this endpoint

Use before choosing whether to allocate existing stock or order a shortage. This is a snapshot calculation; execute and verify the later movement separately.

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

ParameterTypeRequiredDescription
stockNative array of rowsYesNative list of {id,container,qty}; container is sourceType_ownerID, e.g. 0_0 or 2_vehicleUUID. All rows must have a positive stock ID, supported source type 0–22 and finite nonnegative qty. Zero qty is a no-op; malformed rows fail the whole preview.
linkNative {id,type} objectNoOptional allocation context. Uses stock-source types, including 7 Job or 12 Quote; these differ from Requisition target-type numbers.

Example request

$availability = FM_api('Stocks_checkAvailable', ['stock'=>[['id'=>'1042','container'=>'0_0','qty'=>'4']]]);

Example response

{"ok":1,"outOfStock":[{"id":1042,"qty":1,"index":0}],"inStock":[{"id":1042,"qty":3,"index":0}],"roID":0}

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

ResponseCondition
{"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"}stock missing or not a native array.

Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.

Behaviour and edge cases

  • Preserves fractional quantities. Repeated rows share a remaining balance per stock/logical source and consume it in input order; index identifies the original input row. Numeric and UUID vehicle aliases share the same remaining counter.
  • Type0 reads warehouse; type15 sums matching order_containers for that Requisition and optional link context; other sources read their exact allocation. Negative saved balances display as zero. Missing active stock, ambiguous duplicate allocation rows, invalid owner/quantity or missing vehicles return a controlled error.
  • Only positive inStock entries are returned. Empty stock returns ok:1,empty lists,roID=0. No reservation or write is performed; a later movement must independently check the then-current balance.
  • roID is a Requisition ID only. A single explicitly selected Requisition supplies it; ordinary owner IDs do not. On a shortage with link.type=7 Job or12 Quote, the reader looks directly for undeleted Requisitions targeting that exact Job/Quote. Zero or multiple candidates returns0, never an arbitrary owner ID. No order status restriction is added.

Side effects

  • Database reads only; no reservation, movement, alert or history entry is created.

See it in Fieldmotion

CRM1

No direct CRM1 caller was found. CRM1 legacy allocation editors perform their own warehouse-based limits.

CRM2

In CRM2, start creating an order from stock (widgetOrder) or load reserved Quote stock into a Job (widgetStock). Filter Network for Stocks_checkAvailable; callers send a native row list, and use returned index to map the split back to input.

Related endpoints