# Data Export

Export customer data from your platform to AIDP.

## Export Formats

AIDP supports multiple export formats:

* **JSON** - Structured data export
* **CSV** - Bulk data export
* **API** - Real-time sync
* **Webhooks** - Event-driven updates

***

## JSON Export

### Business Profile Export

```json
{
  "businesses": [
    {
      "externalId": "your-business-id-123",
      "name": "Artisan Coffee Roasters",
      "category": "restaurants",
      "description": "Family-owned coffee roastery...",
      "address": {
        "street": "123 Main St",
        "city": "Portland",
        "state": "OR",
        "zip": "97201",
        "country": "USA"
      },
      "coordinates": {
        "lat": 45.5235,
        "lon": -122.677
      },
      "contact": {
        "phone": "+1-503-555-0123",
        "email": "hello@artisancoffee.com",
        "website": "https://artisancoffee.com"
      },
      "hours": {
        "monday": { "open": "07:00", "close": "18:00" },
        "tuesday": { "open": "07:00", "close": "18:00" }
      },
      "services": [
        {
          "name": "Espresso Drinks",
          "description": "Handcrafted espresso beverages",
          "pricing": { "min": 4.0, "max": 6.5 }
        }
      ],
      "media": [
        {
          "type": "photo",
          "url": "https://cdn.yourplatform.com/photos/123.jpg",
          "caption": "Our cozy interior"
        }
      ]
    }
  ]
}
```

### Upload JSON Export

```bash
curl -X POST https://api.aidp.dev/v1/partner/import \
  -H "Authorization: Bearer YOUR_PARTNER_KEY" \
  -H "Content-Type: application/json" \
  -d @export.json
```

***

## CSV Export

### CSV Format

```csv
external_id,name,category,description,street,city,state,zip,phone,email,website
biz_001,Artisan Coffee,restaurants,Family-owned...,123 Main St,Portland,OR,97201,+1-503-555-0123,hello@artisan.com,https://artisan.com
biz_002,Downtown Cafe,restaurants,Modern cafe...,456 Oak Ave,Portland,OR,97202,+1-503-555-0124,info@downtown.com,https://downtown.com
```

### Upload CSV

```bash
curl -X POST https://api.aidp.dev/v1/partner/import/csv \
  -H "Authorization: Bearer YOUR_PARTNER_KEY" \
  -F "file=@businesses.csv"
```

***

## API Sync

### Real-Time Sync

```typescript
import { AIDPPartnerClient } from '@aidp/partner-sdk';

const partner = new AIDPPartnerClient({
  apiKey: process.env.AIDP_PARTNER_KEY,
});

// Sync single business
await partner.sync.business('customer-id', businessData);

// Sync batch
await partner.sync.batch([
  { customerId: 'cust_1', data: business1 },
  { customerId: 'cust_2', data: business2 },
]);
```

***

## Field Mapping

### Required Fields

* `externalId` - Your unique business ID
* `name` - Business name
* `category` - Business category
* `address` - Full address
* `coordinates` - Lat/lon coordinates

### Optional Fields

* `description` - Business description
* `contact` - Phone, email, website
* `hours` - Operating hours
* `services` - Services offered
* `media` - Photos and videos
* `amenities` - Features (wifi, parking, etc.)

***

## Best Practices

### 1. Incremental Updates

Only export changed data:

```typescript
const lastExport = await getLastExportTime();
const changes = await getChangedBusinesses(lastExport);
await partner.sync.incremental(changes);
```

### 2. Batch Processing

Export in batches of 100-500 records:

```typescript
const businesses = await getAllBusinesses();
const batches = chunk(businesses, 100);

for (const batch of batches) {
  await partner.sync.batch(batch);
  await sleep(1000); // Rate limiting
}
```

### 3. Error Handling

```typescript
try {
  await partner.sync.business(customerId, data);
} catch (error) {
  if (error.code === 'VALIDATION_ERROR') {
    console.error('Invalid data:', error.details);
  } else {
    console.error('Sync failed:', error);
  }
}
```

***

**Next**: [Sync Guide →](https://amistan.gitbook.io/aidp-docs/for-saas-platforms/sync)
