When to use this endpoint

Delete one file with content cleanup, deletion logging and supported relationship refresh. Files_delete delegates selected matches through this same lifecycle; it is not metadata-only.

Authentication and permissions

Normal API transport requires signed API-key fields or a logged-in CRM session and a tenant context. Session CSRF applies except for the dispatcher’s upload/download exceptions.

These handlers do not add general Files Add/Edit/Delete or file-owner role checks. UI visibility is not that protection. Configured team-scope entry checks are separate and may validate the linked record and its Edit permission before a handler runs; see the route-specific note below. This does not introduce CRM2 role requirements for ordinary CRM1 requests.

When department/team or Assigned Jobs Only scope is configured for the actor, the dispatcher adds record-scope checks. This is selected by account features/actor flags, separately from the CRM2-only Files View check; the existing TeamAccess entry guard has no CRM-version condition. Explicit id/ids values are checked against visible file records. Other filename-only selections or mapped-filter-only bulk mutations can be rejected for lacking an explicit scoped selection.

Parameters

ParameterTypeRequiredDescription
idInteger-compatibleYesPositive ID of a currently non-deleted file. Use the tenant file-record ID returned by upload/list/detail calls. This is separate from type_id/typeId (the linked resource ID), and from the random token in a storage URL.

Example request

$result = FM_api('File_delete', ['id' => '4821']);

Example response

{
  "ok": 1
}

Errors and unusual responses

ResponseCondition
{"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 non-positive.
{"error":"file not found"}No live row matches.
{"error": "failed to delete file"}The metadata UPDATE failed.
{"error": "failed to remove file content"}Metadata is already marked deleted but clearing stored content failed.
{"error": "failed to record file deletion"}Earlier metadata/content steps completed but deletion logging 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

  • The row is marked deleted=1 with a Unix ddate and current last_edited; stored bytes/archive linkage are cleared and a deletes entry is recorded.
  • Customer and Asset file CSV fields are rebuilt. Job and recurring-Job records receive the remaining live file IDs and updated timestamps; Job edited_uuid becomes File_delete. User-file deletion writes a User audit message.
  • Database, storage, deletion-log, and parent updates are not one transaction. Explicit errors are returned if the metadata, content, or deletion-log step fails.
  • No pagination applies to this write. Use a fresh metadata/list read before dependent work; an error after storage, audit or notification work does not imply that earlier steps were rolled back.

See it in Fieldmotion

CRM1

Click delete on Customer, Job, Asset, User, Task, Asset Type, recurring-Job, or generic file tables.

CRM2

Use Delete on a modern file row; bulk framework behavior may instead call Files_delete.

Related endpoints