Skip to main content

List All Products

Response

products
array
Array of product objects

Example Request

curl -X GET https://api.example.com/producto \
  -H "Content-Type: application/json"

Example Response

[
  {
    "id": 1,
    "codigo": "PROD001",
    "nombre": "Wireless Mouse",
    "descripcion": "Ergonomic wireless mouse with USB receiver",
    "cantidad": 50,
    "precioVenta": 29.99,
    "costoCompra": 15.00,
    "estado": true,
    "fechaCreacion": "2026-03-06T10:00:00",
    "fechaActualizacion": "2026-03-06T10:00:00",
    "categoria": {
      "id": 1,
      "nombre": "Electronics"
    },
    "imagen": "/images/prod001.jpg"
  }
]

Get Product by ID

Path Parameters

id
long
required
The unique identifier of the product

Response

Returns a single product object with all fields.

Example Request

curl -X GET https://api.example.com/producto/1 \
  -H "Content-Type: application/json"

Example Response

{
  "id": 1,
  "codigo": "PROD001",
  "nombre": "Wireless Mouse",
  "descripcion": "Ergonomic wireless mouse with USB receiver",
  "cantidad": 50,
  "precioVenta": 29.99,
  "costoCompra": 15.00,
  "estado": true,
  "fechaCreacion": "2026-03-06T10:00:00",
  "fechaActualizacion": "2026-03-06T10:00:00",
  "categoria": {
    "id": 1,
    "nombre": "Electronics"
  },
  "imagen": "/images/prod001.jpg"
}

Error Responses

  • 404 Not Found: Product with the specified ID does not exist

Search Product by Code

Path Parameters

codigo
string
required
The unique product code to search for

Response

Returns a single product object matching the code.

Example Request

curl -X GET https://api.example.com/producto/buscar/codigo/PROD001 \
  -H "Content-Type: application/json"

Example Response

{
  "id": 1,
  "codigo": "PROD001",
  "nombre": "Wireless Mouse",
  "descripcion": "Ergonomic wireless mouse with USB receiver",
  "cantidad": 50,
  "precioVenta": 29.99,
  "costoCompra": 15.00,
  "estado": true,
  "fechaCreacion": "2026-03-06T10:00:00",
  "fechaActualizacion": "2026-03-06T10:00:00",
  "categoria": {
    "id": 1,
    "nombre": "Electronics"
  },
  "imagen": "/images/prod001.jpg"
}

Error Responses

  • 404 Not Found: No product found with the specified code

Create Product with Image

Request Headers

Content-Type: multipart/form-data

Form Data Parameters

codigo
string
required
Unique product code
nombre
string
required
Product name (must be unique)
descripcion
string
Product description (optional)
cantidad
integer
required
Available quantity in stock
precioVenta
double
required
Sale price
costoCompra
double
required
Purchase cost
categoriaId
long
required
ID of the category this product belongs to
imagen
file
Product image file (optional)

Response

Returns the created product object with auto-generated fields.

Example Request

curl -X POST https://api.example.com/producto/crear-con-imagen \
  -H "Content-Type: multipart/form-data" \
  -F "codigo=PROD002" \
  -F "nombre=Mechanical Keyboard" \
  -F "descripcion=RGB mechanical keyboard with blue switches" \
  -F "cantidad=30" \
  -F "precioVenta=89.99" \
  -F "costoCompra=45.00" \
  -F "categoriaId=1" \
  -F "[email protected]"

Example Response

{
  "id": 2,
  "codigo": "PROD002",
  "nombre": "Mechanical Keyboard",
  "descripcion": "RGB mechanical keyboard with blue switches",
  "cantidad": 30,
  "precioVenta": 89.99,
  "costoCompra": 45.00,
  "estado": true,
  "fechaCreacion": "2026-03-06T16:00:00",
  "fechaActualizacion": "2026-03-06T16:00:00",
  "categoria": {
    "id": 1,
    "nombre": "Electronics"
  },
  "imagen": "/images/uuid-keyboard.jpg"
}

Error Responses

  • 500 Internal Server Error: Error processing the request or saving the image

Update Product

Path Parameters

id
long
required
The unique identifier of the product to update

Request Body

codigo
string
Updated product code
nombre
string
Updated product name
descripcion
string
Updated product description
cantidad
integer
Updated quantity
precioVenta
double
Updated sale price
costoCompra
double
Updated purchase cost
estado
boolean
Updated product status
categoria
object
Updated category object with id

Response

Returns the updated product object.

Example Request

curl -X PUT https://api.example.com/producto/2 \
  -H "Content-Type: application/json" \
  -d '{
    "codigo": "PROD002",
    "nombre": "Mechanical Keyboard RGB",
    "descripcion": "Premium RGB mechanical keyboard",
    "cantidad": 25,
    "precioVenta": 99.99,
    "costoCompra": 45.00,
    "estado": true,
    "categoria": {
      "id": 1
    }
  }'

