Skip to main content

Endpoint

/database/bodega.php

Get All Warehouses

Retrieve a list of all warehouses ordered by ID (newest first).
curl -X GET https://your-domain.com/database/bodega.php

Response

{
  "success": true,
  "data": [
    {
      "id": 3,
      "nombre": "Almacén Central",
      "descripcion": "Bodega principal de distribución"
    },
    {
      "id": 2,
      "nombre": "Bodega Norte",
      "descripcion": "Sucursal zona norte"
    },
    {
      "id": 1,
      "nombre": "Bodega Sur",
      "descripcion": ""
    }
  ]
}

Response Fields

id
integer
Unique warehouse identifier
nombre
string
Warehouse name
descripcion
string
Warehouse description (can be empty)

Create Warehouse

Create a new warehouse location.
curl -X POST https://your-domain.com/database/bodega.php \
  -H "Content-Type: application/json" \
  -d '{
    "nombre": "Almacén Central",
    "descripcion": "Bodega principal de distribución"
  }'

Request Parameters

nombre
string
required
Warehouse name (maximum 100 characters, must be unique)
descripcion
string
Optional warehouse description

Validation Rules

  • nombre: Required, maximum 100 characters, must be unique
  • descripcion: Optional, no length limit
  • Warehouse name uniqueness is checked before creation

Response

{
  "success": true,
  "id": 4,
  "message": "Bodega creada exitosamente"
}

Update Warehouse

Update an existing warehouse’s information.
curl -X PUT https://your-domain.com/database/bodega.php \
  -H "Content-Type: application/json" \
  -d '{
    "id": 4,
    "nombre": "Almacén Central Actualizado",
    "descripcion": "Nueva descripción"
  }'

Request Parameters

id
integer
required
Warehouse ID to update (must be greater than 0)
nombre
string
required
New warehouse name (maximum 100 characters)
descripcion
string
New warehouse description

Validation Rules

  • id: Required, must be greater than 0, warehouse must exist
  • nombre: Required, maximum 100 characters, must be unique (excluding current warehouse)
  • descripcion: Optional
  • Updates fecha_actualizacion timestamp automatically

Response

{
  "success": true,
  "message": "Bodega actualizada exitosamente"
}

Delete Warehouse

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

Request Parameters

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

Validation Rules

  • id: Required, must be greater than 0, warehouse must exist
  • Cannot delete if warehouse has associated products
  • Checks productos table for foreign key relationships

Response

{
  "success": true,
  "message": "Bodega eliminada exitosamente"
}
Deleting a warehouse is prevented if it has associated products. You must reassign or delete the products first.

Database Schema

The warehouses are stored in the bodegas table:
CREATE TABLE bodegas (
  id INT AUTO_INCREMENT PRIMARY KEY,
  nombre VARCHAR(100) NOT NULL UNIQUE,
  descripcion TEXT,
  fecha_creacion DATETIME,
  fecha_actualizacion DATETIME
);

Error Codes

Error MessageCauseSolution
Datos inválidosInvalid JSON in request bodyCheck JSON syntax
El nombre es obligatorioMissing nombre fieldInclude nombre in request
El nombre no puede superar 100 caracteresName too longShorten the warehouse name
Ya existe una bodega con este nombreDuplicate nameUse a different warehouse name
ID inválidoInvalid or missing IDProvide valid ID > 0
Bodega no encontradaWarehouse doesn’t existCheck warehouse ID
No se puede eliminar. Tiene X producto(s) asociado(s)Foreign key constraintRemove products first

Build docs developers (and LLMs) love