Vehicles
Retrieve a user vehicle assignment
/a/Vehicle_getByUserId
Read the raw vehicle assignment stored on one tenant user.
When to use this endpoint
CRM1 uses Vehicle_getByUserId while editing job mileage: when the job has no vehicle, it looks up the assigned user’s default vehicle before loading that vehicle’s costs.
Authentication and permissions
The request must establish an authenticated tenant database through signed API credentials or a CRM session. This legacy handler checks only for the tenant database prefix and does not call the normal user-login guard.
It performs no page or role-permission check.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
userid | Integer-compatible | Yes | Tenant user ID. It must integer-convert to at least 1. |
Example request
$assignment = FM_api('Vehicle_getByUserId', [
'userid' => '94012',
]);
Example response
{"vehicle_id":"4ec721a4aa8f4ec393b6c66fd31bf611"}
The stored assignment may be a numeric vehicle ID, a vehicle UUID, an empty string, or null; the endpoint returns it without normalisation.
Errors and unusual responses
| Response | Condition |
|---|---|
{"error":"not logged in"} | No tenant database prefix is defined. |
{"error":"missing or invalid parameter: userid"} | The user ID is absent, zero, negative, or nonnumeric. |
false | No user has that numeric 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
- The lookup does not require the user to be active and does not verify that the referenced vehicle still exists.
- Only
vehicle_idis returned; user and vehicle details are not joined.
See it in Fieldmotion
CRM1
Open a job in CRM1, choose a user with an assigned vehicle, and inspect the mileage section. When the job itself has no vehicle, filter the network log for Vehicle_getByUserId.
CRM2
No direct CRM2 caller was found. CRM2’s Vehicles table loads user assignments as a separate mapped user query.
Related endpoints
Vehicle_getresolves the returned numeric ID or UUID to costs and registration details.Vehicles_getCostPerDistanceprovides a lightweight UUID-to-cost list.