Skip to main content

Endpoint

/database/proveedores.php

Get All Suppliers

Retrieve all suppliers with their status information.
curl -X GET https://your-domain.com/database/proveedores.php

Response

{
  "success": true,
  "data": [
    {
      "id": 3,
      "nif": "B12345678",
      "nombre": "Distribuidora Tech SA",
      "contacto": "Juan Pérez",
      "email": "[email protected]",
      "telefono": "+34 900 123 456",
      "direccion": "Calle Principal 123",
      "ciudad": "Madrid",
      "web": "https://disttech.com",
      "terminos": 30,
      "parametro_id": 5,
      "estado_nombre": "Activo",
      "estado_color": "#4a90e2",
      "productos_count": 0
    },
    {
      "id": 2,
      "nif": "A98765432",
      "nombre": "Suministros Globales",
      "contacto": "María García",
      "email": "[email protected]",
      "telefono": "+34 910 987 654",
      "direccion": "Avenida Industrial 45",
      "ciudad": "Barcelona",
      "web": "",
      "terminos": 60,
      "parametro_id": 5,
      "estado_nombre": "Activo",
      "estado_color": "#4a90e2",
      "productos_count": 0
    }
  ]
}

Response Fields

id
integer
Unique supplier identifier
nif
string
Tax identification number
nombre
string
Supplier company name (required)
contacto
string
Contact person name
email
string
Contact email address
telefono
string
Contact phone number
direccion
string
Physical address
ciudad
string
City location
web
string
Website URL
terminos
integer
Payment terms in days (e.g., 30, 60, 90)
parametro_id
integer
Status parameter ID (links to parametros table)
estado_nombre
string
Status name from parametros table
estado_color
string
Status color from parametros table
productos_count
integer
Number of associated products (always 0 in current implementation)

Create Supplier

Create a new supplier record.
curl -X POST https://your-domain.com/database/proveedores.php \
  -H "Content-Type: application/json" \
  -d '{
    "nif": "B12345678",
    "nombre": "Distribuidora Tech SA",
    "contacto": "Juan Pérez",
    "email": "[email protected]",
    "telefono": "+34 900 123 456",
    "direccion": "Calle Principal 123",
    "ciudad": "Madrid",
    "web": "https://disttech.com",
    "terminos": 30,
    "parametro_id": 5
  }'

Request Parameters

nombre
string
required
Supplier company name (required field)
nif
string
Tax identification number
contacto
string
Contact person name
email
string
Contact email address
telefono
string
Contact phone number
direccion
string
Physical address
ciudad
string
City location
web
string
Website URL
terminos
integer
Payment terms in days (can be null)
parametro_id
integer
Status parameter ID (can be null)

Validation Rules

  • nombre: Required, cannot be empty after trimming
  • All other fields are optional
  • terminos and parametro_id accept null values
  • All string fields are trimmed and SQL-escaped

Response

{
  "success": true,
  "id": 4,
  "message": "Proveedor creado"
}

Update Supplier

Update an existing supplier’s information.
curl -X PUT https://your-domain.com/database/proveedores.php \
  -H "Content-Type: application/json" \
  -d '{
    "id": 4,
    "nif": "B12345678",
    "nombre": "Distribuidora Tech SA - Actualizado",
    "contacto": "Juan Pérez González",
    "email": "[email protected]",
    "telefono": "+34 900 123 456",
    "direccion": "Calle Principal 123, Oficina 5",
    "ciudad": "Madrid",
    "web": "https://disttech.com",
    "terminos": 45,
    "parametro_id": 5
  }'

Request Parameters

id
integer
required
Supplier ID to update (must be greater than 0)
nombre
string
required
Supplier company name
nif
string
Tax identification number
contacto
string
Contact person name
email
string
Contact email address
telefono
string
Contact phone number
direccion
string
Physical address
ciudad
string
City location
web
string
Website URL
terminos
integer
Payment terms in days
parametro_id
integer
Status parameter ID

Validation Rules

  • id: Required, must be greater than 0
  • nombre: Required, cannot be empty
  • Updates fecha_actualizacion timestamp automatically
  • No existence check is performed before update

Response

{
  "success": true,
  "message": "Proveedor actualizado"
}

Delete Supplier

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

Request Parameters

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

Validation Rules

  • id: Required, must be greater than 0
  • No foreign key constraint check is performed
  • No existence check is performed before deletion

Response

{
  "success": true,
  "message": "Proveedor eliminado"
}
Unlike other endpoints, the suppliers delete operation does not check for associated products or verify existence before deletion.

Database Schema

Suppliers are stored in the proveedores table:
CREATE TABLE proveedores (
  id INT AUTO_INCREMENT PRIMARY KEY,
  nif VARCHAR(20),
  nombre VARCHAR(100) NOT NULL,
  contacto VARCHAR(100),
  email VARCHAR(100),
  telefono VARCHAR(20),
  direccion VARCHAR(200),
  ciudad VARCHAR(50),
  web VARCHAR(200),
  terminos INT,
  parametro_id INT,
  fecha_creacion DATETIME,
  fecha_actualizacion DATETIME,
  FOREIGN KEY (parametro_id) REFERENCES parametros(id)
);

Status Integration

Suppliers can have status managed through the parametros system:
1

Create Status Parameter

First, create a status parameter using the Parameters API:
{
  "nombre": "Activo",
  "color": "#4a90e2"
}
2

Assign to Supplier

Use the returned id as parametro_id when creating or updating suppliers
3

Status Display

The GET endpoint joins with parametros table to return estado_nombre and estado_color

Error Codes

Error MessageCauseSolution
Datos inválidosInvalid JSONCheck JSON syntax
El nombre es obligatorioMissing nombreInclude nombre in request
ID inválidoInvalid IDProvide valid ID > 0
Error al crear: [details]Database errorCheck database logs
Error al actualizar: [details]Database errorCheck database logs
Error al eliminar: [details]Database errorCheck database logs

Build docs developers (and LLMs) love