Skip to main content

Get Products

Headers

Authorization
string
required
Bearer token for authentication

Query Parameters

Search term to filter products by name or description
category
string
Filter by product category
brand
string
Filter by product brand
supplier
string
Filter by supplier
availability
string
Filter by availability status (e.g., “available”, “limited”, “unlimited”)
minPrice
number
Minimum price filter
maxPrice
number
Maximum price filter
page
number
default:"1"
Page number for pagination
limit
number
default:"10"
Number of items per page
sortBy
string
Field to sort by (e.g., “name”, “price”, “stock”)
sortOrder
string
Sort order: “asc” or “desc”

Response

success
boolean
Indicates if the request was successful
products
array
Array of product objects
pagination
object
Pagination information including total, pages, current page

Example Request

curl -X GET "https://cemac-api.vercel.app/inventory?page=1&limit=10&category=Cuadernos" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json"

Example Response

{
  "success": true,
  "products": [
    {
      "id": "prod_123",
      "name": "Cuaderno Profesional 100 hojas",
      "description": "Cuaderno rayado profesional",
      "price": 45.50,
      "stock": 150,
      "category": "Cuadernos",
      "brand": "Scribe",
      "supplier": "Papelería Central",
      "availability": "available",
      "imageUrl": "https://example.com/image.jpg"
    }
  ],
  "pagination": {
    "total": 100,
    "page": 1,
    "limit": 10,
    "totalPages": 10
  }
}

Error Codes

  • 401 - Unauthorized - Invalid or missing token
  • 500 - Internal server error

Create Product

Headers

Authorization
string
required
Bearer token for authentication

Request Body (FormData)

name
string
required
Product name
description
string
Product description
price
number
required
Product price
stock
number
required
Initial stock quantity
category
string
required
Product category
brand
string
Product brand
supplier
string
Supplier name
availability
string
Availability status
image
file
Product image file (multipart/form-data)

Response

success
boolean
Indicates if the product was created
product
object
Created product object
message
string
Success or error message

Example Request

curl -X POST https://cemac-api.vercel.app/inventory \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -F "name=Cuaderno A4" \
  -F "price=35.00" \
  -F "stock=100" \
  -F "category=Cuadernos" \
  -F "image=@/path/to/image.jpg"

Example Response

{
  "success": true,
  "product": {
    "id": "prod_456",
    "name": "Cuaderno A4",
    "price": 35.00,
    "stock": 100,
    "category": "Cuadernos",
    "imageUrl": "https://example.com/uploads/image.jpg",
    "createdAt": "2025-11-16T10:30:00Z"
  },
  "message": "Producto creado exitosamente"
}

Error Codes

  • 400 - Invalid input or missing required fields
  • 401 - Unauthorized
  • 403 - Forbidden - Admin role required
  • 500 - Internal server error

Update Product

Headers

Authorization
string
required
Bearer token for authentication

Path Parameters

productId
string
required
ID of the product to update

Request Body (FormData)

name
string
Product name
description
string
Product description
price
number
Product price
stock
number
Stock quantity
category
string
Product category
brand
string
Product brand
supplier
string
Supplier name
availability
string
Availability status
image
file
New product image file

Response

success
boolean
Indicates if the update was successful
product
object
Updated product object
message
string
Success or error message

Example Request

curl -X PUT https://cemac-api.vercel.app/inventory/prod_123 \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -F "price=40.00" \
  -F "stock=200"

Example Response

{
  "success": true,
  "product": {
    "id": "prod_123",
    "name": "Cuaderno Profesional 100 hojas",
    "price": 40.00,
    "stock": 200,
    "updatedAt": "2025-11-16T11:00:00Z"
  },
  "message": "Producto actualizado exitosamente"
}

Error Codes

  • 400 - Invalid input
  • 401 - Unauthorized
  • 403 - Forbidden - Admin role required
  • 404 - Product not found
  • 500 - Internal server error

Delete Product

Headers

Authorization
string
required
Bearer token for authentication

Path Parameters

productId
string
required
ID of the product to delete

Response

success
boolean
Indicates if deletion was successful
message
string
Confirmation message

Example Request

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

Example Response

{
  "success": true,
  "message": "Producto eliminado exitosamente"
}

Error Codes

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

Update Stock

Headers

Authorization
string
required
Bearer token for authentication

Path Parameters

productId
string
required
ID of the product

Request Body

quantity
number
required
Quantity to add or subtract
type
string
default:"add"
Operation type: “add” or “subtract”

Response

success
boolean
Indicates if stock was updated
product
object
Updated product with new stock

Example Request

curl -X PUT https://cemac-api.vercel.app/inventory/products/prod_123/stock \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "quantity": 50,
    "type": "add"
  }'

Example Response

{
  "success": true,
  "product": {
    "id": "prod_123",
    "stock": 250,
    "updatedAt": "2025-11-16T12:00:00Z"
  }
}

Get Stock History

Headers

Authorization
string
required
Bearer token for authentication

Path Parameters

productId
string
required
ID of the product

Response

success
boolean
Indicates if request was successful
history
array
Array of stock change records

Example Request

curl -X GET https://cemac-api.vercel.app/inventory/products/prod_123/stock-history \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json"

Example Response

{
  "success": true,
  "history": [
    {
      "id": "hist_001",
      "productId": "prod_123",
      "type": "add",
      "quantity": 50,
      "previousStock": 200,
      "newStock": 250,
      "timestamp": "2025-11-16T12:00:00Z",
      "userId": "user_123"
    }
  ]
}

Error Codes

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

Build docs developers (and LLMs) love