Skip to main content

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​

  1. Export orders from your platform
  2. Transform data to edrone format
  3. Send each order via API
  4. Verify import in Mission Control

Example: Batch import​

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)

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:

  1. Go to Mission Control → CRM
  2. Check customer profiles for imported orders
  3. Verify order counts in Analytics