Skip to main content
POST
/
secured
/
post_products
curl --location 'http://localhost:8080/secured/post_products' \
--header 'Authorization: Bearer YOUR_JWT_TOKEN' \
--header 'user: [email protected]' \
--header 'Content-Type: application/json' \
--data '[
  {
    "claveProducto": "PROD001",
    "descripcionP": "High-quality electronic component",
    "typeWOO": "simple",
    "descriptionWoo": "Full detailed description of the product features and specifications",
    "shortDescriptionWOO": "Compact design, High durability, Easy installation",
    "precio": 150.50,
    "categoryWOO": "Electronics"
  },
  {
    "claveProducto": "PROD002",
    "descripcionP": "Premium accessory",
    "typeWOO": "simple",
    "descriptionWoo": "Premium quality accessory item",
    "shortDescriptionWOO": "Premium materials, Long-lasting",
    "precio": 75.00,
    "categoryWOO": "Accessories"
  }
]'
{
  "msg": "Productos subidos correctamente"
}
This endpoint publishes products to a WooCommerce store, creates bitacora (audit log) entries, and tracks published products in the database.

Authentication

This endpoint requires authentication. Include a valid JWT token in the Authorization header (raw token, no “Bearer” prefix).
Authorization
string
required
JWT token for authentication (raw token without Bearer prefix)
user
string
required
User email address for audit logging

Request Body

The request body should be an array of product objects with the following WooCommerce fields:
claveProducto
string
required
Unique product key/identifier
descripcionP
string
required
Product name/description (used as WooCommerce product name)
typeWOO
string
required
WooCommerce product type (e.g., “simple”, “variable”, “grouped”)
descriptionWoo
string
Full product description for WooCommerce
shortDescriptionWOO
string
Short description/characteristics for WooCommerce
precio
number
required
Regular price (will be converted to string)
categoryWOO
string
Category name for WooCommerce

Response

msg
string
Success or error message
  • Success: “Productos subidos correctamente”
  • Error: “Productos no seleccionados” with “Reintente seleccionar archivos”
curl --location 'http://localhost:8080/secured/post_products' \
--header 'Authorization: Bearer YOUR_JWT_TOKEN' \
--header 'user: [email protected]' \
--header 'Content-Type: application/json' \
--data '[
  {
    "claveProducto": "PROD001",
    "descripcionP": "High-quality electronic component",
    "typeWOO": "simple",
    "descriptionWoo": "Full detailed description of the product features and specifications",
    "shortDescriptionWOO": "Compact design, High durability, Easy installation",
    "precio": 150.50,
    "categoryWOO": "Electronics"
  },
  {
    "claveProducto": "PROD002",
    "descripcionP": "Premium accessory",
    "typeWOO": "simple",
    "descriptionWoo": "Premium quality accessory item",
    "shortDescriptionWOO": "Premium materials, Long-lasting",
    "precio": 75.00,
    "categoryWOO": "Accessories"
  }
]'
{
  "msg": "Productos subidos correctamente"
}

Error Codes

200
success
Products published to WooCommerce successfully
400
error
Bad Request - WooCommerce API error or empty product array
401
error
Unauthorized - Invalid or missing authentication token

Implementation Notes

WooCommerce Integration

  • Connects to WooCommerce REST API v3 (configured at line 14 in cliente.js:14)
  • Uses WooCommerce credentials for store at https://hometoys.com.mx/pruebas2021/
  • Posts products to the /products endpoint (line 153)

Product Data Transformation

  • shortDescriptionWOO is formatted as HTML list: <p>CARACTERÍSTICAS</p>\n<ul>\n<li>{value}</li>\n</ul>\n (line 126)
  • Price is converted to string with .toString() (line 127)
  • Category ID is hardcoded to 123 (line 130)
  • Category slug is set to “desconocido” (line 132)
  • Default placeholder images are included (lines 135-148)

Audit Trail

  • Creates entries in productos_publicados table with user ID (line 183)
  • Creates bitacora (audit log) entry with user, date, and product count (line 174)
  • User is identified by email from the user header (line 113)

Processing

  • Products are processed sequentially in a loop (line 121)
  • All products receive success response after loop completes (line 161)
  • Individual WooCommerce API errors are caught but don’t stop processing

Important Warnings

The category ID is hardcoded to 123. Ensure this category exists in your WooCommerce store.
Product images use placeholder URLs. You’ll need to update these with actual product images.

Build docs developers (and LLMs) love