Skip to main content

Generate Alerts

Headers

Authorization
string
required
Bearer token for authentication (admin role required)

Response

success
boolean
Indicates if alerts were generated successfully
alertsGenerated
number
Number of new alerts created
message
string
Success or error message

Example Request

curl -X POST https://cemac-api.vercel.app/alerts/generate \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json"

Example Response

{
  "success": true,
  "alertsGenerated": 5,
  "message": "Alertas generadas exitosamente"
}

Error Codes

  • 401 - Unauthorized
  • 403 - Forbidden - Admin role required
  • 500 - Internal server error

Get Alerts

Headers

Authorization
string
required
Bearer token for authentication

Query Parameters

status
string
Filter by alert status (“pendiente”, “en_proceso”, “atendido”)
priority
string
Filter by priority level (“critica”, “urgente”, “media”, “baja”)
startDate
string
Filter alerts from this date (ISO 8601 format)
endDate
string
Filter alerts until this date (ISO 8601 format)
page
number
default:"1"
Page number for pagination
limit
number
default:"10"
Number of alerts per page
sortBy
string
Field to sort by (e.g., “createdAt”, “priority”)
sortOrder
string
Sort order: “asc” or “desc”

Response

success
boolean
Indicates if the request was successful
data
object
Response data object
data.alerts
array
Array of alert objects
data.pagination
object
Pagination information

Example Request

curl -X GET "https://cemac-api.vercel.app/alerts?status=pendiente&priority=urgente&page=1&limit=10" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json"

Example Response

{
  "success": true,
  "data": {
    "alerts": [
      {
        "id": "alert_001",
        "type": "stock_low",
        "priority": "urgente",
        "status": "pendiente",
        "productId": "prod_123",
        "productName": "Cuaderno Profesional 100 hojas",
        "productCategory": "Cuadernos y Libretas",
        "currentStock": 5,
        "minThreshold": 20,
        "message": "Stock bajo: Solo quedan 5 unidades de Cuaderno Profesional 100 hojas",
        "createdAt": "2025-11-16T10:30:00.000Z",
        "updatedAt": "2025-11-16T10:30:00.000Z"
      },
      {
        "id": "alert_002",
        "type": "stock_out",
        "priority": "critica",
        "status": "pendiente",
        "productId": "prod_456",
        "productName": "Bolígrafo BIC Azul",
        "productCategory": "Bolígrafos",
        "currentStock": 0,
        "minThreshold": 10,
        "message": "Producto agotado: Bolígrafo BIC Azul",
        "createdAt": "2025-11-16T09:15:00.000Z",
        "updatedAt": "2025-11-16T09:15:00.000Z"
      }
    ],
    "pagination": {
      "currentPage": 1,
      "totalPages": 3,
      "total": 25,
      "totalAlerts": 25,
      "hasNextPage": true,
      "hasPrevPage": false,
      "limit": 10
    }
  }
}

Error Codes

  • 401 - Unauthorized
  • 500 - Internal server error

Get Latest Critical Alert

Headers

Authorization
string
required
Bearer token for authentication

Response

success
boolean
Indicates if the request was successful
data
object
Response data object
data.hasAlert
boolean
Indicates if a critical alert exists
data.alert
object
The latest critical alert object (if exists)

Example Request

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

Example Response

{
  "success": true,
  "data": {
    "hasAlert": true,
    "alert": {
      "id": "alert_002",
      "type": "stock_out",
      "priority": "critica",
      "status": "pendiente",
      "productId": "prod_456",
      "productName": "Bolígrafo BIC Azul",
      "currentStock": 0,
      "message": "Producto agotado: Bolígrafo BIC Azul",
      "createdAt": "2025-11-16T09:15:00.000Z"
    }
  }
}

Get Alerts Count

Headers

Authorization
string
required
Bearer token for authentication

Response

success
boolean
Indicates if the request was successful
data
object
Alert counts by category
data.byStatus
object
Counts grouped by status
data.byPriority
object
Counts grouped by priority
data.total
number
Total number of alerts

Example Request

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

Example Response

{
  "success": true,
  "data": {
    "byStatus": {
      "pendiente": 15,
      "en_proceso": 8,
      "atendido": 2
    },
    "byPriority": {
      "critica": 3,
      "urgente": 12,
      "media": 7,
      "baja": 3
    },
    "total": 25
  }
}

Get Alert by ID

Headers

Authorization
string
required
Bearer token for authentication

Path Parameters

alertId
string
required
ID of the alert to retrieve

Response

success
boolean
Indicates if the alert was found
alert
object
Alert object with full details

Example Request

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

Example Response

