Skip to main content

Endpoint

/database/parametros.php

Overview

Parameters are reusable status configurations that can be assigned to products, suppliers, and other entities. Each parameter has a code, name, description, and color for UI display.

Get All Parameters

Retrieve all parameters with product counts.
curl -X GET https://your-domain.com/database/parametros.php

Response

{
  "success": true,
  "data": [
    {
      "id": 1,
      "codigo": "001",
      "nombre": "Activo",
      "descripcion": "Productos en stock disponibles para venta",
      "color": "#4a90e2",
      "productos_count": 45
    },
    {
      "id": 2,
      "codigo": "002",
      "nombre": "Agotado",
      "descripcion": "Productos sin stock",
      "color": "#e74c3c",
      "productos_count": 12
    },
    {
      "id": 3,
      "codigo": "003",
      "nombre": "Descontinuado",
      "descripcion": "Productos que ya no se fabrican",
      "color": "#95a5a6",
      "productos_count": 8
    }
  ]
}

Response Fields

id
integer
Unique parameter identifier
codigo
string
Parameter code (auto-generated if not provided)
nombre
string
Parameter name (max 50 characters, unique)
descripcion
string
Parameter description
color
string
Hex color code in format #RRGGBB
productos_count
integer
Number of products using this parameter

Create Parameter

Create a new parameter configuration.
curl -X POST https://your-domain.com/database/parametros.php \
  -H "Content-Type: application/json" \
  -d '{
    "codigo": "004",
    "nombre": "En Revisión",
    "descripcion": "Productos pendientes de revisión de calidad",
    "color": "#f39c12"
  }'

Request Parameters

nombre
string
required
Parameter name (max 50 characters, must be unique)
codigo
string
Parameter code (auto-generated if empty, must be unique)
descripcion
string
Parameter description
color
string
default:"#4a90e2"
Hex color code (must match format #RRGGBB)

Validation Rules

  • nombre: Required, max 50 characters, must be unique
  • codigo: Optional, auto-generated as 3-digit padded number if empty (e.g., “001”, “002”)
    • If provided, must be unique
  • color: Optional, defaults to #4a90e2
    • Must match regex pattern: ^#[0-9A-Fa-f]{6}$
    • Format: # followed by exactly 6 hexadecimal characters
  • descripcion: Optional, no length limit

Auto-Generated Codes

Response

{
  "success": true,
  "id": 4,
  "message": "Parámetro creado"
}

Update Parameter

Update an existing parameter’s information.
curl -X PUT https://your-domain.com/database/parametros.php \
  -H "Content-Type: application/json" \
  -d '{
    "id": 4,
    "nombre": "En Revisión Actualizado",
    "descripcion": "Productos en proceso de control de calidad",
    "color": "#e67e22"
  }'

Request Parameters

id
integer
required
Parameter ID to update (must be greater than 0)
nombre
string
required
New parameter name (max 50 characters)
descripcion
string
New parameter description
color
string
default:"#4a90e2"
New hex color code (must match format #RRGGBB)

Validation Rules

  • id: Required, must be greater than 0, parameter must exist
  • nombre: Required, max 50 characters, must be unique (excluding current parameter)
  • color: Must match regex pattern ^#[0-9A-Fa-f]{6}$
  • codigo: Cannot be updated (read-only after creation)
  • Updates fecha_actualizacion timestamp automatically

Response

{
  "success": true,
  "message": "Parámetro actualizado"
}
The codigo field is immutable and cannot be changed after creation. Only nombre, descripcion, and color can be updated.

Delete Parameter

Delete a parameter from the system.
curl -X DELETE https://your-domain.com/database/parametros.php \
  -H "Content-Type: application/json" \
  -d '{"id": 4}'

Request Parameters

id
integer
required
Parameter ID to delete (must be greater than 0)

Validation Rules

  • id: Required, must be greater than 0
  • Cannot delete if parameter has associated products
  • Checks productos table for parametro_id foreign key references

Response

{
  "success": true,
  "message": "Parámetro eliminado"
}
Deleting a parameter is prevented if it has associated products. You must reassign or delete the products first.

Database Schema

Parameters are stored in the parametros table:
CREATE TABLE parametros (
  id INT AUTO_INCREMENT PRIMARY KEY,
  codigo VARCHAR(10) NOT NULL UNIQUE,
  nombre VARCHAR(50) NOT NULL UNIQUE,
  descripcion TEXT,
  color VARCHAR(7) DEFAULT '#4a90e2',
  fecha_creacion DATETIME,
  fecha_actualizacion DATETIME
);

Usage Examples

Product Status Management

1

Create Status Parameters

Create parameters for different product statuses:
# Create "Active" status
curl -X POST .../parametros.php -d '{
  "nombre": "Activo",
  "color": "#4a90e2"
}'

# Create "Out of Stock" status
curl -X POST .../parametros.php -d '{
  "nombre": "Agotado",
  "color": "#e74c3c"
}'
2

Assign to Products

Use the parameter id when creating or updating products
3

Monitor Usage

Use GET endpoint to see productos_count for each parameter

Color Validation

Valid color formats:
#4a90e2  ✓ (lowercase)
#E74C3C  ✓ (uppercase)
#95A5a6  ✓ (mixed case)
#000000  ✓ (black)
#FFFFFF  ✓ (white)

Error Codes

Error MessageCauseSolution
Datos inválidosInvalid JSONCheck JSON syntax
El nombre es obligatorioMissing nombreInclude nombre in request
Longitud de nombre inválidaName exceeds 50 charsShorten parameter name
Color inválido. Use formato #RRGGBBInvalid color formatUse hex format like #4a90e2
Código o nombre ya existeDuplicate codigo or nombreUse unique values
ID y nombre son obligatoriosMissing id or nombre in PUTInclude both fields
No encontradoParameter doesn’t existCheck parameter ID
ID inválidoInvalid IDProvide valid ID > 0
No se puede eliminar: tiene productos asociadosHas product referencesReassign products first

Build docs developers (and LLMs) love