Skip to main content

Products Sync API

📦 Overview

The Products Sync API provides specialized endpoints for synchronizing product data between GeSmart ERP and PrestaShop. Unlike the general sync endpoints, these endpoints offer fine-grained control over product synchronization with support for extended fields including brands, images, and technical specifications.

Key Features

  • Single Product Sync: Synchronize individual products with complete control
  • Batch Synchronization: Efficiently sync multiple products in a single request
  • Extended Fields Support: Manage brands, multiple images, and technical data
  • Real-time Updates: Webhook integration for instant product updates from GeSmart
  • Comprehensive Status Tracking: Monitor synchronization progress and outcomes

Use Cases

  • Initial product catalog import from GeSmart ERP
  • Real-time product updates triggered by ERP changes
  • Bulk product data synchronization during migration
  • Individual product corrections and updates
  • Product deletion and inventory management

🔐 Authentication

All endpoints require JWT Bearer token authentication:

Authorization: Bearer YOUR_JWT_TOKEN

Obtain your JWT token from the /api/auth/login endpoint. See Authentication for details.


📥 Postman Collection

Test our API easily with our complete Postman collection containing all endpoints with pre-configured examples.

Download Collection

📥 Download Postman Collection

How to Import

  1. Open Postman
  2. Click Import in the top left
  3. Select the downloaded file
  4. Configure environment variables:
    • base_url: Your API URL (e.g., https://your-domain.com)
    • jwt_token: Your JWT authentication token

Required Environment Variables

VariableDescriptionExample
base_urlBase API URLhttps://your-domain.com
jwt_tokenJWT authentication tokenObtained from /api/auth/login

📍 API Endpoints

POST /api/products/sync

Synchronizes a single product from GeSmart ERP to PrestaShop with support for extended fields.

Headers

HeaderValueRequired
AuthorizationBearer {token}Yes
Content-Typeapplication/jsonYes

Request Body

FieldTypeRequiredDescriptionValidation
operationstringYesOperation type: create or updateMust be 'create' or 'update'
referencestringYesUnique product reference/SKUMax 64 characters
namestringYesProduct name1-255 characters
descriptionstringNoProduct descriptionMax 10000 characters
pricenumberYesProduct price (tax excluded)Must be >= 0
quantitynumberYesAvailable stock quantityMust be >= 0, integer
activebooleanNoProduct active statusDefault: true
categoriesarrayNoArray of category IDsEach ID must exist in PrestaShop
ean13stringNoEAN13 barcode13 characters or empty
weightnumberNoProduct weight in kgMust be >= 0
brandobjectNoBrand informationSee Brand structure
imagesarrayNoProduct imagesMax 10 images
technical_dataarrayNoTechnical specificationsMax 100 items

Success Response (200 OK)

{
"success": true,
"message": "Product synchronized successfully",
"data": {
"productId": 123,
"reference": "PROD001",
"presta_id": 456,
"syncId": "sync_abc123xyz",
"operation": "create",
"imagesProcessed": 3,
"technicalDataProcessed": 15
}
}

Code Examples

curl -X POST https://your-domain.com/api/products/sync \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"operation": "create",
"reference": "PROD001",
"name": "Professional Coffee Machine",
"description": "High-end espresso machine",
"price": 1299.99,
"quantity": 50,
"active": true,
"categories": [5, 12],
"brand": {
"name": "CoffeePro"
}
}'

📊 Data Models

Complete Product Object

interface Product {
// Required fields
operation: 'create' | 'update';
reference: string; // Max 64 chars
name: string; // 1-255 chars
price: number; // >= 0
quantity: number; // >= 0, integer

// Optional basic fields
description?: string; // Max 10000 chars
active?: boolean; // Default: true
categories?: number[]; // PrestaShop category IDs
ean13?: string; // 13 chars or empty
weight?: number; // >= 0, in kg

// Extended fields
brand?: Brand;
images?: Image[]; // Max 10 images
technical_data?: TechnicalData[]; // Max 100 items
}

Brand Model

interface Brand {
name: string; // Required
description?: string;
}

Image Model

interface Image {
fileName: string; // Required, valid extension
base64: string; // Required, max 10MB per image
}

Supported formats: jpg, jpeg, png, gif, webp

Technical Data Model

interface TechnicalData {
Gruppo: string; // Required - Group/Category
Descrizione: string; // Required - Description
Valore: string; // Required - Value
Suffisso?: string; // Optional - Unit suffix
PrintOrder?: number; // Optional - Display order (default: 0)
}

Limits: Maximum 100 technical data items per product


⚠️ Error Handling

HTTP Status Codes

CodeStatusDescription
200OKRequest successful
400Bad RequestInvalid request data or validation failed
401UnauthorizedMissing or invalid authentication token
404Not FoundResource not found
409ConflictResource conflict (duplicate reference)
422Unprocessable EntityValidation errors in request data
429Too Many RequestsRate limit exceeded
500Internal Server ErrorServer error during processing
502Bad GatewayPrestaShop API communication error

Error Response Format

{
"success": false,
"error": "Validation failed",
"details": [
{
"field": "price",
"message": "Price must be a positive number"
}
]
}

✅ Best Practices

1. Image Optimization

Recommended specs:

  • Maximum dimensions: 1200x1200 pixels
  • Format: JPEG for photos, PNG for graphics with transparency
  • Quality: 80-85% for JPEG
  • Size: Under 500KB per image (before base64 encoding)

2. Batch Size Optimization

  • Optimal batch size: 50 products per request
  • Add 1-2 second delay between batches to avoid rate limiting
  • Monitor partial failures in batch responses

3. Validation Before Sync

  • Validate data locally before sending to API
  • Check required fields: reference, name, price, quantity
  • Verify image count (max 10) and technical data count (max 100)
  • Ensure proper data types for all fields

4. Webhook Security

Security checklist:

  • ✅ Use strong webhook secret (minimum 32 characters)
  • ✅ Always verify HMAC signatures
  • ✅ Use HTTPS for webhook endpoint
  • ✅ Log all webhook attempts for audit trail

🔍 Data Flow Diagram

sequenceDiagram
participant ERP as GeSmart ERP
participant API as Sync App API
participant DB as Database
participant PS as PrestaShop API

Note over ERP,PS: Single Product Sync Flow

ERP->>API: POST /api/products/sync
API->>API: Validate JWT Token
API->>API: Validate Product Data
API->>DB: Create Sync Record
API->>PS: Create/Update Product
PS-->>API: Product ID

opt If images provided
loop For each image
API->>PS: Upload Image
PS-->>API: Image ID
end
end

opt If brand provided
API->>PS: Create/Update Brand
PS-->>API: Brand ID
API->>PS: Link Brand to Product
end

opt If technical data provided
API->>PS: Save Technical Specifications
PS-->>API: Confirmation
end

API->>DB: Update Sync Status
API-->>ERP: Success Response

Note over ERP,PS: Webhook Flow

ERP->>API: POST /api/webhooks/gesmart/products
API->>API: Verify HMAC Signature
API->>DB: Queue Sync Job
API-->>ERP: 200 OK (Immediate Response)

Note over API,PS: Async Processing
API->>API: Process Queue
API->>PS: Sync Product
PS-->>API: Result
API->>DB: Update Sync Status

📚 Additional Resources


💡 Support

For issues or questions about the Products Sync API:

  1. Check the error handling section above
  2. Review best practices
  3. Test with the Postman collection
  4. Contact technical support with detailed logs and sync IDs