Smart Library Docs

Notifications Endpoints

API reference for in-app notification operations — list, mark as read, and bulk mark all as read.

Notifications Endpoints

Manage in-app notifications for the authenticated user. Notifications are generated automatically by the system for events like fine generation, reservation fulfillment, and overdue alerts.

Base Path: /api/v1/notifications

All endpoints require authentication (authenticate middleware applied globally on the router).


Get My Notifications

GET /api/v1/notifications

Returns the 50 most recent notifications for the authenticated user, sorted by newest first. Also includes an unreadCount for badge display.

Authorization: Any authenticated user

Success Response — 200 OK

{
  "notifications": [
    {
      "_id": "...",
      "userId": "...",
      "title": "New Fine Generated",
      "message": "An overdue fine of $5 has been generated for a book you have checked out.",
      "type": "WARNING",
      "isRead": false,
      "createdAt": "2026-07-06T00:00:00.000Z",
      "updatedAt": "2026-07-06T00:00:00.000Z"
    }
  ],
  "unreadCount": 3
}

Notification Types

TypeUsage
INFOGeneral information (default)
WARNINGFine alerts, overdue notices
SUCCESSReservation fulfilled, book returned
ERRORSystem errors or critical alerts

Mark Notification as Read

PUT /api/v1/notifications/:id/read

Marks a single notification as read. Only the notification owner can mark it.

Authorization: Any authenticated user (own notifications only)

Path Parameters

ParameterDescription
idNotification ID

Success Response — 200 OK

{
  "message": "Marked as read",
  "notification": {
    "_id": "...",
    "isRead": true,
    "title": "...",
    "message": "..."
  }
}

Error Responses

CodeCondition
404Notification not found or not owned by user
500Internal server error

Mark All as Read

PUT /api/v1/notifications/mark-all-read

Marks all unread notifications for the authenticated user as read in a single operation.

Authorization: Any authenticated user

Success Response — 200 OK

{
  "message": "All notifications marked as read"
}

Route Summary

MethodPathAuthDescription
GET/notificationsGet own notifications (max 50)
PUT/notifications/mark-all-readMark all as read
PUT/notifications/:id/readMark single notification as read

On this page