Stock items and catalogue maintenance
Delete an archived stock item
/a/Stock_delete
Soft-delete one catalogue item and record its tenant deletion event.
When to use this endpoint
Archive first, then delete. Keep deletion distinct from archive: ordinary lists can still opt into archived stock, but exclude deleted rows.
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 | Integer-compatible | Yes | Positive stock catalogue ID. It is not a stock-container row ID, category ID or supplier ID. |
force | Present value; legacy control | No | Any non-null present value, including 0 or empty string, bypasses the archived prerequisite. Normal integrations should archive first rather than use this bypass. |
Example request
$result = FM_api('Stock_delete', ['id'=>'18']);
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":"no id given"} | ID integer-converts below 1. |
{"error":"stock does not exist"} | No undeleted item matches. |
{"error":"can only delete stock that is archived"} | Item is active and force is absent. |
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 an undeleted item and is_archived nonzero unless force is present. Marks deleted=1,ddate=Unix now,last_edited=SQL now, then records Core_logDeletion(stock,id,app_id=0).
- Deletes the item’s legacy global api_syncs_uploads queue rows and tenant api_syncs links. Does not remove allocation, supplier or category membership rows or fire Stock_edit.
- No transaction/check of the update, deletion-log and mapping cleanup results; the response does not prove all steps succeeded.
Side effects
- Tombstone/timestamps, deletion log and accounting mapping/queue removal. Cache key is stock.
See it in Fieldmotion
CRM1
Open Stock in CRM1. The legacy grid is Stock_getDT and its editor/inline actions use legacy Stock routes. Inspect the exact function name in the browser Network panel. Choose Delete for an archived item.
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. The Stocks module checks selected archive state before its legacy per-ID Stock_delete calls.
Related endpoints
Stock_restore— Restore one stock tombstone through an Admin-console authenticated session.Stock_deleteByDate— Soft-delete the tenant’s undeleted stock rows whose creation datetime begins with a date.Stock_deleteByIDs— Soft-delete catalogue items within an inclusive numeric ID interval.Stock_updateOneField— Set name, code, archive flag or threshold through the legacy inline editor.