Stock catalog fields and lookups
Set the legacy single stock supplier
/a/Stock_supplierSet
Replace stock.supplier_id without changing current multi-supplier pricing records.
When to use this endpoint
Use for the legacy stock editor’s one-supplier assignment. Set supplier_id=0 to clear it; this does not clear stock_suppliers.
Authentication and permissions
Authenticate with signed API-key fields or a logged-in CRM session. This handler requires both a user identity and tenant context; it adds no stock-page, finance or administrator permission check.
All queries use the authenticated tenant. API signing and session CSRF checks still apply; see Getting started.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | Integer-compatible string | Yes | Stock ID converted with intval; must be at least 1. |
supplier_id | Integer-compatible string | Yes | Required scalar, integer-converted; zero clears the legacy scalar assignment. Negative values are rejected. Positive IDs must resolve to a non-deleted supplier (inactive/on-hold suppliers are allowed). |
Example request
$result = FM_api('Stock_supplierSet', ['id'=>'1042', 'supplier_id'=>'1088']);
Example response
{"ok":"1"}
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"} | Missing/nonpositive id. |
{"error":"missing or invalid parameter: supplier_id"} | supplier_id absent/null. |
{"error":"stock catalog write failed"} | A primary write or required history insert fails; the transaction rolls back. |
{"error":"stock catalog read failed"} | A checked read fails; a normalization or write transaction is rolled back. |
{"error":"stock catalog transaction failed"} | Transaction start or commit fails; no success is returned. |
{"error":"stock catalog operation failed"} | Unexpected database/runtime failure during the transaction. |
{"error":"Stock item does not exist"} | Missing/deleted target stock. |
{"error":"supplier does not exist"} | Positive supplier ID is missing/deleted. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- Locks a non-deleted stock row and validates/locks a positive non-deleted supplier. Archived stock remains editable. No-op returns string ok without timestamps/history/events.
- Does not maintain manymany or stock_suppliers, supplier cost/price or part numbers.
- Checked stock write and field history commit together; Stock_edit runs afterwards. No stock-page or supplier setting is consulted.
- No direct mobile caller was found in the current app JavaScript or
m/wwwintermediary. The app receives stock throughsyncDownloads, which selects non-deleted stock by edit timestamp; these calls are not the app synchronization protocol.
Side effects
- On change, writes supplier_id, server last_edited, edited_uuid=Stock_supplierSet and checked history; invalidates stocks cache.
- Runs configured Stock_edit after commit; no stock movement.
See it in Fieldmotion
CRM1
Click the Stock supplier cell and choose a supplier or blank option. CRM1 sends id/supplier_id here; choosing Add new creates a supplier first through Stock_supplierAdd.
CRM2
No direct call was found. The Stocks module uses a multi-supplier editor; do not substitute this scalar setter for StockSupplier_setSuppliers.
Related endpoints
Stock_suppliersGetloads the old selector.StockSupplier_setSupplierschanges the separate multi-supplier records.