Example Response

{
  "id": 2,
  "codigo": "PROD002",
  "nombre": "Mechanical Keyboard RGB",
  "descripcion": "Premium RGB mechanical keyboard",
  "cantidad": 25,
  "precioVenta": 99.99,
  "costoCompra": 45.00,
  "estado": true,
  "fechaCreacion": "2026-03-06T16:00:00",
  "fechaActualizacion": "2026-03-06T17:30:00",
  "categoria": {
    "id": 1,
    "nombre": "Electronics"
  },
  "imagen": "/images/uuid-keyboard.jpg"
}

Error Responses

  • 404 Not Found: Product with the specified ID does not exist

Update Product with Image

Path Parameters

id
long
required
The unique identifier of the product to update

Request Headers

Content-Type: multipart/form-data

Form Data Parameters

codigo
string
required
Updated product code
nombre
string
required
Updated product name
descripcion
string
Updated product description (optional)
cantidad
integer
required
Updated quantity
precioVenta
double
required
Updated sale price
costoCompra
double
required
Updated purchase cost
estado
boolean
required
Updated product status
categoriaId
long
required
Updated category ID
imagen
file
New product image file (optional - if not provided, keeps existing image)

Response

Returns the updated product object with the new image path.

Example Request

curl -X PUT https://api.example.com/producto/2/actualizar-con-imagen \
  -H "Content-Type: multipart/form-data" \
  -F "codigo=PROD002" \
  -F "nombre=Premium Mechanical Keyboard" \
  -F "descripcion=Premium RGB mechanical keyboard with wrist rest" \
  -F "cantidad=20" \
  -F "precioVenta=119.99" \
  -F "costoCompra=50.00" \
  -F "estado=true" \
  -F "categoriaId=1" \
  -F "[email protected]"

Example Response

{
  "id": 2,
  "codigo": "PROD002",
  "nombre": "Premium Mechanical Keyboard",
  "descripcion": "Premium RGB mechanical keyboard with wrist rest",
  "cantidad": 20,
  "precioVenta": 119.99,
  "costoCompra": 50.00,
  "estado": true,
  "fechaCreacion": "2026-03-06T16:00:00",
  "fechaActualizacion": "2026-03-06T18:00:00",
  "categoria": {
    "id": 1,
    "nombre": "Electronics"
  },
  "imagen": "/images/new-uuid-keyboard.jpg"
}

Error Responses

  • 500 Internal Server Error: Error processing the request or saving the image

Update Product Quantity

Path Parameters

id
long
required
The unique identifier of the product

Request Body

nuevaCantidad
integer
required
The new quantity value

Response

Returns the updated product object.

Example Request

curl -X PUT https://api.example.com/producto/2/cantidad \
  -H "Content-Type: application/json" \
  -d '15'

Example Response

{
  "id": 2,
  "codigo": "PROD002",
  "nombre": "Premium Mechanical Keyboard",
  "descripcion": "Premium RGB mechanical keyboard with wrist rest",
  "cantidad": 15,
  "precioVenta": 119.99,
  "costoCompra": 50.00,
  "estado": true,
  "fechaCreacion": "2026-03-06T16:00:00",
  "fechaActualizacion": "2026-03-06T19:00:00",
  "categoria": {
    "id": 1,
    "nombre": "Electronics"
  },
  "imagen": "/images/new-uuid-keyboard.jpg"
}

Deactivate Product

Path Parameters

id
long
required
The unique identifier of the product to deactivate

Response

Returns a 200 OK status on success.

Example Request

curl -X PUT https://api.example.com/producto/2/desactivar \
  -H "Content-Type: application/json"

Response

200 OK

Error Responses

  • 404 Not Found: Product with the specified ID does not exist

Delete Product

Path Parameters

id
long
required
The unique identifier of the product to delete

Response

Returns a 204 No Content status on success.

Example Request

curl -X DELETE https://api.example.com/producto/2 \
  -H "Content-Type: application/json"

Response

204 No Content
This is a permanent deletion. Consider using the deactivate endpoint for soft deletes instead.

Image Handling

The catalog service supports image uploads for products through multipart/form-data requests.

Image Upload Details

  • Images are uploaded as multipart/form-data files
  • The service generates unique filenames using UUIDs to prevent conflicts
  • Images are stored in the server’s file system
  • The imagen field in the response contains the path/URL to the stored image
  • When updating a product with a new image, the old image is replaced

Supported Endpoints

  • POST /producto/crear-con-imagen - Create product with image
  • PUT /producto/{id}/actualizar-con-imagen - Update product with new image

Best Practices

  • Always use the imagen parameter name for file uploads
  • Image upload is optional - you can create/update products without images
  • Supported image formats typically include JPG, PNG, and other common formats
  • Consider implementing image size and format validation on the client side

Build docs developers (and LLMs) love