The Expenses API records purchase invoices and costs incurred by the business — the payable side of the ledger. Each gasto links to an optional supplier (Documentation Index
Fetch the complete documentation index at: https://mintlify.com/eme2dev/Eme2App/llms.txt
Use this file to discover all available pages before exploring further.
proveedores), carries a reference from the supplier’s invoice (referencia_proveedor), and supports multiple detail lines, each with its own tax type (iva_id) and calculated cuota_iva. This data feeds the IVA deductible reports and cost analysis dashboards. All endpoints require a Bearer token with a valid empresa_id.
The router is mounted at two paths for backward compatibility:
/api/gastos— primary path/api/facturas-compra— alias, identical behaviour
Authorization: Bearer <token> with empresa_id embedded.
Endpoint reference
| Method | Path | Description |
|---|---|---|
| GET | /api/gastos | List expenses (paginated) |
| POST | /api/gastos | Create expense |
| GET | /api/gastos/:id | Get expense by ID |
| PUT | /api/gastos/:id | Update expense |
| DELETE | /api/gastos/:id | Delete expense |
GET /api/gastos
Returns a paginated list of expenses for the active company. Query parameters| Parameter | Type | Description |
|---|---|---|
page | integer | Page number (default: 1) |
pageSize | integer | Results per page (default: company setting) |
POST /api/gastos
Creates a new expense record. The server validates that all required fields are present and that every detail line has a positivebase_imponible.
Date of the supplier’s invoice. Format must be
YYYY-MM-DD.ID of an existing
proveedores record. Required if proveedor (free-text) is not provided.Free-text supplier name. Used when the supplier is not in the catalogue. Required if
proveedor_id is not provided.Supplier’s own invoice number. Max 20 characters. Used for duplicate detection and cross-reference.
Active/inactive flag. Defaults to
true.Array of expense detail lines. If omitted, the server builds a single-line detail from the top-level
concepto and base_imponible fields.Top-level convenience field. Used as the single detail line’s
concepto when detalles is not provided.Top-level convenience field. Used as the single detail line’s
base_imponible when detalles is not provided.Top-level IVA rate. Used when
detalles is not provided.| Rule | Error message |
|---|---|
fecha missing or wrong format | "La fecha es requerida y debe estar en formato YYYY-MM-DD" |
Neither proveedor_id nor proveedor provided | "El proveedor es requerido" |
referencia_proveedor missing | "La referencia del proveedor es requerida" |
referencia_proveedor > 20 chars | "La referencia del proveedor no puede exceder 20 caracteres" |
| No detail lines resolved | "Debes indicar al menos un concepto" |
Any detail missing concepto | "Todos los conceptos deben tener descripción" |
Any detail with base_imponible ≤ 0 | "La base imponible de cada concepto debe ser mayor a 0" |
GET /api/gastos/:id
Returns a single expense with all its detail lines. ResponsePUT /api/gastos/:id
Full update of an expense. The request body mirrorsPOST /api/gastos. Detail lines are replaced entirely.
Response
DELETE /api/gastos/:id
Permanently deletes the expense and all its detail lines. Response| Status | mensaje |
|---|---|
| 404 | "Gasto no encontrado" |
| 500 | "Error al eliminar gasto" |