Skip to main content

Create Service Record

Create a new lubrication service record.
POST /api/engrases

Request Body

fecha
string
required
Service date in YYYY-MM-DD format
conductor_id
number
required
ID of the driver from areas_conductores table
placa_id
number
required
ID of the vehicle plate from areas_placas table
area_operacion_id
number
required
ID of the operational area from areas_operacion table
lavado
number
required
Washing service cost (can be 0)
engrase
number
required
Lubrication service cost (can be 0)
otros
number
required
Other services cost (can be 0)
observaciones
string
Additional notes or comments about the service
The suma field is automatically calculated as lavado + engrase + otros.

Response

id
number
ID of the newly created service record
fecha
string
Service date
conductor_id
number
Driver ID
placa_id
number
Vehicle plate ID
area_operacion_id
number
Operational area ID
lavado
number
Washing cost
engrase
number
Lubrication cost
otros
number
Other services cost
suma
number
Total cost (calculated)
observaciones
string | null
Service notes
creado_por
string
User ID who created the record

Example Request

curl -X POST "https://api.example.com/api/engrases" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "fecha": "2024-03-04",
    "conductor_id": 5,
    "placa_id": 23,
    "area_operacion_id": 2,
    "lavado": 25000,
    "engrase": 45000,
    "otros": 10000,
    "observaciones": "Servicio completo con cambio de aceite"
  }'

Example Response

{
  "id": 102,
  "fecha": "2024-03-04",
  "conductor_id": 5,
  "placa_id": 23,
  "area_operacion_id": 2,
  "lavado": 25000,
  "engrase": 45000,
  "otros": 10000,
  "suma": 80000,
  "observaciones": "Servicio completo con cambio de aceite",
  "creado_por": "user-uuid-here"
}

Validation Rules

All cost fields (lavado, engrase, otros) must be non-negative numbers.
  • fecha must be a valid date in YYYY-MM-DD format
  • conductor_id must reference an existing driver
  • placa_id must reference an existing vehicle plate
  • area_operacion_id must reference an existing operational area
  • Cost fields cannot be negative
  • At least one cost field should be greater than 0

Common Use Cases

Complete Service

Record all three service types:
{
  "fecha": "2024-03-04",
  "conductor_id": 5,
  "placa_id": 23,
  "area_operacion_id": 2,
  "lavado": 25000,
  "engrase": 45000,
  "otros": 10000,
  "observaciones": "Servicio completo"
}

Washing Only

Record only washing service:
{
  "fecha": "2024-03-04",
  "conductor_id": 5,
  "placa_id": 23,
  "area_operacion_id": 2,
  "lavado": 25000,
  "engrase": 0,
  "otros": 0,
  "observaciones": "Solo lavado"
}

Lubrication Only

Record only lubrication service:
{
  "fecha": "2024-03-04",
  "conductor_id": 5,
  "placa_id": 23,
  "area_operacion_id": 2,
  "lavado": 0,
  "engrase": 45000,
  "otros": 0,
  "observaciones": "Cambio de aceite"
}

Error Responses

Missing Required Fields

{
  "error": "Missing required fields"
}

Invalid Foreign Key

{
  "error": "conductor_id does not exist"
}

Invalid Date Format

{
  "error": "Invalid date format. Use YYYY-MM-DD"
}

Build docs developers (and LLMs) love