Vehicles
Set a vehicle distance cost
/a/Vehicle_setCostPerDistance
Replace one vehicle’s internal distance cost through the CRM1 inline editor.
When to use this endpoint
Use Vehicle_setCostPerDistance only for the legacy single-field workflow. New mapped clients should use Vehicle_updateData.
Authentication and permissions
The request must authenticate with signed API-key fields or a logged-in CRM session. The handler requires login but performs no additional Vehicles-page, create, edit, delete, or role-permission check.
All reads and writes use the authenticated tenant’s tables. CRM1 and CRM2 may hide controls through client-side permissions; these routes do not repeat those UI checks.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | Integer-compatible or 32-character string | Effectively yes | Numeric vehicle ID or UUID selected by exact length. Missing, blank, and invalid values can target ID 0 and still return success. |
val | Numeric-compatible | No validation | Converted with floatval(). Missing or nonnumeric input becomes 0; negative values are accepted. |
Example request
$result = FM_api('Vehicle_setCostPerDistance', [
'id' => '30124',
'val' => '0.42',
]);
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. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- Unknown IDs and unchanged values still return success; the query result is not checked.
- The endpoint performs no currency, distance-unit, precision, or minimum validation beyond PHP numeric conversion.
Side effects
- Updates
cost_per_distance, setslast_editedto the current server datetime andedited_uuidtoVehicle_setCostPerDistance, and invalidates the vehicle cache. - It does not write Core field history.
See it in Fieldmotion
CRM1
Open Settings → Vehicles in CRM1 and filter browser developer tools for the exact function name. Edit the Cost per Mile/KM table cell.
CRM2
CRM2 uses Vehicle_updateData from mapped forms; no direct CRM2 caller was found.
Related endpoints
Vehicle_setPricePerDistancechanges the customer charge.Vehicles_getCostPerDistancereads costs keyed by UUID.