API Reference

This page contains the complete API reference for all custom endpoints that are running on the backend server. Once you have the server running locally, you can access the API via the following url: http://localhost:3001/api.

GET /

Root endpoint for health checks

Simple health check endpoint used by Cloud Run and load balancers

Status Codes:
  • 200 OK – Service is running

GET /api/health

Health check endpoint

Checks API and database connectivity. Returns OK even if database is down (for Cloud Run health checks)

Status Codes:
  • 200 OK – Service health status

POST /api/register

Register new user (Admin only)

Creates a new user account. Requires admin role.

Status Codes:
POST /api/login

User login

Authenticate user and receive JWT token. Logs all login attempts (success and failure).

Status Codes:
GET /api/me

Get current user

Returns the authenticated user’s information

Status Codes:
GET /api/current-stock

Get current stock status

Retrieves the current stock status for all stores and items from the v_current_stock_status view

Status Codes:
GET /api/daily-summary

Get daily stock summary

Retrieves daily stock summary data for the specified number of days, optionally filtered by store

Query Parameters:
  • days (integer) – Number of days to retrieve

  • store (string) – Filter by store code

Status Codes:
GET /api/store-performance

Get store performance metrics

Retrieves performance metrics for all stores from the v_store_performance view

Status Codes:
GET /api/item-performance

Get item performance metrics

Retrieves performance metrics for items including out-of-stock events, tracking statistics, and date ranges

Query Parameters:
  • limit (integer) – Maximum number of items to return

  • startDate (string) – Filter from this date (YYYY-MM-DD)

  • endDate (string) – Filter until this date (YYYY-MM-DD)

Status Codes:
GET /api/out-of-stock

Get recent out of stock events

Retrieves out of stock events from the last N hours, optionally filtered by store

Query Parameters:
  • hours (integer) – Number of hours to look back

  • store (string) – Filter by store code

Status Codes:
GET /api/time-windows

Get time window stock data

Retrieves stock status data grouped by time windows for analysis. Can filter by date range or specific date, and optionally by store

Query Parameters:
  • days (integer) – Number of days to retrieve (ignored if date is provided)

  • date (string) – Specific date to retrieve (YYYY-MM-DD). Overrides days parameter

  • store (string) – Filter by store code

Status Codes:

Get weekly stock trends

Retrieves weekly stock trends from the v_weekly_stock_trends view for the specified number of weeks

Query Parameters:
  • weeks (integer) – Number of weeks to retrieve

  • store (string) – Filter by store code

Status Codes:
GET /api/stores

Get list of stores

Returns a list of all unique store codes from the stock_status table

Status Codes:
GET /api/weekly-sales-stores

Get weekly sales store names

Returns a list of all unique store names from the weekly_sales database

Status Codes:
GET /api/weekly-sales-years

Get available years from weekly sales

Returns a list of all available years in the weekly_sales database, sorted descending

Status Codes:
GET /api/items

Get list of items

Returns a list of all unique items (item_id and item_name) from the stock_status table

Status Codes:
GET /api/daily-sales

Get daily sales data

Retrieves daily sales data with catering/non-catering breakdown. Supports filtering by date range and store code

Query Parameters:
  • days (integer) – Number of days to retrieve (used if startDate not provided)

  • store (string) – Filter by store code

  • startDate (string) – Start date (YYYY-MM-DD). Overrides days parameter

  • endDate (string) – End date (YYYY-MM-DD)

Status Codes:
GET /api/weekly-sales

Get weekly sales data

Retrieves weekly sales data from the weekly_sales database. Store parameter is required. Uses the same query structure as generate_visualizations.py

Query Parameters:
  • store (string) – Store name (required) (Required)

  • years (string) – Comma-separated list of years (e.g., “2024,2025”)

Status Codes:
GET /api/login-logs

Get login logs (Admin only)

Retrieves login attempt logs with filtering options. Requires admin role.

Query Parameters:
  • limit (integer) – Maximum number of logs to return

  • username (string) – Filter by username

  • type (string) – Filter by attempt type

  • startDate (string) – Filter logs from this date (YYYY-MM-DD)

  • endDate (string) – Filter logs until this date (YYYY-MM-DD)

Status Codes: