Stock items and catalogue maintenance
Restore a deleted stock item
/a/Stock_restore
Restore one stock tombstone through an Admin-console authenticated session.
When to use this endpoint
Use the Admin deletion-history restore flow. Ordinary CRM login or a tenant API key does not satisfy the required login source.
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.
Core_requireLogin plus session login_source=admin-console is mandatory; client administrator status alone is insufficient.
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. |
Example request
// Requires an Admin-console authenticated session; an ordinary signed-only call is refused.
$result = FM_api('Stock_restore', ['id'=>'18']);
Example response
{
"ok": 1,
"type": "stock",
"id": 18,
"label": "Stock #18 (Valve)",
"summary": {
"type": "stock",
"id": 18,
"name": "Valve",
"code": "VALVE-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"} | ID is absent or integer-converts below 1. |
{"error":"admin console login required"} | Session login_source is not exactly admin-console. |
{"error":"deleted stock not found"} | No deleted item matches. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- Delegates to apiDeletedObjectRestore(stock). Requires deleted=1, then resets deleted/ddate only; is_archived and existing last_edited remain unchanged.
- Marks matching tenant deletes-log entries restored with restoration user/function metadata. Does not recreate accounting links/queues, rebalance stock, rebuild categories or update allocation/supplier rows.
- Returns ok,type,id,label,summary. summary contains type/id and nonblank saved name/code; label incorporates the saved name.
Side effects
- Updates the stock tombstone and restoration metadata in the deletion log; invalidates stock cache. The helper’s writes are separate and unchecked.
See it in Fieldmotion
CRM1
No ordinary CRM1 stock restore caller was found. Restoration is an Admin-console deletion-history operation.
CRM2
No ordinary CRM2 stock restore caller was found. Use the Admin-console workflow; it is not a CRM2 role-controlled stock action.
Related endpoints
Stock_delete— Soft-delete one catalogue item and record its tenant deletion event.Stock_get— Read the full saved stock row, with selected manufacturing metadata flattened for the legacy editor.