Endpoint
Get All Subcategories
Retrieve all subcategories or filter by category.Get All Subcategories
Get Subcategories by Category
Query Parameters
Filter subcategories by parent category ID
Response
Response Fields
Unique subcategory identifier
Parent category ID
Subcategory name (max 50 characters)
Subcategory description (max 200 characters)
Hex color code for UI display
Subcategory status
Creation timestamp
Last update timestamp (null if never updated)
Create Subcategory
Create a new subcategory within a category.Request Parameters
Parent category ID (must be greater than 0 and exist)
Subcategory name (max 50 characters, unique within category)
Subcategory description (max 200 characters)
Hex color code for UI display
Subcategory status
Validation Rules
- categoria_id: Required, must be greater than 0, category must exist
- nombre: Required, max 50 characters, unique within the same category
- descripcion: Optional, max 200 characters
- color: Optional, defaults to
#2e6df6 - estado: Optional, defaults to
ACTIVO
Response
Subcategory names must be unique within the same category. You can have the same subcategory name in different categories.
Update Subcategory
Update an existing subcategory’s information.Request Parameters
Subcategory ID to update (must be greater than 0)
New subcategory name (max 50 characters)
New description (max 200 characters)
New color code
New status
Validation Rules
- id: Required, must be greater than 0, subcategory must exist
- nombre: Required, max 50 characters, unique within category (excluding current)
- descripcion: Optional, max 200 characters
- Cannot change
categoria_id(parent category) - Updates
fecha_actualizaciontimestamp automatically
Response
Delete Subcategory
Delete a subcategory from the system.Request Parameters
Subcategory ID to delete (must be greater than 0)
Validation Rules
- id: Required, must be greater than 0, subcategory must exist
- Cannot delete if subcategory has associated products
- Checks
productostable forsubcategoria_idforeign key
Response
Database Schema
Subcategories are stored in thesubcategorias table:
Error Codes
| Error Message | Cause | Solution |
|---|---|---|
Datos inválidos | Invalid JSON | Check JSON syntax |
Categoría inválida | Invalid categoria_id | Provide valid category ID |
Categoría no encontrada | Category doesn’t exist | Check category exists |
El nombre es obligatorio | Missing nombre | Include nombre in request |
El nombre no puede superar 50 caracteres | Name too long | Shorten subcategory name |
La descripción no puede superar 200 caracteres | Description too long | Shorten description |
Ya existe una subcategoría con este nombre en esta categoría | Duplicate within category | Use different name or different category |
ID inválido | Invalid ID | Provide valid ID > 0 |
Subcategoría no encontrada | Subcategory doesn’t exist | Check subcategory ID |
No se puede eliminar. Tiene X producto(s) asociado(s) | Has products | Remove products first |