# Import and export clients

Transfer clients between systems, perform backups, or integrate data from your previous records.

## Export clients to CSV

### Simple Download

1. Go to **Clients**
2. Click on **Export > CSV**
3. File `clientes-{fecha}.csv` is downloaded

The file contains all columns:

```csv
nombre,tipo,cif_nif,email,telefono,ciudad,pais,fecha_creacion
Acme Corp,empresa,A12345678,contacto@acme.com,+34 91 123 45 67,Madrid,ES,2025-11-15
Juan García,persona,12345678A,juan@email.com,+34 666 123 456,Barcelona,ES,2026-01-10
```

### Export with Filters

Before exporting, apply filters:

1. Filter by **type** (companies / individuals)
2. Filter by **region** or **country**
3. Filter by **date range** (new clients)
4. Then export

Only filtered clients are exported.

### Use Cases

- **Accounting system change**: Export clients to import into new software
- **Backup**: Regularly save secure CSV
- **Manual invoicing**: Export to create correspondence in Word/Excel
- **Integration**: Send clients to marketing tool or CRM

## Import clients from CSV

### Prepare file

Create a CSV with minimum columns:

```csv
nombre,tipo,cif_nif,email
Beers Ltd,empresa,B87654321,info@beers.com
María López,persona,87654321B,maria@example.com
Servicios TI SL,empresa,C11223344,contacto@servicios-ti.es
```

Automatically recognized columns:

| Column | Required | Example |
|---|---|---|
| nombre | Yes | "Acme Corp" |
| tipo | Yes | company / individual |
| cif_nif | Yes | A12345678 / 12345678A |
| email | No | contacto@empresa.com |
| telefono | No | +34 91 123 45 67 |
| ciudad | No | Madrid |
| pais | No | ES |
| region | No | Madrid |
| codigo_postal | No | 28001 |
| web | No | www.empresa.com |

### Smart Column Detection

Frihet uses **AI to automatically detect** columns even if they have slightly different names:

- "Company" = "nombre"
- "Client Type" = "tipo"
- "NIF" / "CIF" = "cif_nif"
- "Email" / "Mail" / "E-mail" = "email"
- "Phone" / "Tel" = "telefono"
- "City" / "Municipality" = "ciudad"
- "Web" / "Website" = "web"

This allows importing files from other systems without manual reformatting.

### Import Process

1. Go to **Clients > Import > From CSV**
2. Drag file or select from disk
3. Frihet **validates format** and shows preview:
   - Rows to import
   - Detected columns
   - Problems found
4. Resolve conflicts (see below)
5. Click **Import**

### Validation and Conflicts

During import, Frihet verifies:

#### Duplicates

If the CIF/NIF already exists in your account:

- **Option 1**: Skip (do not import that client)
- **Option 2**: Update existing client data
- **Option 3**: Create new with import data

#### Invalid CIF/NIF

If the format is not valid:

```
Fila 5: "Acme Corp" — CIF "123" no válido
Sugerencia: ¿Quisiste decir "A12345678"?
```

You can:
- Correct before importing
- Leave blank (requires manual editing later)
- Skip that row

#### Duplicate Email

If the same email is registered for 2 clients:

```
Fila 3: "García & Asociados" usa email "contacto@empresas.com"
También en: "García Servicios Legales" (existente)
```

Choose which to keep or create a new one with a different email.

### Example: Import from Excel

If your clients are in Excel:

1. Open file in Numbers / Excel
2. Select data range
3. Copy (Cmd+C)
4. In Frihet, go to **Clients > Import**
5. Paste (Cmd+V) into the import area
6. Frihet automatically detects format

## Batch Operations

After importing, you can apply changes to multiple clients:

### Assign Payment Term

1. Go to **Clients**
2. Select multiple (checkbox in list)
3. Click **Actions > Set payment term**
4. Choose term (30, 60, 90 days)
5. Apply to all selected

### Change Region

Useful if you imported clients from another branch:

1. Select clients
2. **Actions > Edit region**
3. New region: Catalonia
4. Apply

### Add Tag

Categorize imported clients:

1. Select clients
2. **Actions > Add tag**
3. Create tag (e.g.: "Imported 2026")
4. Apply

Tags allow filtering later.

## Export to Other Tools

### To Stripe (for payments)

Frihet exports clients to Stripe-compatible format:

1. Go to **Clients > Export**
2. Select **Stripe Format**
3. JSON with correct structure is downloaded
4. Import into Stripe dashboard

### To HubSpot (CRM)

1. **Clients > Export > HubSpot**
2. Frihet generates integration token
3. Automatically synchronizes bidirectional (Premium plan)

### To Google Sheets

For collaboration:

1. **Clients > Export > Google Sheets**
2. A new shareable sheet opens
3. Changes in Sheets synchronize to Frihet (1-hour delay)

## Continuous Synchronization

In **Premium** plan, enable synchronization:

1. Go to **Integrations > CRM**
2. Select tool (HubSpot, Pipedrive, Salesforce)
3. Authorize access (OAuth)
4. Choose what to synchronize:
   - Client data (bidirectional)
   - Invoice history (unidirectional: Frihet → CRM)
   - Payments (unidirectional)

Changes synchronize automatically every hour.

## Common Problems

### "Invalid CIF in row 3"

The CIF must follow format: 1 letter + 7 numbers + 1 letter/number.
- ✅ A12345678
- ❌ 12345678 (missing letter)
- ❌ A1234567 (only 7 digits)

Correct before importing.

### "Duplicate email in my account"

A client has 2 records with the same email. Use **Clients > Merge clients** to consolidate before importing.

### "Corrupt CSV file"

If Frihet cannot read the file:

- Save as UTF-8 (not Latin-1)
- Verify delimiter (comma, semicolon)
- Open in Excel and save again as new CSV
- Try importing again

### "Slow import"

If you import 10,000+ clients:

- Process in batches of 5,000 maximum
- In Premium plan, contact support for optimized import
- The first import is slower (indexing); subsequent ones are fast
