Skip to main content

Overview

The Alert System API provides real-time monitoring of inventory issues including low stock, expiring products, expired items, and out-of-stock situations. All endpoints require authentication.

Low Stock Alerts

Get items with stock levels below the threshold. Access: Private (all authenticated users)

Query Parameters

threshold
number
default:"10"
Stock threshold (uses LOW_STOCK_THRESHOLD env variable if not provided)

Response

alerts
array
Array of low stock items
alertType
string
Alert type: low_stock
severity
string
HIGH if quantity ≤ threshold/2, otherwise MEDIUM
message
string
Alert message with current stock level
count
number
Number of low stock items
threshold
number
Threshold value used

Example Response

{
  "success": true,
  "message": "Low stock alerts fetched successfully",
  "data": {
    "alerts": [
      {
        "_id": "65a1234567890abcdef12345",
        "productName": "Organic Apples",
        "category": "Fruits",
        "sku": "FRT-001",
        "quantity": 4,
        "expiryDate": "2024-02-15T00:00:00.000Z",
        "supplier": "Fresh Farms Ltd",
        "alertType": "low_stock",
        "severity": "HIGH",
        "message": "Only 4 units left in stock"
      }
    ],
    "count": 1,
    "threshold": 10
  }
}

Expiring Soon Alerts

Get items expiring within the specified number of days. Access: Private (all authenticated users)

Query Parameters

days
number
default:"7"
Number of days to look ahead (uses EXPIRY_ALERT_DAYS env variable if not provided)

Response

alerts
array
Array of expiring items sorted by expiry date
alertType
string
Alert type: expiring_soon
severity
string
CRITICAL (≤1 day), HIGH (≤3 days), MEDIUM (≤5 days), or LOW (>5 days)
daysUntilExpiry
number
Days until expiration
message
string
Alert message with days until expiry
count
number
Number of expiring items
days
number
Days parameter used

Example Response

{
  "success": true,
  "message": "Expiring soon alerts fetched successfully",
  "data": {
    "alerts": [
      {
        "_id": "65a1234567890abcdef12345",
        "productName": "Fresh Milk",
        "category": "Dairy",
        "quantity": 25,
        "expiryDate": "2024-01-18T00:00:00.000Z",
        "alertType": "expiring_soon",
        "severity": "HIGH",
        "daysUntilExpiry": 2,
        "message": "Expires in 2 days"
      }
    ],
    "count": 1,
    "days": 7
  }
}

Expired Items Alerts

Get items that have passed their expiry date. Access: Private (all authenticated users)

Response

alerts
array
Array of expired items sorted by expiry date (oldest first)
alertType
string
Alert type: expired
severity
string
Always CRITICAL
daysExpired
number
Days since expiration
message
string
Alert message with days expired
count
number
Number of expired items

Example Response

{
  "success": true,
  "message": "Expired items alerts fetched successfully",
  "data": {
    "alerts": [
      {
        "_id": "65a1234567890abcdef12345",
        "productName": "Old Cheese",
        "category": "Dairy",
        "quantity": 5,
        "expiryDate": "2024-01-10T00:00:00.000Z",
        "alertType": "expired",
        "severity": "CRITICAL",
        "daysExpired": 5,
        "message": "Expired 5 days ago"
      }
    ],
    "count": 1
  }
}

Out of Stock Alerts

Get items with zero quantity. Access: Private (all authenticated users)

Response

alerts
array
Array of out-of-stock items
alertType
string
Alert type: out_of_stock
severity
string
Always HIGH
message
string
Alert message
count
number
Number of out-of-stock items

Example Response

{
  "success": true,
  "message": "Out of stock alerts fetched successfully",
  "data": {
    "alerts": [
      {
        "_id": "65a1234567890abcdef12345",
        "productName": "Bananas",
        "category": "Fruits",
        "sku": "FRT-015",
        "quantity": 0,
        "alertType": "out_of_stock",
        "severity": "HIGH",
        "message": "Out of stock - Immediate restocking required"
      }
    ],
    "count": 1
  }
}

