Overview
The Consumos API records and retrieves resource consumption data linked to production work records. Each consumption entry tracks how much of a specific resource was used during a work activity. Consumptions create traceability between:- Resources (Recursos API) - What was consumed
- Work Records (
registros_trabajo) - When and where it was consumed - Production Quantities - Enabling yield and efficiency calculations
Base URL
Get Consumptions by Work Record
registro_trabajo_id), ordered by timestamp (most recent first).
Path Parameters
The
registro_trabajo_id (work record ID) to retrieve consumptions forResponse
Indicates if the request was successful
Array of consumption objects for the specified work record
Response Example
Create Consumption Record
MANAGE_PRODUCTION
Request Body
ID of the work record (
registros_trabajo) where this consumption occurred. Must reference an existing work record.ID of the resource being consumed. Must reference an existing resource from the Recursos API.
Quantity consumed, measured in the resource’s
unidad_medida (kg, liters, units, etc.). Must be a positive number.ISO 8601 timestamp indicating when the consumption occurred. Should typically align with the work record’s production time.
Response
Returns the created consumption record with the generatedid.
Indicates if the creation was successful
The created consumption object including the auto-generated
idResponse Example
Data Model
Consumption Schema
TheCONSUMO table structure:
| Column | Type | Constraints | Description |
|---|---|---|---|
id | INTEGER | PRIMARY KEY, AUTOINCREMENT | Unique consumption identifier |
registro_trabajo_id | INTEGER | FOREIGN KEY → registros_trabajo(id) | Work record reference |
recurso_id | INTEGER | FOREIGN KEY → RECURSO(id) | Resource reference |
cantidad_consumida | REAL | - | Quantity consumed |
timestamp_consumo | DATETIME | - | Consumption timestamp |
Relationships
- Work Record (
registros_trabajo): One work record can have multiple consumption entries - Resource (
RECURSO): One resource can be consumed multiple times across different work records - This creates a many-to-many relationship between work records and resources, with consumption quantities tracked in the junction table
Related Tables
registros_trabajo
Work records from production operations:id: Work record identifiercantidad_producida: Output quantitylinea_ejecucion_id: Production line referencemaquina_id: Machine referencefecha_hora: Production timestamp
RECURSO
Resource catalog (see Recursos API):id: Resource identifiercodigo: Resource codenombre: Resource nameunidad_medida: Unit of measurement for quantities
Usage Examples
Recording Material Consumption During Production
Retrieving All Consumptions for a Work Record
Complete Production Recording Workflow
Calculating Production Metrics
Combining consumption data with production output enables key manufacturing metrics:Material Yield
- Produced: 1500 kg
- Consumed: 245.5 kg (recurso #1) + 12.8 kg (recurso #3) = 258.3 kg
- Yield: (1500 / 258.3) × 100 = 580.6% (indicates output measurement differs from input)
Specific Consumption
- Adhesive consumed: 12.8 kg
- Product produced: 1500 kg
- Specific consumption: 12.8 / 1500 = 0.0085 kg adhesive per kg product
Resource Usage Over Time
Query multiple work records to track:- Total consumption by resource type
- Consumption trends over time
- Machine-specific consumption patterns
- Production efficiency variations
Error Handling
Common Error Responses
400 Bad Request - Missing Required Field
400 Bad Request - Invalid Data Type
401 Unauthorized
403 Forbidden
404 Not Found - Invalid Work Record
404 Not Found - Invalid Resource
500 Internal Server Error
Best Practices
Timestamp Accuracy
- Record
timestamp_consumoas close to actual consumption time as possible - For batch operations, use the midpoint or start of production
- Maintain consistency within each work record (same or similar timestamps)
- Use UTC timestamps to avoid timezone issues
Quantity Precision
- Match precision to your measurement equipment capabilities
- For weight-based materials: typically 1-2 decimal places (e.g., 245.5 kg)
- For volume-based liquids: 1-2 decimal places (e.g., 12.8 liters)
- For discrete units: whole numbers (e.g., 150 units)
Resource Validation
Before recording consumption:- Verify the resource exists in the catalog (Recursos API)
- Confirm the work record exists and is still open/editable
- Ensure units match expectations (kg vs. liters vs. units)
- Validate quantities are within reasonable ranges
Data Integrity
- Record all material consumptions for complete traceability
- Include both primary and secondary materials
- Don’t forget indirect consumptions (adhesives, inks, etc.)
- Maintain referential integrity with work records
Batch Recording
When recording multiple consumptions for one work record:Integration Patterns
Production Recording Flow
Reporting and Analytics
Retrieval pattern for production analysis:- Query work records by date range, machine, or production line
- For each work record, retrieve consumptions via
GET /consumos/registro/:id - Join with resource catalog to get names and units
- Calculate metrics (yield, specific consumption, etc.)
- Aggregate across multiple work records for trends
Related Endpoints
- Recursos API - Resource catalog management
- Registros de Trabajo - Work records and production output
- Líneas de Ejecución - Production line management