Skip to main content

Get Sales Analytics

Headers

Authorization
string
required
Bearer token for authentication

Response

success
boolean
Indicates if the request was successful
data
object
Analytics data object
data.daily
object
Daily sales data for the last 7 days
data.daily.labels
array
Array of day labels (e.g., [“Dom”, “Lun”, “Mar”, …])
data.daily.values
array
Array of daily revenue values
data.monthly
object
Monthly sales data for the last 6 months
data.monthly.labels
array
Array of month labels
data.monthly.values
array
Array of monthly revenue values
data.topProducts
array
Top selling products by sales volume

Example Request

curl -X GET https://cemac-api.vercel.app/analysis/sales \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json"

Example Response

{
  "success": true,
  "data": {
    "daily": {
      "labels": ["Dom", "Lun", "Mar", "Mie", "Jue", "Vie", "Sab"],
      "values": [1500, 2300, 1800, 2100, 2800, 3200, 2600]
    },
    "monthly": {
      "labels": ["Jun", "Jul", "Ago", "Sep", "Oct", "Nov"],
      "values": [48000, 51000, 54000, 58000, 62000, 65000]
    },
    "topProducts": [
      {
        "id": "prod_123",
        "name": "Cuaderno Profesional 100 hojas",
        "sales": 150,
        "revenue": 6825
      },
      {
        "id": "prod_456",
        "name": "Bolígrafo BIC Azul",
        "sales": 120,
        "revenue": 2400
      }
    ]
  }
}

Error Codes

  • 401 - Unauthorized
  • 500 - Internal server error

Get Executive Summary

Headers

Authorization
string
required
Bearer token for authentication

Response

success
boolean
Indicates if the request was successful
data
object
Executive summary data
data.currentMonth
object
Current month statistics
data.currentMonth.sales
number
Total number of sales this month
data.currentMonth.revenue
number
Total revenue this month
data.currentMonth.averageOrderValue
number
Average order value this month
data.lastMonth
object
Last month statistics
data.growth
object
Growth percentages
data.growth.revenue
number
Revenue growth percentage
data.growth.sales
number
Sales growth percentage

Example Request

curl -X GET https://cemac-api.vercel.app/analysis/sales/summary \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json"

Example Response

{
  "success": true,
  "data": {
    "currentMonth": {
      "sales": 45,
      "revenue": 12500.75,
      "averageOrderValue": 277.79
    },
    "lastMonth": {
      "sales": 38,
      "revenue": 10200.5,
      "averageOrderValue": 268.43
    },
    "growth": {
      "revenue": 22.55,
      "sales": 18.42
    }
  }
}

Get Custom Period Analytics

Headers

Authorization
string
required
Bearer token for authentication

Query Parameters

startDate
string
required
Start date for the analysis period (ISO 8601 format)
endDate
string
required
End date for the analysis period (ISO 8601 format)
groupBy
string
default:"day"
Grouping interval: “day” or “month”

Response

success
boolean
Indicates if the request was successful
data
object
Custom period analytics data
data.labels
array
Array of date labels based on groupBy parameter
data.values
array
Array of revenue values for each period

Example Request

curl -X GET "https://cemac-api.vercel.app/analysis/sales/custom?startDate=2025-10-01&endDate=2025-11-16&groupBy=day" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json"

Example Response

{
  "success": true,
  "data": {
    "labels": ["01/10", "02/10", "03/10", "04/10", "05/10"],
    "values": [1500, 2300, 1800, 2100, 2800]
  }
}

Get Today’s Statistics

Headers

Authorization
string
required
Bearer token for authentication

Query Parameters

startDate
string
required
Set to today’s date to get today’s stats (ISO 8601 format)
limit
number
default:"1000"
Number of sales to retrieve

Response

success
boolean
Indicates if the request was successful
sales
array
Array of today’s sales

Example Request

curl -X GET "https://cemac-api.vercel.app/sales?startDate=2025-11-16&limit=1000" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json"

Example Response

{
  "success": true,
  "sales": [
    {
      "id": "sale_001",
      "date": "2025-11-16",
      "total": 263.90,
      "cliente": "María González",
      "products": [
        {
          "productId": "prod_123",
          "quantity": 5
        }
      ]
    }
  ]
}
The frontend calculates today’s statistics from the sales data, including total revenue, number of orders, products sold, and unique customers.

Get Inventory Analysis

Headers

Authorization
string
required
Bearer token for authentication

Query Parameters

limit
number
default:"1000"
Maximum number of products to retrieve

Response

success
boolean
Indicates if the request was successful
products
array
Array of all products with stock information

Example Request

curl -X GET "https://cemac-api.vercel.app/inventory?limit=1000" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json"

Example Response

{
  "success": true,
  "products": [
    {
      "id": "prod_123",
      "name": "Cuaderno A4",
      "stock": 150,
      "availability": "available"
    },
    {
      "id": "prod_456",
      "name": "Bolígrafo",
      "stock": 5,
      "availability": "limited"
    },
    {
      "id": "prod_789",
      "name": "Marcador",
      "stock": 0,
      "availability": "out_of_stock"
    }
  ]
}
The analytics service categorizes products as:
  • Disponible: Stock > 10 or availability = “unlimited”
  • Stock Bajo: Stock between 1 and 10
  • Agotado: Stock = 0

Error Codes

  • 401 - Unauthorized
  • 500 - Internal server error

Analytics Data Processing

The CEMAC analytics service includes fallback mechanisms:
  • If /analysis/sales endpoint is unavailable, analytics are calculated from /sales endpoint data
  • Daily data shows the last 7 days
  • Monthly data shows the last 6 months
  • Top products are ranked by sales volume
  • All calculations include proper date filtering and aggregation

Build docs developers (and LLMs) love