Critical Alerts

Get all critical alerts combined (expired, expiring in ≤3 days, out of stock, critically low stock below 5 units). Access: Private (all authenticated users)

Response

alerts
array
Combined array of critical alerts sorted by priority
alertType
string
Alert type: expired, expiring_critical, out_of_stock, or critical_low_stock
severity
string
CRITICAL or HIGH
priority
number
Priority ranking (1 = highest)
count
number
Total number of critical alerts
breakdown
object
expired
number
Count of expired items
expiringSoon
number
Count of items expiring in ≤3 days
outOfStock
number
Count of out-of-stock items
criticalLowStock
number
Count of items with less than 5 units

Example Response

{
  "success": true,
  "message": "Critical alerts fetched successfully",
  "data": {
    "alerts": [
      {
        "productName": "Old Cheese",
        "alertType": "expired",
        "severity": "CRITICAL",
        "priority": 1,
        "message": "Expired 5 days ago"
      },
      {
        "productName": "Fresh Milk",
        "alertType": "expiring_critical",
        "severity": "CRITICAL",
        "priority": 2,
        "daysUntilExpiry": 2,
        "message": "Expires in 2 days"
      }
    ],
    "count": 2,
    "breakdown": {
      "expired": 1,
      "expiringSoon": 1,
      "outOfStock": 0,
      "criticalLowStock": 0
    }
  }
}

Category-Specific Alerts

Get all alerts for a specific category. Access: Private (all authenticated users)

Path Parameters

category
string
required
Category name (case-insensitive)

Response

category
string
Category name
alerts
array
Array of items with their alerts
alerts
array
Array of alert objects for this item
type
string
Alert type
severity
string
Severity level
message
string
Alert message
count
number
Number of items with alerts

Example Response

{
  "success": true,
  "message": "Alerts for Dairy category fetched successfully",
  "data": {
    "category": "Dairy",
    "alerts": [
      {
        "_id": "65a1234567890abcdef12345",
        "productName": "Fresh Milk",
        "category": "Dairy",
        "quantity": 25,
        "alerts": [
          {
            "type": "expiring_soon",
            "severity": "HIGH",
            "message": "Expires in 2 days"
          }
        ]
      },
      {
        "_id": "65a9876543210fedcba98765",
        "productName": "Cheese",
        "category": "Dairy",
        "quantity": 3,
        "alerts": [
          {
            "type": "low_stock",
            "severity": "HIGH",
            "message": "Only 3 units left"
          }
        ]
      }
    ],
    "count": 2
  }
}

Alert Summary

Get dashboard summary of all alert counts. Access: Private (all authenticated users)

Response

summary
object
totalAlerts
number
Total number of alerts
breakdown
object
expired
number
Count of expired items
expiringSoon
number
Count of items expiring within 7 days
outOfStock
number
Count of out-of-stock items
lowStock
number
Count of low stock items (quantity < 10)
criticalCount
number
Count of critical alerts (expired + out of stock)

Example Response

{
  "success": true,
  "message": "Alert summary fetched successfully",
  "data": {
    "summary": {
      "totalAlerts": 15,
      "breakdown": {
        "expired": 2,
        "expiringSoon": 4,
        "outOfStock": 3,
        "lowStock": 6
      },
      "criticalCount": 5
    }
  }
}

Severity Levels

SeverityDescriptionUse Case
CRITICALRequires immediate actionExpired items, items expiring in ≤1 day
HIGHUrgent attention neededOut of stock, very low stock (below 5), expiring in ≤3 days
MEDIUMShould be addressed soonLow stock (5-9), expiring in 4-5 days
LOWFor awarenessExpiring in 6-7 days
Always prioritize CRITICAL and HIGH severity alerts to prevent product waste and stockouts.

Build docs developers (and LLMs) love