Stock items and catalogue maintenance
Edit mapped stock fields
/a/Stock_updateData
Update stock fields, category membership and picker values through the full mapped save.
When to use this endpoint
Use for a stock layout save. Omitted fields are retained; Stock_add remains the separate legacy import/upsert route with signed quantity increments.
Authentication and permissions
Authenticate with a signed API key or a logged-in CRM session on the account’s routed host. API keys act as their owner; session calls require dispatcher CSRF protection where configured. IDs address the authenticated tenant.
These stock handlers do not add a Stock page-action or CRM2 role check, and the dispatcher has no Stock/Stocks TeamAccess object mapping. CRM2 screen controls are separate from this shared API contract; their roles must not be assumed to apply to CRM1.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | Scalar or native array | Yes | Stock ID or native bulk-update ID list. All undeleted targets are checked before saving; category and event handling applies to each item in one transaction. An empty list is a no-op. |
Stock fields | Mapped values | Depends on operation | Mapped names: id,name,averageCost (alias cost),cDate,ownerID,inStock,categories,categoryIDS,lastEdited,code,isArchived,amtTrigger,description,supplierID,price,notes,nominalCode,taxRate,meta,editedUUID,priceBands. Metadata projections: metaManufacturer,metaBarcode,metaManufacturerPartNo,metaSupplierPartNo,metaSuppliers,metaUnit,metaTaxRateID,metaNominalCodeID,metaNominalID,metaNominalName,customValues,metaReferrenceType. taxType is a composite picker with id,taxRate,nominalID,nominalName,nominalCode. Preserve the misspelling metaReferrenceType. |
taxType | Native picker object | No | Expands id→metaTaxRateID, taxRate→taxRate, nominalID→metaNominalID, nominalName→metaNominalName, nominalCode→nominalCode. Keep nominal IDs, codes and display names distinct. |
categoryIDS | ID list / JSON list / comma text | No | The full wrappers normalize positive IDs, deduplicate/sort, and save them as JSON strings. Unknown category IDs return an error; empty category lists remain supported. |
widgetPriceBand | Encoded JSON or mapped value | No | Alias to priceBands on full create/update; underlying JSON replaces the saved value. |
taxRate | Integer-compatible category ID | No | Full wrappers save the input as metaTaxRateID and replace taxRate with the selected account_categories.tax_rate, preserving fractions. A composite taxType object expands later in the shared helper and can supply its own percentage. |
Example request
$result = FM_api('Stock_updateData', ['id'=>'18', 'name'=>'Replacement valve', 'categoryIDS'=>json_encode(['7'])]);
Example response
{
"ok": 1
}
Application errors can use HTTP 200. Inspect error/warning fields; database numeric values can be strings unless this handler explicitly converts them.
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"} | Selection is absent. |
{"error":"stock does not exist"} | A category update’s initial item lookup failed. |
{"error":"Unable to update record"} | Generic UPDATE failed. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- Omitted mapped business values remain unchanged. Explicit zero price and taxType.id=0 are supported. Display lifecycle fields cDate,lastEdited,editedUUID,ownerID are not writable through layout payloads.
- Native bulk IDs are normalized and every undeleted target is checked/locked before saving. Each selected item receives its own category membership, history and Stock_edit; a failed target/category rolls the whole batch back. Empty ID arrays are a no-op.
- Top-level taxRate is a category ID whose full fractional rate is preserved; missing positive categories fail. taxType is a native picker object and ID 0 clears tax/nominal values.
- categoryIDS replaces the selected memberships, including explicit empty-list clearing. widgetPriceBand remains an alias to priceBands. Saved prior values are retained for mention comparison.
- Primary changes and stock history use a checked transaction. Failed validation/read/write/commit returns an error and rolls back open changes. Configured events/notices run after commit; a post-commit warning means the save succeeded and must not be repeated blindly.
Side effects
- Checked stock/category/history/cache changes; configured Stock_edit and mention notices after commit.
See it in Fieldmotion
CRM1
No direct CRM1 Stock_updateData caller was found. CRM1 uses Stock_add and individual legacy setters.
CRM2
Open Stocks in CRM2. Stock layouts derive Stock_createData, Stock_updateData and Stock_getLayoutDetails through the shared helpers; the grid calls Stocks_getDataTable. Inspect the exact function name in Network requests. Save a Stock layout or the tax picker; inspect the native taxType object and categoryIDS payload, then reload the item.
Related endpoints
Stock_createData— Create a catalogue record from CRM2 layout fields and synchronize category membership.Stock_updateField— Set one mapped field for one or more stock items using the inline-save contract.Stock_getLayoutDetails— Read mapped stock rows while adapting price-band widgets and tax category selections.