{
  "success": true,
  "alert": {
    "id": "alert_001",
    "type": "stock_low",
    "priority": "urgente",
    "status": "pendiente",
    "productId": "prod_123",
    "productName": "Cuaderno Profesional 100 hojas",
    "currentStock": 5,
    "minThreshold": 20,
    "message": "Stock bajo: Solo quedan 5 unidades",
    "createdAt": "2025-11-16T10:30:00.000Z",
    "updatedAt": "2025-11-16T10:30:00.000Z"
  }
}

Error Codes

  • 401 - Unauthorized
  • 404 - Alert not found
  • 500 - Internal server error

Update Alert Status

Headers

Authorization
string
required
Bearer token for authentication

Path Parameters

alertId
string
required
ID of the alert to update

Request Body

status
string
required
New status: “pendiente”, “en_proceso”, or “atendido”
notes
string
Optional notes about the status change

Response

success
boolean
Indicates if the update was successful
alert
object
Updated alert object

Example Request

curl -X PUT https://cemac-api.vercel.app/alerts/alert_001/status \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "status": "en_proceso",
    "notes": "Pedido realizado al proveedor"
  }'

Example Response

{
  "success": true,
  "alert": {
    "id": "alert_001",
    "status": "en_proceso",
    "notes": "Pedido realizado al proveedor",
    "updatedAt": "2025-11-16T11:00:00.000Z"
  }
}

Error Codes

  • 400 - Invalid status value
  • 401 - Unauthorized
  • 404 - Alert not found
  • 500 - Internal server error

Mark All Alerts as Read

Headers

Authorization
string
required
Bearer token for authentication

Request Body

filters
object
Optional filters to select which alerts to mark (e.g., {"priority": "media"})
notes
string
Optional notes to add to all updated alerts

Response

success
boolean
Indicates if the operation was successful
updatedCount
number
Number of alerts updated

Example Request

curl -X PUT https://cemac-api.vercel.app/alerts/mark-all-read \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "filters": {"priority": "media"},
    "notes": "Revisión masiva completada"
  }'

Example Response

{
  "success": true,
  "updatedCount": 7,
  "message": "7 alertas marcadas como atendidas"
}

Get Alerts History

Headers

Authorization
string
required
Bearer token for authentication

Query Parameters

month
string
Filter by specific month (format: “YYYY-MM”)
page
number
default:"1"
Page number for pagination
limit
number
default:"10"
Number of items per page

Response

success
boolean
Indicates if the request was successful
history
array
Array of historical alert records
pagination
object
Pagination information

Example Request

curl -X GET "https://cemac-api.vercel.app/alerts/history?month=2025-11&page=1&limit=10" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json"

Example Response

{
  "success": true,
  "history": [
    {
      "id": "alert_003",
      "type": "stock_low",
      "priority": "media",
      "status": "atendido",
      "productName": "Marcador Sharpie Negro",
      "resolvedAt": "2025-11-16T12:00:00.000Z",
      "notes": "Stock repuesto"
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 10,
    "total": 50
  }
}

Update Alert Thresholds

Headers

Authorization
string
required
Bearer token for authentication (admin role required)

Request Body

stockThresholds
object
required
Threshold configuration object
stockThresholds.critical
number
Stock level for critical alerts
stockThresholds.low
number
Stock level for low stock alerts
stockThresholds.warning
number
Stock level for warning alerts

Response

success
boolean
Indicates if thresholds were updated
settings
object
Updated threshold settings

Example Request

curl -X PUT https://cemac-api.vercel.app/alerts/settings/thresholds \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "stockThresholds": {
      "critical": 5,
      "low": 20,
      "warning": 50
    }
  }'

Example Response

{
  "success": true,
  "settings": {
    "stockThresholds": {
      "critical": 5,
      "low": 20,
      "warning": 50
    },
    "updatedAt": "2025-11-16T13:00:00.000Z"
  }
}

Error Codes

  • 401 - Unauthorized
  • 403 - Forbidden - Admin role required
  • 500 - Internal server error

Delete Alert

Headers

Authorization
string
required
Bearer token for authentication (admin role required)

Path Parameters

alertId
string
required
ID of the alert to delete

Response

success
boolean
Indicates if deletion was successful
message
string
Confirmation message

Example Request

curl -X DELETE https://cemac-api.vercel.app/alerts/alert_001 \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json"

Example Response

{
  "success": true,
  "message": "Alerta eliminada exitosamente"
}

Error Codes

  • 401 - Unauthorized
  • 403 - Forbidden - Admin role required
  • 404 - Alert not found
  • 500 - Internal server error

Build docs developers (and LLMs) love