The XML Import Orchestrator API handles intelligent XML file imports with automatic field detection, AI-powered mapping suggestions, and product creation.
Edge Function: xml-import-orchestrator
Base URL: https://bgbavxtjlbvgplozizxu.supabase.co/functions/v1/xml-import-orchestrator
All requests require authentication via Supabase Auth:
Authorization: Bearer <supabase_access_token>
Method: POST
Path: /
Request:
{
workspace_id: string, // Required
category: string, // Required - Product category
xml_content: string, // Required - Base64 encoded XML
source_name?: string, // Optional - Source identifier
mapping_template_id?: string, // Optional - Use existing template
field_mappings?: Record<string, string>, // Optional - Custom mappings
preview_only?: boolean, // Optional - Only detect fields
generate_preview?: boolean, // Optional - Generate sample product
manual_values?: { // Optional - Manual field values
factory_name?: string,
name?: string,
material_category?: string
}
}
Detect all fields in the XML without creating products.
Request:
{
workspace_id: 'workspace-123',
category: 'flooring',
xml_content: '<base64-encoded-xml>',
preview_only: true
}
Response:
{
success: true,
detected_fields: Array<{
xml_field: string, // Field name in XML
sample_values: string[], // Sample values from XML
suggested_mapping: string, // AI-suggested target field
confidence: number, // Confidence score (0-1)
data_type: string // Detected data type
}>,
suggested_mappings: {
'xml_field_name': 'target_field_name',
// ... more mappings
},
total_products: number
}
Example:
const { data, error } = await supabase.functions.invoke('xml-import-orchestrator', {
body: {
workspace_id: 'workspace-123',
category: 'flooring',
xml_content: btoa(xmlString), // Base64 encode
preview_only: true
}
});
console.log('Detected fields:', data.detected_fields);
console.log('Suggested mappings:', data.suggested_mappings);
Generate a sample product with applied mappings.
Request:
{
workspace_id: 'workspace-123',
category: 'flooring',
xml_content: '<base64-encoded-xml>',
field_mappings: {
'product_name': 'name',
'product_description': 'description',
'manufacturer': 'factory_name',
'category': 'material_category'
},
generate_preview: true
}
Response:
{
success: true,
preview_product: {
name: string,
description: string,
factory_name: string,
factory_group_name?: string,
material_category: string,
images?: string[],
metadata: Record<string, any>
},
total_products: number
}
Create products from XML with specified mappings.
Request:
{
workspace_id: 'workspace-123',
category: 'flooring',
xml_content: '<base64-encoded-xml>',
source_name: 'Supplier ABC',
field_mappings: {
'product_name': 'name',
'product_description': 'description',
'manufacturer': 'factory_name',
'category': 'material_category',
'image_url': 'images'
},
manual_values: {
factory_name: 'ABC Manufacturing',
material_category: 'Wood Flooring'
}
}
Response:
{
success: true,
job_id: string, // Import job ID for tracking
message: string,
total_products: number
}
| Target Field | Description | Required |
|---|---|---|
name |
Product name | Yes |
description |
Product description | No |
factory_name |
Manufacturer name | Yes |
factory_group_name |
Manufacturer group | No |
material_category |
Material category | Yes |
images |
Product images (URLs) | No |
price |
Product price | No |
sku |
SKU/Product code | No |
dimensions |
Product dimensions | No |
weight |
Product weight | No |
color |
Product color | No |
finish |
Surface finish | No |
material |
Material composition | No |
Any unmapped fields are stored in the metadata object:
{
name: 'Oak Flooring',
factory_name: 'ABC Manufacturing',
metadata: {
custom_field_1: 'value1',
custom_field_2: 'value2',
// ... other unmapped fields
}
}
The system uses AI to:
The system supports multiple XML structures:
<!-- Format 1: Standard product elements -->
<products>
<product>
<name>Product Name</name>
<description>Description</description>
</product>
</products>
<!-- Format 2: Item elements -->
<catalog>
<item>
<title>Product Name</title>
<details>Description</details>
</item>
</catalog>
<!-- Format 3: Material elements -->
<materials>
<material>
<product_name>Product Name</product_name>
<product_desc>Description</product_desc>
</material>
</materials>
After creating an import job, track its progress:
// Get job status
const { data: job } = await supabase
.from('data_import_jobs')
.select('*')
.eq('id', jobId)
.single();
console.log('Status:', job.status);
console.log('Progress:', job.processed_count, '/', job.total_count);
{
success: false,
error: string,
details?: object
}
Common Errors:
400 - Invalid XML format, missing required parameters401 - Unauthorized422 - XML parsing error500 - Internal server errorpreview_only: true to verify field detectiongenerate_preview: true to see a sample product