Assets
Set an asset owner
/a/Asset_setOwner
Replace an asset’s owner and, when it changes, record ownership history and refresh linked job parent caches.
When to use this endpoint
Use Asset_setOwner when assigning a known customer as owner or clearing ownership with 0.
This endpoint changes ownership only; it does not move the asset’s current location.
Authentication and permissions
The handler requires an authenticated tenant context, established by signed API-key fields or a CRM session. It checks the tenant table prefix but does not separately require a logged-in user ID.
No page, role, customer, or asset permission is checked.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | Integer string | Yes | Positive server-side asset ID. The asset lookup includes archived and soft-deleted rows. |
val | Integer string | Yes | New owner customer ID after integer conversion. Use 0 for no owner. The customer is not checked; negative and nonexistent IDs are accepted. |
Example request
$result = FM_api('Asset_setOwner', [
'id' => '4821',
'val' => '1088',
]);
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":"missing or invalid parameter: id"} | id is absent or does not convert to a positive integer. |
{"error":"missing or invalid parameter: val"} | val is omitted. A supplied blank value is accepted as owner 0. |
{"error":"asset does not exist"} | No asset row, including a soft-deleted row, has the ID. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- A strict integer comparison decides whether ownership changed. The same owner still runs the asset update and audit path, but skips movement history and job-cache refresh.
- On a real change, an older asset without initial movement history is first backfilled from its creation date and prior owner/location.
- An ownership movement uses the asset’s current location and stores the new owner explicitly.
0means no owner; it is distinct from anullmovement owner, which represents no ownership change on location-only movement rows. - The endpoint can update archived or soft-deleted assets.
- This is a single-record mutation; it provides no list filtering or pagination.
Side effects
- Updates
owner_idandlast_edited, setsedited_uuidtoAsset_setOwner, and invalidates theassetsandcustomer_assetscache keys. - When the owner changes, closes the current active movement, inserts a new active movement, and refreshes cached parent customer IDs on every non-deleted job directly targeting the asset. Changed job caches receive a new
last_editedandedited_uuid=Job_parentCacheRefresh. - Writes an asset audit entry. These writes are not wrapped in one transaction.
See it in Fieldmotion
CRM1
Open Assets, edit the Owner cell, and filter Network requests for Asset_setOwner. CRM1’s customer selector supplies the ID and redraws the asset table after success.
CRM2
No direct production CRM2 call to Asset_setOwner was found; CRM2 uses its newer asset update contract.
Related endpoints
Asset_getOwnerreads the current owner and optional customer name.Asset_getAddressfalls back to the owner’s address when current whereabouts do not resolve.Asset_newaccepts the initial owner and writes the first movement row.