Skip to main content
All product endpoints require authentication via JWT token cookie.

List Products

Authentication

Required: JWT token via cookie
Role: Any authenticated user

Request Parameters

No parameters required.

Response

ok
boolean
Success indicator
statusCode
number
HTTP status code (200)
mensaje
string
Empty string
data
array
Array of product objects

Example Request

curl -X GET http://localhost:3000/api-productos/productos \
  -b cookies.txt

Example Response

{
  "ok": true,
  "statusCode": 200,
  "mensaje": "",
  "data": [
    {
      "id": 1,
      "nombre": "Laptop Dell XPS 15",
      "precio": 1299.99,
      "stock": 15,
      "descripcion": "High-performance laptop with Intel i7",
      "categoria_id": 1,
      "categoria_nombre": "Electrónica",
      "creado": "2026-01-15T10:30:00.000Z",
      "actualizado": "2026-02-20T14:45:00.000Z"
    }
  ]
}

Error Responses

401 Unauthorized
Missing or invalid authentication token
500 Internal Server Error
Server error
{
  "ok": false,
  "statusCode": 500,
  "mensaje": "Error al listar los productos.",
  "detalles": "Error message"
}

Create Product

Authentication

Required: JWT token via cookie
Role: Any authenticated user

Request Body

nombre
string
required
Product name
precio
number
required
Product price
stock
number
required
Initial stock quantity
descripcion
string
required
Product description
categoria_id
number
required
Category ID (must exist in Categorias table)

Response

ok
boolean
Success indicator
statusCode
number
HTTP status code (201)
mensaje
string
“Producto registrado exitosamente.”
data
null
No data returned

Example Request

curl -X POST http://localhost:3000/api-productos/productos \
  -H "Content-Type: application/json" \
  -b cookies.txt \
  -d '{
    "nombre": "Laptop Dell XPS 15",
    "precio": 1299.99,
    "stock": 15,
    "descripcion": "High-performance laptop with Intel i7",
    "categoria_id": 1
  }'

Example Response

{
  "ok": true,
  "statusCode": 201,
  "mensaje": "Producto registrado exitosamente.",
  "data": null
}

Error Responses

401 Unauthorized
Missing or invalid authentication token
500 Internal Server Error
Server error or foreign key constraint violation
{
  "ok": false,
  "statusCode": 500,
  "mensaje": "Error al registrar el producto.",
  "detalles": "Error message"
}

Get Product by ID

Authentication

Required: JWT token via cookie
Role: Any authenticated user

Path Parameters

id
number
required
Product ID

Response

ok
boolean
Success indicator
statusCode
number
HTTP status code (200)
mensaje
string
Empty string
data
object
Product object with same structure as list endpoint

Example Request

curl -X GET http://localhost:3000/api-productos/productos/1 \
  -b cookies.txt

Example Response

{
  "ok": true,
  "statusCode": 200,
  "mensaje": "",
  "data": {
    "id": 1,
    "nombre": "Laptop Dell XPS 15",
    "precio": 1299.99,
    "stock": 15,
    "descripcion": "High-performance laptop with Intel i7",
    "categoria_id": 1,
    "categoria_nombre": "Electrónica",
    "creado": "2026-01-15T10:30:00.000Z",
    "actualizado": "2026-02-20T14:45:00.000Z"
  }
}

Error Responses

400 Bad Request
Product not found
{
  "ok": false,
  "statusCode": 400,
  "mensaje": "Producto no encontrado.",
  "detalles": null
}
401 Unauthorized
Missing or invalid authentication token
500 Internal Server Error
Server error
{
  "ok": false,
  "statusCode": 500,
  "mensaje": "Error al leer el producto.",
  "detalles": "Error message"
}

Update Product

Authentication

Required: JWT token via cookie
Role: Any authenticated user

Path Parameters

id
number
required
Product ID

Request Body

nombre
string
required
Product name
precio
number
required
Product price
stock
number
required
Stock quantity
descripcion
string
required
Product description
categoria_id
number
required
Category ID

Response

ok
boolean
Success indicator
statusCode
number
HTTP status code (200)
mensaje
string
“Producto actualizado exitosamente.”
data
null
No data returned

Example Request

curl -X PUT http://localhost:3000/api-productos/productos/1 \
  -H "Content-Type: application/json" \
  -b cookies.txt \
  -d '{
    "nombre": "Laptop Dell XPS 15 (Updated)",
    "precio": 1199.99,
    "stock": 20,
    "descripcion": "High-performance laptop - Price reduced!",
    "categoria_id": 1
  }'

Example Response

{
  "ok": true,
  "statusCode": 200,
  "mensaje": "Producto actualizado exitosamente.",
  "data": null
}

Error Responses

400 Bad Request
Product not found
{
  "ok": false,
  "statusCode": 400,
  "mensaje": "Producto no encontrado.",
  "detalles": null
}
401 Unauthorized
Missing or invalid authentication token
500 Internal Server Error
Server error
{
  "ok": false,
  "statusCode": 500,
  "mensaje": "Error al actualizar el producto.",
  "detalles": "Error message"
}

Delete Product

Authentication

Required: JWT token via cookie
Role: Any authenticated user

Path Parameters

id
number
required
Product ID

Response

ok
boolean
Success indicator
statusCode
number
HTTP status code (200)
mensaje
string
“Producto eliminado exitosamente.”
data
null
No data returned

Example Request

curl -X DELETE http://localhost:3000/api-productos/productos/1 \
  -b cookies.txt

Example Response

{
  "ok": true,
  "statusCode": 200,
  "mensaje": "Producto eliminado exitosamente.",
  "data": null
}

Error Responses

400 Bad Request
Product not found
{
  "ok": false,
  "statusCode": 400,
  "mensaje": "Producto no encontrado.",
  "detalles": null
}
401 Unauthorized
Missing or invalid authentication token
500 Internal Server Error
Server error
{
  "ok": false,
  "statusCode": 500,
  "mensaje": "Error al eliminar el producto.",
  "detalles": "Error message"
}

Notes

  • All timestamps are automatically managed by the database
  • The creado field is set to CURRENT_TIMESTAMP on creation
  • The actualizado field is updated to CURRENT_TIMESTAMP on every update
  • Product data is retrieved from the ProductosView database view which includes category information
  • Category ID must reference an existing category in the Categorias table

Build docs developers (and LLMs) love