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

ParameterTypeRequiredDescription
idInteger stringYesPositive server-side asset ID. The asset lookup includes archived and soft-deleted rows.
valInteger stringYesNew 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

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 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. 0 means no owner; it is distinct from a null movement 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_id and last_edited, sets edited_uuid to Asset_setOwner, and invalidates the assets and customer_assets cache 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_edited and edited_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_getOwner reads the current owner and optional customer name.
  • Asset_getAddress falls back to the owner’s address when current whereabouts do not resolve.
  • Asset_new accepts the initial owner and writes the first movement row.