Product Sync API
Sync your products from any source (Shopify, WooCommerce, custom system) to AI Commerce. AI embeddings are automatically generated for all products.
Info
docs.callouts.productSyncInfo
API Endpoints
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/products | Create single product or batch upsert |
| GET | /api/v1/products | List products with pagination |
| GET | /api/v1/products/:id | Get product details |
| PUT | /api/v1/products/:id | Update a product |
| DELETE | /api/v1/products/:id | Delete a product |
| POST | /api/v1/upload | Upload product image |
Create Product
Create a single product in your store catalog:
create.ts
typescript
import { AICommerce } from '@yassirbenmoussa/aicommerce-sdk';
const client = new AICommerce({
apiKey: 'YOUR_API_KEY',
storeId: 'YOUR_STORE_ID',
});
// Create a single product
const result = await client.products.create({
name: 'MacBook Pro 14"',
slug: 'macbook-pro-14',
description: 'Powerful laptop with M3 Pro chip',
price: 1999.99,
currency: 'USD',
tags: 'laptop, apple, macbook, professional',
images: [{ url: 'https://example.com/macbook.jpg', isPrimary: true }]
});
console.log('Product ID:', result.product.id);Batch Upsert
Create or update multiple products at once (up to 100):
batch.ts
typescript
// Batch upsert products (create or update)
const result = await client.products.batchUpsert([
{
name: 'iPhone 15 Pro',
slug: 'iphone-15-pro',
price: 999.99,
externalId: 'shopify_123', // Use for idempotent sync
tags: 'phone, apple, iphone'
},
{
name: 'AirPods Pro',
slug: 'airpods-pro',
price: 249.99,
externalId: 'shopify_456',
tags: 'audio, wireless, earbuds'
}
]);
console.log(`Processed: ${result.processed}, Errors: ${result.errors}`);Tip
docs.callouts.productSyncTip
List Products
Retrieve products with pagination and filters:
list.ts
typescript
// List products with pagination
const products = await client.products.list({
page: 1,
perPage: 20,
search: 'laptop',
isActive: true
});
console.log(`Found ${products.total} products`);
products.data.forEach(p => console.log(p.name, p.price));Update & Delete
Update or remove products from your catalog:
update.ts
typescript
// Update a product
await client.products.update('product_id', {
price: 1899.99,
quantity: 45
});
// Delete a product
await client.products.delete('product_id');Upload Images
Upload and associate images with your products:
upload.ts
typescript
// Upload image from file input
const fileInput = document.querySelector('input[type="file"]');
const file = fileInput.files[0];
const result = await client.upload(file);
console.log('Image URL:', result.url);
// Upload and associate with product
const result = await client.upload(file, {
productId: 'product_id',
isPrimary: true
});Product Fields
| Field | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | Product display name |
| slug | string | Yes | URL-friendly unique identifier |
| price | number | Yes | Product price as number |
| description | string | No | Detailed product description |
| tags | string | No | Comma-separated keywords (helps AI search) |
| productUrl | string | No | External URL to the product page |
| externalId | string | No | Your system's ID (for syncing) |