Skip to content

Extend vehicle API endpoints to support all editable fields #1280 - #1300

Open
iamdabe wants to merge 3 commits into
hargata:mainfrom
iamdabe:API-Vehicle-Extended
Open

Extend vehicle API endpoints to support all editable fields #1280#1300
iamdabe wants to merge 3 commits into
hargata:mainfrom
iamdabe:API-Vehicle-Extended

Conversation

@iamdabe

@iamdabe iamdabe commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

This PR extend the existing Vehicles endpoint to include all editable fields bringing the API’s functionality in line with the UI as discussed in issue #1280

The primary goal was to support adding and editing Purchase and Sold information via the API. While I was there it wasn't much effort to add the other missing fields too.

Add/Update Vehicle (POST /api/vehicle/add, PUT /api/vehicle/update)

  • Added support for ImageLocation, PurchaseDate, SoldDate, PurchasePrice, SoldPrice, OdometerMultiplier, and OdometerDifference fields on the VehicleInputModel
  • Added pre-flight validation for date-parseable strings (PurchaseDate, SoldDate), decimal (OdometerMultiplier), and integer (OdometerDifference) fields before attempting to apply them
  • Add endpoint applies safe defaults (OdometerMultiplier = "1", OdometerDifference = "0", HasOdometerAdjustment = false) when fields are omitted. Update endpoint skips fields not provided for backwards compatibility.
  • I've also included the IsElectric and IsDiesel patch that resolves bug changing fuel type.

Image Upload (POST /api/images/upload)

  • New endpoint for uploading vehicle images via the API
  • Validates Content-Type starts with image/
  • Rejects files larger than 500KB with a descriptive error (as no way to get width/height without including a 3rd party image package.
  • Returns Location and Name on success, matching the existing UploadedFiles response pattern as used by documents upload endpoint

Image Upload Flow

To set a vehicle image via the API, first upload the image, then pass the returned location into the vehicle add/update payload.

1. Upload the image

POST /api/images/upload

Multipart form upload with the file in the image field. Max 500KB.

Returns:

{
  "location": "/images/abc123.jpg",
  "name": "mycar.jpg"
}

2. Use the location in Add or Update Vehicle

POST /api/vehicles/add

{
  "year": 2019,
  "make": "Nissan",
  "model": "Altima",
  "identifier": "LicensePlate",
  "licensePlate": "HITNCURBS",
  "fuelType": "Gasoline",
  "imageLocation": "/images/abc123.jpg",
  "purchaseDate": "2019-01-01",
  "purchasePrice": 20000.00,
  "odometerMultiplier": "1.0",
  "odometerDifference": "0"
}

PUT /api/vehicles/update

{
  "id": 1,
  "year": 2019,
  "make": "Nissan",
  "model": "Altima",
  "identifier": "LicensePlate",
  "licensePlate": "HITNCURBS",
  "fuelType": "Gasoline",
  "imageLocation": "/images/abc123.jpg",
  "soldDate": "2023-06-15",
  "soldPrice": 15000.00
}

Notes

  • purchaseDate / soldDate — ISO 8601 date strings, optional
  • purchasePrice / soldPrice — decimal, optional
  • odometerMultiplier / odometerDifference — if either is provided, odometer adjustment is automatically enabled on the vehicle
  • All fields except the required vehicle identifiers are optional on update (patch behaviour)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant