Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Nieto2020/portalhub/llms.txt

Use this file to discover all available pages before exploring further.

The Notifications API manages the notificaciones table, which acts as the platform’s alert layer. Notifications are generated in two ways: manually via these REST endpoints (by Admins and Asesores) and automatically by the NotificationService PHP class, which other backend modules call after key events such as client assignment changes. Each notification is scoped to exactly one destination user (id_usuario_destino) and carries a free-form tipo_evento label and a mensaje_texto body.
Role IDs used throughout this API: Admin = 1, Asesor = 2, Cliente = 3.

GET /backend/modules/notificaciones/listar.php

Returns all notifications addressed to the session user, ordered by fecha_creacion descending (newest first). Both read and unread notifications are included. Required role: Any authenticated user Query parameters: None
id_notificacion
integer
Primary key of the notification row.
id_usuario_destino
integer
ID of the user this notification is addressed to (always the session user).
tipo_evento
string
Short event label, e.g. Asignación, sistema, or any custom string set by the creator.
mensaje_texto
string
Full human-readable notification body.
leida
integer
Read flag. 0 = unread, 1 = read.
fecha_creacion
timestamp
UTC timestamp when the notification was inserted.
curl -s \
  --cookie "PHPSESSID=<your_session_id>" \
  "https://your-domain.com/backend/modules/notificaciones/listar.php"
Response 200
{
  "status": 200,
  "message": "Notificaciones obtenidas",
  "data": [
    {
      "id_notificacion": 17,
      "id_usuario_destino": 3,
      "tipo_evento": "Asignación",
      "mensaje_texto": "Se le ha asignado un nuevo asesor contable.",
      "leida": 0,
      "fecha_creacion": "2024-08-15 10:45:00"
    }
  ]
}
Error responses
CodeMessage
401No autenticado
500Error en el servidor

POST /backend/modules/notificaciones/crear.php

Creates a single notification targeted at one user. Only Admin and Asesor roles are permitted to call this endpoint. Required role: Admin or Asesor (id_rol = 1 or 2)
id_usuario_destino
integer
required
The user ID that will receive this notification.
tipo_evento
string
required
A short label categorising the event (e.g. Recordatorio, Alerta, Asignación). Maximum 50 characters.
mensaje_texto
string
required
Full notification body text. No length restriction enforced at the API layer.
curl -s -X POST \
  --cookie "PHPSESSID=<asesor_session_id>" \
  -H "Content-Type: application/json" \
  -d '{
    "id_usuario_destino": 9,
    "tipo_evento": "Recordatorio",
    "mensaje_texto": "Su declaración de impuestos vence en 3 días."
  }' \
  "https://your-domain.com/backend/modules/notificaciones/crear.php"
Response 201
{
  "status": 201,
  "message": "Notificación creada exitosamente",
  "data": null
}
Error responses
CodeMessage
400Faltan campos requeridos
403Acceso denegado
405Método no permitido
500Error en el servidor

POST /backend/modules/notificaciones/crear_masivo.php

Broadcasts a notification to multiple users in a single atomic database transaction. Only Admin users may call this endpoint. Optionally scope recipients by role; if no roles array is provided the notification is sent to every user (roles 1, 2, and 3). The stored mensaje_texto is composed as titulo + ': ' + contenido. The tipo_evento is always set to sistema by the server. Required role: Admin (id_rol = 1)
titulo
string
required
Subject / heading of the broadcast. Cannot be empty.
contenido
string
required
Body text of the broadcast. Cannot be empty.
roles
integer[]
Optional array of role IDs to restrict recipients. Valid values: 1, 2, 3. Defaults to [1, 2, 3] when omitted or empty.
message
string
Confirmation string with recipient count, e.g. "Notificación enviada a 45 usuarios".
All inserts run inside a transaction. A failure in any single insert triggers a full rollback and returns 500.
curl -s -X POST \
  --cookie "PHPSESSID=<admin_session_id>" \
  -H "Content-Type: application/json" \
  -d '{
    "titulo": "Actualización de política",
    "contenido": "A partir del 1 de septiembre entran en vigor las nuevas políticas de privacidad."
  }' \
  "https://your-domain.com/backend/modules/notificaciones/crear_masivo.php"
Response 200
{
  "status": 200,
  "message": "Notificación enviada a 45 usuarios",
  "data": null
}
Error responses
CodeMessage
400Asunto y contenido son requeridos
403Acceso denegado
405Método no permitido
500Error (with rollback)

POST /backend/modules/notificaciones/marcar_leido.php

Marks a single notification as read (leida = 1). The update is scoped to both the provided id_notificacion and the session user’s id_usuario_destino, preventing any user from marking another user’s notifications. Required role: Any authenticated user
id_notificacion
integer
required
Primary key of the notification to mark as read.
curl -s -X POST \
  --cookie "PHPSESSID=<your_session_id>" \
  -H "Content-Type: application/json" \
  -d '{ "id_notificacion": 17 }' \
  "https://your-domain.com/backend/modules/notificaciones/marcar_leido.php"
Response 200
{
  "status": 200,
  "message": "Notificación marcada como leída",
  "data": null
}
Error responses
CodeMessage
400ID de notificación no proporcionado
404Notificación no encontrada o ya leída
405Método no permitido
500Error en el servidor

NotificationService — Internal PHP service

NotificationService (backend/services/NotificationService.php) is used internally by other modules to emit notifications automatically after key domain events, without going through the HTTP layer. This avoids duplicating the INSERT logic across modules.

Constructor

$notificador = new NotificationService($conexion);
Accepts a live PDO connection object. The service is stateless beyond this dependency.

Method: notify()

$notificador->notify(int $userId, string $type, string $message): bool
ParameterTypeDescription
$userIdintid_usuario_destino — the recipient’s user ID
$typestringtipo_evento label (max 50 chars)
$messagestringmensaje_texto body
Returns true on success, false if the PDO execute fails (exception is caught silently to avoid disrupting the calling transaction).

Usage example — assignment module

The asignar.php module calls NotificationService immediately after committing the new cliente_asesor row:
$notificador = new NotificationService($conexion);
$notificador->notify(
    $id_cliente,
    "Asignación",
    "Se le ha asignado un nuevo asesor contable."
);
Because notify() catches its own PDOException and returns false, a notification failure never rolls back the parent transaction. If guaranteed delivery is required, check the return value and handle the failure explicitly in your module.

Modules that use NotificationService

ModuleEventtipo_evento sent
asignaciones/asignar.phpNew client–advisor assignmentAsignación

Build docs developers (and LLMs) love