Skip to main content

Get All Products

curl -X GET "https://api.miscompras.com/api/productos"
Retrieve all products from the marketplace.

Response

Returns an array of product objects.
products
array
Array of product objects
[
  {
    "id_producto": 1,
    "nombre": "iPhone 15 Pro",
    "descripcion": "Latest Apple smartphone with A17 Pro chip",
    "precio": 999.99,
    "imagen": "1704123456_abc123def456.jpg",
    "id_vendedor": 5,
    "id_categoria": 1,
    "stock": 10
  },
  {
    "id_producto": 2,
    "nombre": "Samsung Galaxy S24",
    "descripcion": "Premium Android smartphone",
    "precio": 849.99,
    "imagen": "1704123789_def789ghi012.jpg",
    "id_vendedor": 3,
    "id_categoria": 1,
    "stock": 15
  }
]

Get Product by ID

curl -X GET "https://api.miscompras.com/php/obtener_producto.php?id=1"
Retrieve detailed information about a specific product.

Query Parameters

id
integer
required
The unique identifier of the product

Response

exito
boolean
Indicates whether the product was found
producto
object
Product information (only present when found)
{
  "exito": true,
  "producto": {
    "id_producto": 1,
    "nombre": "iPhone 15 Pro",
    "precio": 999.99,
    "descripcion": "Latest Apple smartphone with A17 Pro chip",
    "imagen": "1704123456_abc123def456.jpg"
  }
}

Search Products

curl -X GET "https://api.miscompras.com/php/buscar_productos.php?q=iphone"
Search for products by name, description, or price.

Query Parameters

q
string
required
Search term to match against product name, description, or price

Response

exito
boolean
Indicates whether the search was successful
productos
array
Array of matching products
{
  "exito": true,
  "productos": [
    {
      "id_producto": 1,
      "nombre": "iPhone 15 Pro",
      "precio": 999.99,
      "imagen": "1704123456_abc123def456.jpg"
    },
    {
      "id_producto": 5,
      "nombre": "iPhone 14",
      "precio": 799.99,
      "imagen": "1704123999_xyz789abc123.jpg"
    }
  ]
}
The search uses SQL LIKE matching and searches across product name, description, and price fields.

Get Products by Category

curl -X GET "https://api.miscompras.com/php/obtener_productos_por_categoria.php"
Retrieve all products grouped by category.

Response

exito
boolean
Indicates success
categorias
array
Array of category groups
{
  "exito": true,
  "categorias": [
    {
      "categoria": "Electrónicos",
      "productos": [
        {
          "id_producto": 1,
          "nombre": "iPhone 15 Pro",
          "descripcion": "Latest Apple smartphone",
          "precio": 999.99,
          "imagen": "1704123456_abc123def456.jpg",
          "id_vendedor": 5,
          "vendedor": "TechStore"
        }
      ]
    },
    {
      "categoria": "Hogar",
      "productos": [
        {
          "id_producto": 10,
          "nombre": "Aspiradora Robot",
          "descripcion": "Robot vacuum cleaner",
          "precio": 299.99,
          "imagen": "1704124000_robot123.jpg",
          "id_vendedor": 8,
          "vendedor": "HomeGoods"
        }
      ]
    }
  ]
}

Get Categories

curl -X GET "https://api.miscompras.com/php/obtener_categorias.php"
Retrieve all available product categories.

Response

exito
boolean
Indicates success
categorias
array
Array of category objects
{
  "exito": true,
  "categorias": [
    {
      "id_categoria": 1,
      "nombre": "Electrónicos"
    },
    {
      "id_categoria": 2,
      "nombre": "Hogar"
    },
    {
      "id_categoria": 3,
      "nombre": "Deportes"
    }
  ]
}

Create Product

curl -X POST https://api.miscompras.com/php/vender.php \
  -H "Content-Type: multipart/form-data" \
  -F "nombre=Laptop HP Pavilion" \
  -F "descripcion=15.6 inch, 16GB RAM, 512GB SSD" \
  -F "precio=799.99" \
  -F "categoria=1" \
  -F "id_vendedor=5" \
  -F "imagen=@laptop.jpg"
Create a new product listing. Requires an active session or seller ID.

Request Parameters

nombre
string
required
Product name
descripcion
string
required
Product description
precio
decimal
required
Product price
categoria
integer
Category ID (optional, can be null)
imagen
file
required
Product image file (uploaded as multipart/form-data)
id_vendedor
integer
Seller’s user ID (can be obtained from session)

Response

success
boolean
Indicates success
exito
boolean
Alternative success indicator
message
string
Result message
mensaje
string
Alternative result message
{
  "success": true,
  "exito": true,
  "message": "✅ Producto publicado correctamente.",
  "mensaje": "Producto publicado correctamente."
}
The image is stored with a unique filename using timestamp and random bytes to prevent collisions.

Update Product

curl -X POST https://api.miscompras.com/php/actualizar_producto.php \
  -H "Content-Type: multipart/form-data" \
  -F "id_producto=1" \
  -F "nombre=iPhone 15 Pro Max" \
  -F "precio=1099.99" \
  -F "descripcion=Updated description" \
  -F "imagen=@new_image.jpg"
Update an existing product. Image upload is optional.

Request Parameters

id_producto
integer
required
ID of the product to update
nombre
string
required
Updated product name
precio
decimal
required
Updated price
descripcion
string
required
Updated description
imagen
file
New product image (optional - if not provided, keeps existing image)

Response

exito
boolean
Indicates success
mensaje
string
Error message (only on failure)
{
  "exito": true
}

Delete Product

curl -X POST https://api.miscompras.com/php/eliminar_producto.php \
  -H "Content-Type: application/json" \
  -d '{"id_producto": 1}'
Delete a product from the marketplace.
This endpoint accepts the product ID via POST body (JSON), GET query parameter, or form data.

Request Parameters

id_producto
integer
required
ID of the product to delete

Response

exito
boolean
Indicates success
mensaje
string
Result message
{
  "exito": true,
  "mensaje": "Producto eliminado correctamente."
}
Deleting a product is permanent and cannot be undone. Ensure you have proper authorization checks in place.
curl -X GET "https://api.miscompras.com/php/obtener_destacados_por_categoria.php"
Retrieves the top 3 most recent products for each category.

Response

exito
boolean
Request success status
categorias
array
Array of category objects with featured products
{
  "exito": true,
  "categorias": [
    {
      "id_categoria": 2,
      "categoria": "Laptops",
      "productos": [
        {
          "id_producto": 2,
          "nombre": "MacBook Pro M3",
          "descripcion": "Chip M3, pantalla Retina, 16GB RAM, SSD 512GB",
          "precio": "1599.99",
          "imagen": "macbook.jpg",
          "id_vendedor": null,
          "vendedor": null,
          "fecha_publicacion": "2025-12-26 12:04:08"
        }
      ]
    },
    {
      "id_categoria": 3,
      "categoria": "Smartphones",
      "productos": [
        {
          "id_producto": 1,
          "nombre": "iPhone 15 Pro",
          "descripcion": "Chip A17 Pro, cámara de 48MP, titanio",
          "precio": "999.99",
          "imagen": "iphone15.jpg",
          "id_vendedor": null,
          "vendedor": null,
          "fecha_publicacion": "2025-12-26 12:04:08"
        }
      ]
    }
  ]
}
This endpoint is useful for homepage displays showing featured products from each category. Products are ordered by most recent publication date within each category.

Build docs developers (and LLMs) love