The Notifications API manages theDocumentation 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.
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 byfecha_creacion descending (newest first). Both read and unread notifications are included.
Required role: Any authenticated user
Query parameters: None
Primary key of the notification row.
ID of the user this notification is addressed to (always the session user).
Short event label, e.g.
Asignación, sistema, or any custom string set by the creator.Full human-readable notification body.
Read flag.
0 = unread, 1 = read.UTC timestamp when the notification was inserted.
Response 200
| Code | Message |
|---|---|
401 | No autenticado |
500 | Error 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)The user ID that will receive this notification.
A short label categorising the event (e.g.
Recordatorio, Alerta, Asignación). Maximum 50 characters.Full notification body text. No length restriction enforced at the API layer.
Response 201
| Code | Message |
|---|---|
400 | Faltan campos requeridos |
403 | Acceso denegado |
405 | Método no permitido |
500 | Error 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 noroles 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)
Subject / heading of the broadcast. Cannot be empty.
Body text of the broadcast. Cannot be empty.
Optional array of role IDs to restrict recipients. Valid values:
1, 2, 3. Defaults to [1, 2, 3] when omitted or empty.Confirmation string with recipient count, e.g.
"Notificación enviada a 45 usuarios".Response 200
| Code | Message |
|---|---|
400 | Asunto y contenido son requeridos |
403 | Acceso denegado |
405 | Método no permitido |
500 | Error (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
Primary key of the notification to mark as read.
Response 200
| Code | Message |
|---|---|
400 | ID de notificación no proporcionado |
404 | Notificación no encontrada o ya leída |
405 | Método no permitido |
500 | Error 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
Method: notify()
| Parameter | Type | Description |
|---|---|---|
$userId | int | id_usuario_destino — the recipient’s user ID |
$type | string | tipo_evento label (max 50 chars) |
$message | string | mensaje_texto body |
true on success, false if the PDO execute fails (exception is caught silently to avoid disrupting the calling transaction).
Usage example — assignment module
Theasignar.php module calls NotificationService immediately after committing the new cliente_asesor row:
Modules that use NotificationService
| Module | Event | tipo_evento sent |
|---|---|---|
asignaciones/asignar.php | New client–advisor assignment | Asignación |