When to use this endpoint

Use the Stock Returned workflow after selecting a real allocation and its batch choice. It performs quantity changes, unlike the record-only history and dispatch insert routes.

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
stockIDInteger-compatibleYesCatalogue item ID.
containerNative {id,type}YesNative source owner/type object; not an allocation row ID. Numeric and legacy UUID Vehicle identifiers resolve to the same owner. The recorded return owner is its numeric ID.
qtyFloat-compatibleYesFinite positive return quantity no greater than the source allocation and selected batch balance. Negative,zero,nonnumeric/nonfinite input fails before commit.
typeInteger-compatibleYesOnly3 (Return). Other operation types are rejected without changing any balance.
inventoryIDInteger-compatibleYesPositive batch must be active and stock-owned;0 selects an unassigned return to active default storage1/supplier0. The actual reused/created inventory ID is recorded in the return ledger.
descriptionStringNoOptional return description; omitted/null defaults to an empty string. Supply the source through container; scalar containerID/containerType aliases do not override it.
userID / cdateID / Unix or parseable datetimeNoDefault current actor and now. Layout readonly flags do not prohibit supplied values.

Example request

$return = FM_api('StockReturned_createData', ['stockID'=>'1042','container'=>['id'=>'1088','type'=>'1'],'qty'=>'2.5','type'=>'3','inventoryID'=>'3088','description'=>'Unused stock']);

Example response

{"ok":1,"id":5081}

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":"no inventory available"}Positive inventory ID is missing/deleted or belongs to another stock item.
{"error":"missing or invalid parameter"}One of the five required top-level keys is missing.
{"error":"Invalid stock container."}Delegated Return cannot find the allocation.
{"error":"Insuffient stock"}Delegated Return quantity exceeds the saved allocation.
{"error":"invalid stock return"}type is not3 or container is not a native object.
{"error":"The selected batch does not have sufficient allocated stock."}The requested batch quantity exceeds its source assignment.
{"error":"default stock location is not available"}The default unassigned return location is unavailable.

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

Behaviour and edge cases

  • Requires all five top-level values and type3. Locks the tenant catalogue,active stock and exact allocation. Missing/ambiguous source,over-return,invalid batch evidence or nonfinite quantity returns error without committing any changes.
  • Reduces the selected allocation in place,retaining its ID and other metadata,including an exhausted zero row. Structured batch assignments are reduced for the selected batch; quantities cannot exceed the saved allocation. A legacy unassigned allocation can select a real stock-owned batch when returned.
  • Increments warehouse and the selected active inventory. inventoryID0 reuses/creates an active stock inventory at fixed storage1/supplier0; the default location must be active. The return record stores that actual inventory ID rather than leaving0.
  • Allocation,warehouse,batch,return record,checked audits and movement history commit in one transaction. A failure at any read/write/history/audit/commit rolls back the full request. Configured Stock_edit runs after commit; a warning can indicate committed primary success.
  • The route has no idempotency token. A failed acknowledgement or post-commit warning requires a fresh balance/ledger read before retrying; an atomic database transaction does not prove a request was never committed when the connection fails.

Side effects

  • Updates source/warehouse/inventory sync values and caches,retains allocation identity/metadata,and records the return and movement history with checked audits in one transaction. Relevant User/Vehicle/Location sync timestamps are advanced. Stock_edit runs after commit.

See it in Fieldmotion

CRM1

No direct CRM1 caller was found. Legacy allocation editors use negative Stock_containerAdd deltas, which do not create return ledger records.

CRM2

In CRM2 open Stock Returned and create a return. pageStockReturned sends one type3 request per stock/batch. Each success removes only its acknowledged input rows; errors retain failed drafts and the dialog. The caller handles helper errorCallback,prevents duplicate submission while pending,and announces completion only when all requests succeed.

Related endpoints