Skip to main content

Update Tractor

Update an existing tractor’s information. This endpoint requires administrator authentication. Only the fields provided in the request body will be updated (partial updates supported).
Admin Access Required - This endpoint requires a valid JWT token with role_id: 1 (administrator).

Endpoint

PUT /api/tractors/:id

Authentication

This endpoint requires both authentication and administrator privileges:
Authorization: Bearer <jwt_token>
See the Authentication guide for details on obtaining and using JWT tokens.

Path Parameters

id
integer
required
Unique identifier of the tractor to update. Must be a positive integer.

Request Body

All fields are optional. Only include the fields you want to update. The API uses SQL COALESCE to preserve existing values for fields not included in the request.
brand
string
Tractor brand/manufacturer name. Cannot be empty if provided.Example: "John Deere", "Case IH"
model
string
Tractor model identifier. Cannot be empty if provided.Example: "6130M", "Magnum 280"
engine_power_hp
number
Engine power in horsepower (HP). Must be a positive number if provided.Example: 135, 285.5
traction_type
string
Type of traction system. Must be one of: 4x2, 4x4, track
name
string
Display name for the tractor.Example: "John Deere 6130M Updated"
weight_kg
number
Total weight in kilograms. Must be a positive number if provided.Example: 5300, 11500.5
traction_force_kn
number
Traction force in kilonewtons (kN). Must be a positive number if provided.Example: 46.0, 87.2
tire_type
string
Type of tires installed on the tractor.Example: "radial", "bias"
tire_width_mm
number
Tire width in millimeters. Must be a positive number if provided.Example: 550, 720
tire_diameter_mm
number
Tire diameter in millimeters. Must be a positive number if provided.Example: 1620, 1900
tire_pressure_psi
number
Recommended tire pressure in PSI. Must be a positive number if provided.Example: 16, 18.5
status
string
Current status of the tractor. Must be one of: available, maintenance, inactive

Response Fields

success
boolean
Indicates if the request was successful
data
object
The updated tractor object with all fields

Example Request - Partial Update

curl -X PUT http://localhost:4000/api/tractors/1 \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -d '{
    "engine_power_hp": 135,
    "status": "maintenance"
  }'

Example Request - Full Update

curl -X PUT http://localhost:4000/api/tractors/1 \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -d '{
    "name": "John Deere 6130M Updated",
    "brand": "John Deere",
    "model": "6130M",
    "engine_power_hp": 135,
    "weight_kg": 5300,
    "traction_force_kn": 46.0,
    "traction_type": "4x4",
    "tire_type": "radial",
    "tire_width_mm": 550,
    "tire_diameter_mm": 1620,
    "tire_pressure_psi": 16,
    "status": "available"
  }'

Example Responses

{
  "success": true,
  "data": {
    "tractor_id": 1,
    "name": "John Deere 6130M",
    "brand": "John Deere",
    "model": "6130M",
    "engine_power_hp": 135,
    "weight_kg": 5200,
    "traction_force_kn": 45.5,
    "traction_type": "4x4",
    "tire_type": "radial",
    "tire_width_mm": 540,
    "tire_diameter_mm": 1600,
    "tire_pressure_psi": 15,
    "status": "maintenance"
  }
}

Validation Rules

Update-Specific Validation

For updates (PUT requests), required fields from creation are optional. However, if you provide a field, it must pass validation.
If provided, string fields cannot be empty:
  • brand - Cannot be empty string or whitespace
  • model - Cannot be empty string or whitespace
Valid: "John Deere", "Updated Model"Invalid: "", " ", null
If provided, must be positive numbers:
  • engine_power_hp
  • weight_kg
  • traction_force_kn
  • tire_width_mm
  • tire_diameter_mm
  • tire_pressure_psi
Valid: 130, 5200.5, 45Invalid: 0, -10, "abc"
Must match allowed values if provided:traction_type: 4x2, 4x4, trackstatus: available, maintenance, inactive

Common Use Cases

Change Status

Update tractor status (e.g., from available to maintenance)
{ "status": "maintenance" }

Update Specifications

Modify technical specifications after verification
{
  "engine_power_hp": 135,
  "weight_kg": 5300
}

Correct Model Info

Fix typos or update model information
{
  "name": "John Deere 6130M Premium",
  "model": "6130M"
}

Update Tire Config

Change tire specifications
{
  "tire_width_mm": 550,
  "tire_pressure_psi": 16
}

Error Responses

Returned when the tractor ID in the URL path is not a valid positive integer.Examples: /api/tractors/abc, /api/tractors/-1, /api/tractors/0
Returned when the request body contains invalid data. The response includes an errors array.Common errors:
  • "brand no puede estar vacío" - Empty brand provided
  • "model no puede estar vacío" - Empty model provided
  • "engine_power_hp debe ser un número positivo" - Invalid power value
  • "traction_type debe ser uno de: 4x2, 4x4, track" - Invalid traction type
  • "status debe ser uno de: available, maintenance, inactive" - Invalid status
Returned when authentication fails (missing, malformed, expired, or invalid token).
Returned when the authenticated user is not an administrator.
Returned when no tractor exists with the specified ID.
Returned when an unexpected server error occurs.

Cache Invalidation

Updating a tractor automatically invalidates all tractor-related and recommendation caches. This ensures that GET requests immediately reflect the updated information.

Get Tractor

View current tractor details before updating

Create Tractor

Add new tractors to the catalog

Delete Tractor

Remove tractor from catalog

List Tractors

View all tractors

Build docs developers (and LLMs) love