Assets
Set an asset department
/a/Asset_setDepartmentId
Replace an asset’s department assignment with an integer ID.
When to use this endpoint
Use Asset_setDepartmentId for the department selector on a known asset.
Supply 0 to clear the assignment. The endpoint does not validate positive IDs against the department table.
Authentication and permissions
The request must authenticate with signed API-key fields or a logged-in CRM session. The handler performs no additional page or role-permission check.
The lookup and any write use the authenticated tenant; an ID from another tenant cannot be addressed through this call.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | Integer string | Yes | Positive server-side asset ID. The existence check includes soft-deleted assets. |
department_id | Integer string | No | Converted with intval; omission, blank, and nonnumeric input become 0. Positive, negative, and nonexistent department IDs are not rejected. |
Example request
$result = FM_api('Asset_setDepartmentId', [
'id' => '4821',
'department_id' => '23',
]);
Example response
{
"ok": 1
}
If the converted value equals the stored department ID, the response is {"ok":1,"warning":"no change needed"}.
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 does not convert to a positive integer. |
{"error":"asset does not exist"} | No asset row has the ID. Soft-deleted rows still count as existing. |
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 no-change path returns before timestamps or audit data change.
- The endpoint can update archived or soft-deleted assets.
- This is a single-record mutation; it provides no list filtering or pagination.
Side effects
- A real change updates
department_idandlast_edited, setsedited_uuidtoAsset_setDepartmentId, invalidates the asset cache, and writes an asset audit entry.
See it in Fieldmotion
CRM1
Open Assets, expose/edit the Department field for a row, and filter Network requests for Asset_setDepartmentId. CRM1 supplies IDs from Departments_getNames.
CRM2
No direct production CRM2 call to Asset_setDepartmentId was found; CRM2 uses its broader update contract.