Import history
Remove records created by an import
/a/ImportHistory_deleteById
Attempt per-object deletion for records carrying a run’s created-import token, then remove its log.
When to use this endpoint
This is the bulk History removal route. It is not a transaction, an edited-value rollback or the richer per-record selection performed by the interactive removal dialog.
Authentication and permissions
Use signed API-key authentication or a logged-in CRM session. API keys act as their owner; session requests use dispatcher CSRF protection when configured.
Requires a valid tenant account and View on pageImportsHistory plus Delete. Reads and writes use this account’s tenant tables.
Requires View/Delete on the selected business-object page. All matching active records must be in TeamAccess scope before any child delete is attempted.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | Positive integer or decimal integer string | Yes | Positive tenant imports_log row ID (mapped id or sixth legacy grid cell). Do not send the importID run token. |
Example request
$result = FM_api('ImportHistory_deleteById', ['id'=>'312']);
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": "permission denied"} | The user lacks the required Imports page action. |
{"error": "missing or invalid parameter: id"} | A required row ID is missing or invalid. |
{"error": "invalid import_id provided"} | The requested owned source or tenant row does not exist. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- Supports Jobs 0, Customers 1, Contracts 5, Assets 6, Stock 7 and Suppliers 10. Unsupported types fail and retain the history row. Active created_by_import_id associations match both JSON string and numeric forms. Cleanup deliberately has no log-day date cutoff; listItems created preview does.
- Preflights all matching active records against visible scope, then invokes the existing Job_delete, Customer_delete, Contract_delete, Asset_delete, Stock_delete (force=1) or Supplier_delete routes. Their lifecycle, guards, relationship effects and audits remain authoritative.
- Checks every child acknowledgement and persisted deleted state. A failure returns error, deletedIds, failedId and importLogId, retaining history so cleanup can be retried. Earlier removals are not repeated once records are inactive.
- After all children succeed, rechecks log identity and remaining active associations, then removes the log with an audit in a checked transaction. A changed run or remaining record retains history. Does not restore edited field values, maps, source settings or remote files.
Side effects
- Runs existing business-object removals, including their relationship/audit effects. Removes/audits history only after verified completion; partial failures retain the history. No global rollback or remote file operation.
See it in Fieldmotion
CRM1
In CRM1 History, select multiple runs and confirm Delete Imports; inspect ImportHistory_deleteById. The individual-run removal dialog can instead preview IDs and call object routes.
CRM2
In CRM2 History, bulk Delete Imports calls this route per selected log. Its visible per-run type choices include Supplier and this endpoint supports Supplier cleanup.
Related endpoints
ImportHistory_getDataTable— Find the log row ID.ImportHistory_listItems— Inspect metadata-associated IDs.ImportHistory_delete— Remove history only.