Vehicles
Create or update a legacy vehicle
/a/Vehicle_update
Create a CRM1 vehicle or replace its four legacy editable fields by UUID.
When to use this endpoint
Use Vehicle_update only when reproducing CRM1’s Settings → Vehicles dialog. It combines create and update in a UUID-oriented contract that differs from the mapped CRM2 endpoints.
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 | String | No | Omit or send a false-like value to create. Any truthy value is used literally as a UUID in the update query; numeric vehicle IDs therefore do not update their row. |
cost_per_distance | Numeric-compatible | Yes | Internal cost converted with floatval(). This is the only parameter explicitly validated for presence. |
price_per_distance | Numeric-compatible | Effectively yes | Customer charge converted with floatval(). If omitted it is read as missing and becomes 0. |
description | String | Effectively yes | Replacement description. Omission becomes an empty string. |
reg | String | Effectively yes | Registration value. CRM1 prevents a blank value in the dialog, but the handler itself accepts blank and duplicate registrations. |
Example request
$created = FM_api('Vehicle_update', [
'cost_per_distance' => '0.42',
'price_per_distance' => '0.75',
'description' => 'Service van',
'reg' => '241-D-12001',
]);
Example response
{"ok":1,"id":30124,"uuid":"4ec721a4aa8f4ec393b6c66fd31bf611"}
On an update, id echoes the supplied UUID and uuid is null because the update branch never assigns that response variable.
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: cost_per_distance"} | The cost parameter is absent. Blank is accepted and converts to zero. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- Creation generates a legacy MD5-shaped 32-character UUID and stores
cdateas the current Unix timestamp. - All four editable fields are replaced on every update. There is no duplicate-registration, nonnegative-value, or affected-row check.
- The response’s
idchanges meaning: numeric database ID after creation, supplied UUID string after update.
Side effects
- Inserts or updates the tenant vehicle, advances
last_edited, setsedited_uuidtoVehicle_update, and invalidates the vehicle cache. - It does not write mapped Core field-history entries.
See it in Fieldmotion
CRM1
Open Settings → Vehicles in CRM1 and filter browser developer tools for the exact function name. Choose Create or Edit, then save the dialog; existing rows are submitted by UUID.
CRM2
CRM2 does not call this route. Its forms use Vehicle_createData and Vehicle_updateData.
Related endpoints
Vehicle_createDatais the mapped create route and always returns a numeric ID.Vehicle_updateDataupdates mapped fields by numeric ID.