Overview
The Notifications API allows users to retrieve their personal notifications and mark them as read. All endpoints require authentication and only return notifications for the authenticated user.
Endpoints
Get Notifications Retrieve user’s notifications
Mark as Read Mark notifications as read
Get Notifications
curl -X GET "https://api.example.com/api/notificaciones?solo_no_leidas=true" \
-H "Authorization: Bearer YOUR_TOKEN"
Retrieves the authenticated user’s notifications, with optional filtering for unread notifications only.
Query Parameters
Set to true to retrieve only unread notifications
Response
{
"success" : true ,
"data" : [
{
"id_notificacion" : 45 ,
"id_usuario" : 12 ,
"titulo" : "Solicitud aprobada" ,
"mensaje" : "Tu solicitud de vacaciones ha sido aprobada" ,
"leido" : false ,
"fecha_creacion" : "2024-03-08T14:30:00Z" ,
"tipo" : {
"codigo" : "APROBACION" ,
"nombre" : "Aprobación de solicitud"
},
"remitente" : {
"id_empleado" : 5 ,
"nombre" : "María García"
},
"solicitud" : {
"id_solicitud" : 123 ,
"id_tipo_solicitud" : 1 ,
"id_estado_solicitud" : 2
}
},
{
"id_notificacion" : 44 ,
"id_usuario" : 12 ,
"titulo" : "Nuevo documento disponible" ,
"mensaje" : "Se ha publicado el manual de procedimientos 2024" ,
"leido" : false ,
"fecha_creacion" : "2024-03-07T10:15:00Z" ,
"tipo" : {
"codigo" : "DOCUMENTO" ,
"nombre" : "Nuevo documento"
},
"remitente" : {
"id_empleado" : 1 ,
"nombre" : "Administrador Sistema"
},
"solicitud" : null
}
]
}
The API returns a maximum of 10 recent notifications sorted by creation date (most recent first).
Notification Structure
Each notification includes:
Basic info : ID, title, message, read status, and creation date
Type : Notification type code and name (e.g., approval, document, reminder)
Sender : Employee who triggered the notification (optional)
Request : Related request information (optional)
Mark as Read
PUT /api/notificaciones/leer
curl -X PUT "https://api.example.com/api/notificaciones/leer" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"ids": [45, 44, 43]
}'
Marks one or more notifications as read for the authenticated user.
Request Body
Array of notification IDs to mark as read
Response
200 OK
400 Bad Request
500 Error
{
"success" : true ,
"message" : "3 notificaciones marcadas como leídas."
}
Users can only mark their own notifications as read. The API enforces this security constraint automatically.
Usage Examples
Fetch Unread Notifications
const getUnreadNotifications = async () => {
const response = await fetch (
'https://api.example.com/api/notificaciones?solo_no_leidas=true' ,
{
headers: {
'Authorization' : `Bearer ${ token } `
}
}
);
const data = await response . json ();
return data . data ;
};
Mark Multiple Notifications as Read
const markAsRead = async ( notificationIds ) => {
const response = await fetch (
'https://api.example.com/api/notificaciones/leer' ,
{
method: 'PUT' ,
headers: {
'Authorization' : `Bearer ${ token } ` ,
'Content-Type' : 'application/json'
},
body: JSON . stringify ({ ids: notificationIds })
}
);
return response . json ();
};
// Mark notifications 45, 44, and 43 as read
await markAsRead ([ 45 , 44 , 43 ]);
Implementation Reference
Source files:
Routes: src/routes/notificacionRoutes.js:12-13
Controller: src/controllers/notificacionController.js:8-81