Order Import
Import historical orders to populate customer data and enable segmentation.
Use cases
- Initial edrone setup - import past orders
- Data migration from another platform
- Syncing orders from offline sales channels
Import process
- Export orders from your platform
- Transform data to edrone format
- Send each order via API
- Verify import in Mission Control
Example: Batch import
- Python
- PHP
import requests
import time
from datetime import datetime
def import_order(order):
"""Send a single order to edrone."""
data = {
'app_id': 'YOUR_APP_ID',
'sender_type': 'server',
'action_type': 'order',
'email': order['email'],
'first_name': order['first_name'],
'last_name': order.get('last_name', ''),
'order_id': order['order_id'],
'country': order['country'],
'city': order['city'],
'base_currency': 'USD',
'order_currency': order['currency'],
'base_payment_value': str(order['total']),
'order_payment_value': str(order['total']),
'product_ids': '|'.join(str(p['id']) for p in order['products']),
'product_titles': '|'.join(p['title'] for p in order['products']),
'product_images': '|'.join(p['image'] for p in order['products']),
'product_urls': '|'.join(p['url'] for p in order['products']),
'product_counts': '|'.join(str(p['qty']) for p in order['products']),
'product_category_ids': '|'.join(p['category_ids'] for p in order['products']),
'product_category_names': '|'.join(p['category_names'] for p in order['products']),
# Historical date
'event_utc_date': order['date'].strftime('%Y-%m-%d %H:%M:%S')
}
response = requests.post('https://api.edrone.me/trace', data=data)
return response.status_code == 200
def batch_import(orders):
"""Import multiple orders with rate limiting."""
success = 0
failed = 0
for i, order in enumerate(orders):
try:
if import_order(order):
success += 1
else:
failed += 1
except Exception as e:
print(f"Error importing order {order['order_id']}: {e}")
failed += 1
# Rate limiting: 10 requests per second
if (i + 1) % 10 == 0:
time.sleep(1)
# Progress logging
if (i + 1) % 100 == 0:
print(f"Processed {i + 1}/{len(orders)} orders")
print(f"Import complete: {success} success, {failed} failed")
# Example usage
orders = [
{
'order_id': 'ORD-001',
'email': 'customer1@example.com',
'first_name': 'John',
'last_name': 'Doe',
'country': 'US',
'city': 'New York',
'currency': 'USD',
'total': 149.99,
'date': datetime(2024, 1, 15, 10, 30, 0),
'products': [
{
'id': '123',
'title': 'Product A',
'image': 'https://store.com/img/a.jpg',
'url': 'https://store.com/products/a',
'qty': 2,
'category_ids': '1~2~3',
'category_names': 'Category~Sub~Item'
}
]
}
]
batch_import(orders)
<?php
function importOrder($order) {
$products = $order['products'];
$data = http_build_query([
'app_id' => 'YOUR_APP_ID',
'sender_type' => 'server',
'action_type' => 'order',
'email' => $order['email'],
'first_name' => $order['first_name'],
'last_name' => $order['last_name'] ?? '',
'order_id' => $order['order_id'],
'country' => $order['country'],
'city' => $order['city'],
'base_currency' => 'USD',
'order_currency' => $order['currency'],
'base_payment_value' => $order['total'],
'order_payment_value' => $order['total'],
'product_ids' => implode('|', array_column($products, 'id')),
'product_titles' => implode('|', array_column($products, 'title')),
'product_images' => implode('|', array_column($products, 'image')),
'product_urls' => implode('|', array_column($products, 'url')),
'product_counts' => implode('|', array_column($products, 'qty')),
'product_category_ids' => implode('|', array_column($products, 'category_ids')),
'product_category_names' => implode('|', array_column($products, 'category_names')),
'event_utc_date' => $order['date']
]);
$ch = curl_init('https://api.edrone.me/trace');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $httpCode === 200;
}
function batchImport($orders) {
$success = 0;
$failed = 0;
foreach ($orders as $i => $order) {
if (importOrder($order)) {
$success++;
} else {
$failed++;
}
// Rate limiting
if (($i + 1) % 10 === 0) {
sleep(1);
}
}
echo "Import complete: $success success, $failed failed\n";
}
Important: Historical dates
Use event_utc_date to set the original order date:
event_utc_date=2024-01-15 10:30:00
Format: YYYY-MM-DD HH:MM:SS (UTC timezone)
Rate limiting
- Recommended: 10 requests per second
- Maximum: 100 requests per second
- Add delays between batches for large imports
Verification
After import:
- Go to Mission Control → CRM
- Check customer profiles for imported orders
- Verify order counts in Analytics