Overview
The Dashboard API provides aggregated analytics data for sales performance, top products, and user metrics. All endpoints require authentication and automatically filter data based on the authenticated user’s context.
GET /dash/sales/day
Retrieve sales data aggregated by day.
Requires authentication. Returns daily sales for the authenticated user.
Response
Daily sales data Total revenue for the day
curl -X GET https://api.yourdomain.com/dash/sales/day \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Cache-Control: no-cache"
[
{
"date" : "2026-03-07" ,
"totalSales" : 15 ,
"revenue" : 12450.50
},
{
"date" : "2026-03-06" ,
"totalSales" : 12 ,
"revenue" : 9870.25
},
{
"date" : "2026-03-05" ,
"totalSales" : 18 ,
"revenue" : 15320.75
}
]
GET /dash/sales/month
Retrieve sales data aggregated by month.
Response
Monthly sales data Total revenue for the month
curl -X GET https://api.yourdomain.com/dash/sales/month \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Cache-Control: no-cache"
[
{
"month" : "2026-03" ,
"totalSales" : 245 ,
"revenue" : 187650.75
},
{
"month" : "2026-02" ,
"totalSales" : 198 ,
"revenue" : 152340.50
},
{
"month" : "2026-01" ,
"totalSales" : 210 ,
"revenue" : 165890.25
}
]
GET /dash/top-products
Retrieve top-selling products with optional date filtering.
Requires authentication. Supports date range filtering.
Query Parameters
Start date for filtering (ISO format: YYYY-MM-DD)
End date for filtering (ISO format: YYYY-MM-DD)
Response
cURL - All Time
cURL - Date Range
JavaScript
curl -X GET https://api.yourdomain.com/dash/top-products \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Cache-Control: no-cache"
[
{
"productId" : "prod_123" ,
"name" : "Laptop Dell XPS 15" ,
"totalSold" : 45 ,
"revenue" : 58499.55 ,
"image" : "https://cdn.example.com/laptop.jpg"
},
{
"productId" : "prod_124" ,
"name" : "Wireless Mouse" ,
"totalSold" : 120 ,
"revenue" : 3598.80 ,
"image" : "https://cdn.example.com/mouse.jpg"
},
{
"productId" : "prod_125" ,
"name" : "USB-C Hub" ,
"totalSold" : 78 ,
"revenue" : 3120.22 ,
"image" : "https://cdn.example.com/hub.jpg"
}
]
GET /dash/sales/user
Retrieve sales data by user.
Requires authentication. Returns sales breakdown across all users (admin view) or current user’s sales.
Response
curl -X GET https://api.yourdomain.com/dash/sales/user \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Cache-Control: no-cache"
[
{
"userId" : "usr_123456" ,
"userName" : "John Doe" ,
"totalSales" : 245 ,
"revenue" : 187650.75
},
{
"userId" : "usr_123457" ,
"userName" : "Jane Smith" ,
"totalSales" : 198 ,
"revenue" : 152340.50
}
]
GET /dash/sales/week
Retrieve sales data aggregated by week.
Response
Weekly sales data Week identifier (e.g., “2026-W10”)
curl -X GET https://api.yourdomain.com/dash/sales/week \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Cache-Control: no-cache"
[
{
"week" : "2026-W10" ,
"startDate" : "2026-03-02" ,
"endDate" : "2026-03-08" ,
"totalSales" : 58 ,
"revenue" : 45320.75
},
{
"week" : "2026-W09" ,
"startDate" : "2026-02-23" ,
"endDate" : "2026-03-01" ,
"totalSales" : 62 ,
"revenue" : 48650.50
}
]
GET /dash/product-profit
Retrieve profit analysis by product.
Requires authentication. Shows revenue, cost, and profit margins.
Response
curl -X GET https://api.yourdomain.com/dash/product-profit \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Cache-Control: no-cache"
[
{
"productId" : "prod_123" ,
"name" : "Laptop Dell XPS 15" ,
"totalRevenue" : 58499.55 ,
"totalCost" : 40500.00 ,
"profit" : 17999.55 ,
"profitMargin" : 30.77
},
{
"productId" : "prod_124" ,
"name" : "Wireless Mouse" ,
"totalRevenue" : 3598.80 ,
"totalCost" : 1800.00 ,
"profit" : 1798.80 ,
"profitMargin" : 50.00
}
]
Complete Dashboard Data
Fetch all dashboard metrics in a single Redux action:
export const fetchDashboardData = ( startDate = null , endDate = null ) => async ( dispatch ) => {
dispatch ({ type: "DASHBOARD_REQUEST" });
try {
const noCacheHeaders = { "Cache-Control" : "no-cache" };
const query = startDate && endDate
? `?startDate= ${ encodeURIComponent ( startDate ) } &endDate= ${ encodeURIComponent ( endDate ) } `
: "" ;
const [
salesByDayRes ,
salesByMonthRes ,
topProductsRes ,
salesByUserRes ,
salesByWeekRes ,
productProfitRes
] = await Promise . all ([
api . get ( "/dash/sales/day" , { headers: noCacheHeaders }),
api . get ( "/dash/sales/month" , { headers: noCacheHeaders }),
api . get ( `/dash/top-products ${ query } ` , { headers: noCacheHeaders }),
api . get ( "/dash/sales/user" , { headers: noCacheHeaders }),
api . get ( "/dash/sales/week" , { headers: noCacheHeaders }),
api . get ( "/dash/product-profit" , { headers: noCacheHeaders }),
]);
dispatch ({
type: "DASHBOARD_SUCCESS" ,
payload: {
salesByDay: salesByDayRes . data || [],
salesByMonth: salesByMonthRes . data || [],
topProducts: topProductsRes . data || [],
salesByUser: salesByUserRes . data || [],
salesByWeek: salesByWeekRes . data || [],
productProfit: productProfitRes . data || [],
},
});
} catch ( error ) {
dispatch ({
type: "DASHBOARD_FAILURE" ,
payload: error . response ?. data ?. error || error . message ,
});
}
};
Dashboard Use Cases
const renderSalesChart = async () => {
const dailySales = await getSalesByDay ();
const chartData = dailySales . map ( day => ({
date: new Date ( day . date ). toLocaleDateString (),
sales: day . totalSales ,
revenue: day . revenue
}));
// Render with your charting library
renderLineChart ( chartData );
};
const displayTopProducts = async ( startDate , endDate ) => {
const topProducts = await getTopProducts ( startDate , endDate );
console . log ( 'Top 5 Products:' );
topProducts . slice ( 0 , 5 ). forEach (( product , index ) => {
console . log ( ` ${ index + 1 } . ${ product . name } ` );
console . log ( ` Sold: ${ product . totalSold } units` );
console . log ( ` Revenue: $ ${ product . revenue . toFixed ( 2 ) } ` );
});
};
Profit Analysis Dashboard
const analyzeProfits = async () => {
const profits = await getProductProfits ();
const totalRevenue = profits . reduce (( sum , p ) => sum + p . totalRevenue , 0 );
const totalProfit = profits . reduce (( sum , p ) => sum + p . profit , 0 );
const avgMargin = totalProfit / totalRevenue * 100 ;
console . log ( `Total Revenue: $ ${ totalRevenue . toFixed ( 2 ) } ` );
console . log ( `Total Profit: $ ${ totalProfit . toFixed ( 2 ) } ` );
console . log ( `Avg Profit Margin: ${ avgMargin . toFixed ( 2 ) } %` );
// Find best and worst performers
const bestProduct = profits . reduce (( max , p ) =>
p . profitMargin > max . profitMargin ? p : max
);
const worstProduct = profits . reduce (( min , p ) =>
p . profitMargin < min . profitMargin ? p : min
);
console . log ( ` \n Best Performer: ${ bestProduct . name } ( ${ bestProduct . profitMargin } % margin)` );
console . log ( `Needs Improvement: ${ worstProduct . name } ( ${ worstProduct . profitMargin } % margin)` );
};
Cache Control
All dashboard endpoints use Cache-Control: no-cache headers to ensure fresh data:
const headers = { 'Cache-Control' : 'no-cache' };
await api . get ( '/dash/sales/day' , { headers });
This prevents stale data in analytics dashboards.
Error Codes
Status Description 200Success 401Unauthorized 404No data found 500Server error
Dashboard data is fetched using Promise.all() to load all metrics simultaneously, reducing total load time.
Use date range parameters on /dash/top-products to reduce response size and improve query performance.
While the API returns fresh data, consider client-side caching with a TTL (e.g., 5 minutes) for frequently accessed dashboards.