Skip to main content
The Forecast API provides intelligent forecasting capabilities to help optimize inventory management through predictive analytics.
All forecast endpoints require authentication and are accessible only to Manager and Admin roles.

Demand Forecast

Get demand forecast for a specific product based on historical consumption patterns. Access: Private (Manager/Admin)

Query Parameters

productId
string
required
MongoDB ObjectId of the product
months
number
default:3
Number of months to forecast (1-12)

Response

product
object
consumptionRate
number
Daily consumption rate (units per day)
forecast
array
Monthly projections
period
string
Forecast period description

Example Request

GET /api/forecast/demand?productId=673ab12c5f8e9a001234abcd&months=3
Authorization: Bearer <token>

Example Response

{
  "success": true,
  "message": "Demand forecast generated successfully",
  "data": {
    "product": {
      "id": "673ab12c5f8e9a001234abcd",
      "productName": "Fresh Milk",
      "category": "Dairy",
      "currentQuantity": 85,
      "sku": "DA-001"
    },
    "consumptionRate": 2.5,
    "forecast": [
      {
        "month": "Month 1",
        "projectedDemand": 75,
        "projectedStock": 10,
        "needsReorder": true
      },
      {
        "month": "Month 2",
        "projectedDemand": 150,
        "projectedStock": 0,
        "needsReorder": true
      },
      {
        "month": "Month 3",
        "projectedDemand": 225,
        "projectedStock": 0,
        "needsReorder": true
      }
    ],
    "period": "3 months"
  }
}
Products require at least 7 days of historical data for accurate forecasting. If insufficient data exists, the endpoint returns a message indicating this limitation.

Category Demand Forecast

Get aggregated demand forecast for all products in a category. Access: Private (Manager/Admin)

Path Parameters

category
string
required
Category name (case-insensitive)

Query Parameters

months
number
default:3
Number of months to forecast

Response

category
string
Category name
itemCount
number
Number of items in category
currentTotalQuantity
number
Total current quantity across all items
avgConsumptionRate
number
Average daily consumption rate for category
forecast
array
Monthly projections for category

Example Request

GET /api/forecast/demand/category/Dairy?months=2
Authorization: Bearer <token>

Example Response

{
  "success": true,
  "message": "Category demand forecast generated successfully",
  "data": {
    "category": "Dairy",
    "itemCount": 5,
    "currentTotalQuantity": 420,
    "avgConsumptionRate": 3.2,
    "forecast": [
      {
        "month": "Month 1",
        "projectedDemand": 480,
        "projectedStock": 0
      },
      {
        "month": "Month 2",
        "projectedDemand": 960,
        "projectedStock": 0
      }
    ],
    "period": "2 months"
  }
}

Reorder Suggestions

Get intelligent reorder suggestions based on consumption rates and lead times. Access: Private (Manager/Admin)

Query Parameters

leadTime
number
default:7
Lead time in days for receiving orders
safetyStock
number
Safety stock multiplier (e.g., 1.5 = 150% of lead time demand)

Response

suggestions
array
List of products that need reordering
count
number
Number of reorder suggestions
parameters
object
Configuration parameters used

Example Request

GET /api/forecast/reorder-suggestions?leadTime=5&safetyStock=2.0
Authorization: Bearer <token>

Example Response

{
  "success": true,
  "message": "Reorder suggestions generated successfully",
  "data": {
    "suggestions": [
      {
        "product": {
          "id": "673ab12c5f8e9a001234abcd",
          "productName": "Chicken Breast",
          "category": "Meat",
          "sku": "MT-015",
          "supplier": "Fresh Poultry Co"
        },
        "currentQuantity": 0,
        "reorderPoint": 15,
        "suggestedOrderQuantity": 90,
        "urgency": "CRITICAL",
        "consumptionRate": 3.0,
        "estimatedStockoutDays": 0
      },
      {
        "product": {
          "id": "673ab12c5f8e9a001234abce",
          "productName": "Yogurt",
          "category": "Dairy",
          "sku": "DA-008",
          "supplier": "Local Dairy Farm"
        },
        "currentQuantity": 8,
        "reorderPoint": 20,
        "suggestedOrderQuantity": 60,
        "urgency": "HIGH",
        "consumptionRate": 2.0,
        "estimatedStockoutDays": 4
      }
    ],
    "count": 2,
    "parameters": {
      "leadTimeDays": 5,
      "safetyStockMultiplier": 2.0
    }
  }
}
CRITICAL urgency items are out of stock and should be ordered immediately. HIGH urgency items are below 50% of their reorder point.
Get historical stock trend analysis for a product. Access: Private (Manager/Admin)

Query Parameters

productId
string
required
MongoDB ObjectId of the product
period
string
default:"30days"
Analysis period: “7days”, “30days”, or “90days”

Response

product
object
Product details
Historical trend data points
analysis
object
Trend analysis

Example Request

GET /api/forecast/stock-trends?productId=673ab12c5f8e9a001234abcd&period=30days
Authorization: Bearer <token>

Example Response

{
  "success": true,
  "message": "Stock trends fetched successfully",
  "data": {
    "product": {
      "id": "673ab12c5f8e9a001234abcd",
      "productName": "Fresh Milk",
      "category": "Dairy",
      "currentQuantity": 85
    },
    "trends": [
      {
        "date": "2025-02-01",
        "estimatedQuantity": 160
      },
      {
        "date": "2025-02-06",
        "estimatedQuantity": 148
      },
      {
        "date": "2025-02-11",
        "estimatedQuantity": 135
      },
      {
        "date": "2025-02-16",
        "estimatedQuantity": 123
      },
      {
        "date": "2025-02-21",
        "estimatedQuantity": 110
      },
      {
        "date": "2025-02-26",
        "estimatedQuantity": 98
      },
      {
        "date": "2025-03-03",
        "estimatedQuantity": 85,
        "isCurrent": true
      }
    ],
    "analysis": {
      "velocityPerDay": 2.5,
      "trend": "decreasing",
      "period": "30days"
    }
  }
}

Expiry Forecast

Predict items likely to expire with remaining stock, helping minimize waste. Access: Private (Manager/Admin)

Response

forecasts
array
Items at risk of expiring with stock remaining
count
number
Total number of items at risk
highRiskCount
number
Number of high-risk items

Example Request

GET /api/forecast/expiry-forecast
Authorization: Bearer <token>

Example Response

{
  "success": true,
  "message": "Expiry forecast generated successfully",
  "data": {
    "forecasts": [
      {
        "product": {
          "id": "673ab12c5f8e9a001234abcd",
          "productName": "Strawberries",
          "category": "Produce",
          "sku": "PR-025"
        },
        "currentQuantity": 100,
        "expiryDate": "2025-03-08T00:00:00.000Z",
        "daysUntilExpiry": 5,
        "consumptionRate": 8.5,
        "projectedQuantityAtExpiry": 58,
        "wastagePercentage": 58.0,
        "riskLevel": "HIGH",
        "recommendation": "Consider promotional pricing or immediate sale"
      },
      {
        "product": {
          "id": "673ab12c5f8e9a001234abce",
          "productName": "Cheese",
          "category": "Dairy",
          "sku": "DA-012"
        },
        "currentQuantity": 45,
        "expiryDate": "2025-03-15T00:00:00.000Z",
        "daysUntilExpiry": 12,
        "consumptionRate": 3.0,
        "projectedQuantityAtExpiry": 9,
        "wastagePercentage": 20.0,
        "riskLevel": "LOW",
        "recommendation": "Current consumption rate is acceptable"
      }
    ],
    "count": 2,
    "highRiskCount": 1
  }
}
Use high-risk expiry forecasts to plan promotional campaigns, discounts, or alternative distribution channels to minimize waste and maximize revenue recovery.

Error Responses

All forecast endpoints return standard error responses:
Status CodeDescription
400Bad Request - Missing or invalid parameters
401Unauthorized - Invalid or missing token
403Forbidden - Insufficient permissions (Worker role)
404Not Found - Product or category not found
500Internal Server Error - Server-side error

Example Error Response

{
  "success": false,
  "message": "Product ID is required"
}

Analytics API

Demand forecasting and business intelligence

Inventory API

Inventory management endpoints

Alerts API

Low stock and expiry alerts

Demand Forecasting Feature

Learn about forecasting algorithms

Build docs developers (and LLMs) love