Overview
The Tandex Electronics API integrates with WooCommerce to automatically publish products from your internal catalog to your WooCommerce store. This integration uses the official WooCommerce REST API client.WooCommerce API Configuration
The WooCommerce REST API is configured in the application using consumer keys and secrets:cliente.js
Setting Up Consumer Keys
Access WooCommerce Settings
Log in to your WordPress admin panel and navigate to:WooCommerce → Settings → Advanced → REST API
Create API Keys
- Click “Add key”
- Enter a description (e.g., “Tandex API Integration”)
- Select the user for the API
- Set permissions to Read/Write
- Click “Generate API key”
Copy Credentials
Save both the Consumer Key and Consumer Secret immediately. You won’t be able to view the secret again.
The Consumer Key starts with
ck_ and the Consumer Secret starts with cs_Product Publishing Workflow
TheuploadProducts function handles the complete workflow of publishing products to WooCommerce:
cliente.js
Workflow Steps
- Validation: Checks if products are selected
- Data Mapping: Transforms internal product data to WooCommerce format
- API Request: Posts product to WooCommerce using REST API
- Tracking: Records published product in
productos_publicadostable - Logging: Creates audit log entry in
bitacoratable
Product Data Mapping
The product data structure sent to WooCommerce:Field Mapping
Product Name (name)
Product Name (name)
Mapped from
descripcionP field in the internal database. This becomes the main product title in WooCommerce.Product Type (type)
Product Type (type)
Specifies the WooCommerce product type. Common values:
simple- Standard productvariable- Product with variationsgrouped- Collection of productsexternal- External/affiliate product
Descriptions
Descriptions
- description: Full HTML description displayed on product page
- short_description: Brief description shown on product listings
Regular Price (regular_price)
Regular Price (regular_price)
Must be sent as a string. Automatically converted from the numeric
precio field.WooCommerce expects price as string to handle decimal precision correctly.
Categories
Categories
Products are assigned to categories using category ID and name. The slug is currently set to “desconocido” (unknown).
Update the category ID (123) to match your actual WooCommerce category IDs.
Images
Images
Array of image objects with
src URLs. Currently uses placeholder images.Product Tracking
After successful publication, products are tracked in the database:- Product key (
claveProductoP) - Platform identifier (
woocomerce= “WOO”) - User who published (
idUsuarioPP)
Activity Logging
All publication activities are logged to the audit trail:Error Handling
The integration includes error handling for API failures:Common Errors
401 Unauthorized
401 Unauthorized
400 Bad Request
400 Bad Request
Cause: Invalid product data formatSolution:
- Ensure
regular_priceis a string - Verify category IDs exist in WooCommerce
- Check all required fields are present
404 Not Found
404 Not Found
Cause: Incorrect API endpoint URLSolution: Verify the store URL is correct and includes the trailing slash.
SSL Certificate Errors
SSL Certificate Errors
Cause: SSL certificate issues with the WooCommerce storeSolution: Ensure your store has a valid SSL certificate. For development, you may need to configure SSL verification.
Testing the Integration
Prepare test product data
Create a test product in your database with all required WooCommerce fields:
Verify in WooCommerce
- Log in to your WordPress admin
- Navigate to Products → All Products
- Look for your test product
- Verify all fields were populated correctly
Best Practices
- Batch Publishing: Publish products in reasonable batch sizes (50-100 at a time)
- Image Management: Store product images on a CDN and reference their URLs
- Category Mapping: Maintain a mapping table between internal categories and WooCommerce category IDs
- Error Logging: Implement comprehensive error logging for failed publications
- Rate Limiting: Be mindful of WooCommerce API rate limits (typically 60 requests per minute)
- Data Validation: Validate product data before sending to WooCommerce
API Version
The integration uses WooCommerce REST API v3 (wc/v3), which is compatible with:
- WooCommerce 3.5+
- WordPress 4.4+
Always keep your WooCommerce and WordPress installations up to date for security and compatibility.