Skip to main content

List Vehicles

GET /api/vehicles Retrieve all vehicles, optionally filtered by collection center. Results are sorted with default vehicles first, then by plate.

Query Parameters

collectionCenterId
string
Filter vehicles by collection center ID. If not provided, uses the active center from configuration.

Response

Returns an array of vehicle objects sorted by is_default DESC, plate ASC.

Example Request

curl http://localhost:4000/api/vehicles?collectionCenterId=center-1

Example Response

[
  {
    "id": "vehicle-1",
    "plate": "ABC-123",
    "brand": "Toyota",
    "model": "Hilux 2020",
    "owner": "Alternativa Verde",
    "is_default": true,
    "collection_center_id": "center-1",
    "created_at": "2026-01-10T09:00:00Z"
  },
  {
    "id": "vehicle-2",
    "plate": "XYZ-789",
    "brand": "Ford",
    "model": "Ranger 2019",
    "owner": "Juan Pérez",
    "is_default": false,
    "collection_center_id": "center-1",
    "created_at": "2026-02-15T11:30:00Z"
  }
]

Create Vehicle

POST /api/vehicles Create a new vehicle. If isDefault is true, all other vehicles for the same collection center will be set to non-default.

Request Body

id
string
required
Unique vehicle identifier (UUID)
plate
string
required
License plate (must be unique across all vehicles)
brand
string
required
Vehicle brand/manufacturer
model
string
required
Vehicle model
owner
string
required
Vehicle owner name
isDefault
boolean
default:"false"
Set as default vehicle. If true, unsets all other vehicles as default for the same center.
collectionCenterId
string
Associated collection center ID (optional)

Response

Returns the created vehicle object with created_at timestamp.
The operation runs in a transaction. If isDefault is true, it will:
  1. BEGIN transaction
  2. Set all other vehicles to is_default = false for the same center
  3. Insert the new vehicle with is_default = true
  4. COMMIT transaction

Example Request

curl -X POST http://localhost:4000/api/vehicles \
  -H "Content-Type: application/json" \
  -d '{
    "id": "vehicle-new-1",
    "plate": "DEF-456",
    "brand": "Chevrolet",
    "model": "LUV D-MAX 2021",
    "owner": "María García",
    "isDefault": false,
    "collectionCenterId": "center-1"
  }'

Example Response

{
  "id": "vehicle-new-1",
  "plate": "DEF-456",
  "brand": "Chevrolet",
  "model": "LUV D-MAX 2021",
  "owner": "María García",
  "is_default": false,
  "collection_center_id": "center-1",
  "created_at": "2026-03-09T16:00:00Z"
}

Update Vehicle

PUT /api/vehicles/:id Update an existing vehicle. If isDefault is set to true, all other vehicles for the same collection center will be set to non-default.

Path Parameters

id
string
required
Vehicle ID

Request Body

plate
string
required
License plate
brand
string
required
Vehicle brand
model
string
required
Vehicle model
owner
string
required
Vehicle owner name
isDefault
boolean
required
Set as default vehicle
collectionCenterId
string
Associated collection center ID

Response

Returns the updated vehicle object.
The update runs in a transaction. If isDefault is true, it will:
  1. BEGIN transaction
  2. Set all other vehicles (excluding this one) to is_default = false
  3. Update this vehicle with the new values
  4. COMMIT transaction

Example Request

curl -X PUT http://localhost:4000/api/vehicles/vehicle-1 \
  -H "Content-Type: application/json" \
  -d '{
    "plate": "ABC-123",
    "brand": "Toyota",
    "model": "Hilux 2022",
    "owner": "Alternativa Verde C.A.",
    "isDefault": true,
    "collectionCenterId": "center-1"
  }'

Example Response

{
  "id": "vehicle-1",
  "plate": "ABC-123",
  "brand": "Toyota",
  "model": "Hilux 2022",
  "owner": "Alternativa Verde C.A.",
  "is_default": true,
  "collection_center_id": "center-1",
  "created_at": "2026-01-10T09:00:00Z"
}

Delete Vehicle

DELETE /api/vehicles/:id Delete a vehicle by its ID.

Path Parameters

id
string
required
Vehicle ID

Response

ok
boolean
Returns true if deletion was successful

Example Request

curl -X DELETE http://localhost:4000/api/vehicles/vehicle-2

Example Response

{
  "ok": true
}

Error Response

{
  "error": "DB delete error"
}

Build docs developers (and LLMs) love