The Clients API manages the customer master record for each company (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.
empresa). Every client is scoped to a single empresa_id derived from the authenticated user’s JWT, so calls across tenants are impossible by design. Clients carry full Spanish fiscal metadata — tax regime (regimen_fiscal_id), fiscal territory (territorio_fiscal_id), IRPF withholding regime (regimen_irpf_id), an optional default payment term, and an optional accounting sub-account (cuenta_contable_ventas). The NIF is stored normalised to uppercase and is enforced unique per company at the database level, though the API returns an advisory nif_existente object instead of blocking the write — see NIF advisory behaviour below.
Authentication
All endpoints require a valid JWT in theAuthorization header. The token must belong to an active user with role admin or user who is linked to an active empresa.
Endpoints
| Method | Path | Description |
|---|---|---|
GET | /api/clientes | List all active clients |
GET | /api/clientes/siguiente-codigo | Get the next available numeric code |
GET | /api/clientes/:id | Get a single client by ID |
POST | /api/clientes | Create a new client |
PUT | /api/clientes/:id | Update an existing client |
PATCH | /api/clientes/:id/estado | Toggle active / inactive status |
DELETE | /api/clientes/:id | Soft-delete a client |
GET /api/clientes
Returns all clients that haveestado = true (active) for the authenticated company.
Response
Always
"exito" on success.Array of active client objects.
Count of records returned.
GET /api/clientes/siguiente-codigo
Returns the next sequential numeric code to assign to a new client. The value is read from thecontadores table for the authenticated company.
Response
The next available integer code (current counter value + 1).
GET /api/clientes/:id
Returns a single client record. Returns404 if the client does not exist or belongs to a different company.
Path parameters
UUID of the client.
Response 200
Response 404
POST /api/clientes
Creates a new client record for the authenticated company.Body parameters
Full legal name of the client. Whitespace is trimmed automatically.
Tax identification number (NIF/CIF). Stored normalised to uppercase. Unique per
empresa at the database level; see NIF advisory behaviour.Contact email address. Must pass standard email format validation when provided.
Phone number. No format enforcement; whitespace is trimmed.
Street address. Max 500 characters.
Postal code. Whitespace is trimmed.
City / municipality. Whitespace is trimmed.
Province. Whitespace is trimmed.
UUID of a
regimenes_fiscales record belonging to the authenticated company (e.g. Régimen General, Régimen Simplificado).UUID of a
territorios_fiscales record (e.g. Territorio Común, País Vasco, Navarra).UUID of a
regimenes_irpf record. Controls the IRPF withholding percentage applied on invoices.UUID of a
formas_pago record. Must exist, belong to the authenticated company, and have activo = true. Returns 400 if the payment term is inactive or not found.Sales sub-ledger account code. Max 12 characters. Used when exporting to accounting software.
Response 201
NIF advisory behaviour
The When
POST /api/clientes and PUT /api/clientes/:id endpoints never block a write because of a duplicate NIF. Instead, if another client record in the same company already holds the same NIF, the response includes an extra nif_existente object alongside the newly created or updated record. This lets the frontend surface a warning without failing the operation.The mensaje is also adjusted to flag the situation:nif_existente.activo is true the existing client is still live — the API still succeeds but the frontend should prompt the user to review the conflict.Response 400 — inactive payment term
Response 400 — validation failure
PUT /api/clientes/:id
Full update of an existing client. Accepts the same body fields asPOST. Returns 404 if the client does not exist in the company scope.
Path parameters
UUID of the client to update.
POST /api/clientes — all fields validated by the same rule set. The NIF advisory check is also applied: if the incoming NIF differs from the current value and matches another client in the company, a nif_existente object is returned in the response.
Response 200
PATCH /api/clientes/:id/estado
Toggles the client between active (true) and inactive (false) without deleting it. Inactive clients are excluded from the GET /api/clientes list but can still be referenced by existing invoices.
Path parameters
UUID of the client.
Body parameters
Pass
true to activate the client, false to deactivate. Any non-boolean value returns a 400 error.Response 200
DELETE /api/clientes/:id
Soft-deletes the client. The record is not physically removed from the database; the operation is always reversible viaPATCH /:id/estado. Returns 404 if the client is not found within the company.
Path parameters
UUID of the client to delete.
Response 200
Error reference
| HTTP status | estado | Typical mensaje |
|---|---|---|
400 | error | Validation error detail (e.g. "El nombre es requerido") |
400 | error | "La forma de pago predefinida debe estar activa" |
400 | error | "El campo activo debe ser booleano" |
404 | error | "Cliente no encontrado" |
500 | error | Internal server error message |