Skip to main content
POST
/
api
/
admin
/
import-csv
Import CSV
curl --request POST \
  --url https://api.example.com/api/admin/import-csv \
  --header 'Content-Type: application/json' \
  --data '
{
  "email": "<string>",
  "phone": "<string>",
  "código país": "<string>",
  "nombre": "<string>",
  "apellido": "<string>",
  "cumpleaños": "<string>",
  "empresa": "<string>",
  "cargo": "<string>",
  "dirección": "<string>",
  "etiquetas": "<string>"
}
'
{
  "success": true,
  "report": {
    "details": [
      {
        "file": "<string>",
        "location": "<string>",
        "imported": 123,
        "errors": 123,
        "status": "<string>"
      }
    ],
    "totalSuccess": 123,
    "totalErrors": 123
  }
}

Import CSV

Bulk import customer data from predefined CSV files. This endpoint processes multiple CSV files, creates/updates customers, and links them to their respective locations.

Endpoint

POST /api/admin/import-csv

Authentication

Requires canViewSettings permission (admin or super_admin only).
await requirePermission("canViewSettings");

CSV File Mapping

The endpoint processes these predefined CSV files from the project root:
FilenameLocation
molla-clientes.csvLa Tasca Alicante · Centro
balmis-clientes.csvLa Tasca Alicante · Puerto
marques-cubas-clientes.csvLa Tasca Madrid · Centro
claudio-coello-clientes.csvLa Tasca Madrid · Salamanca
el-patio-clientes.csvEl Patio Alicante

CSV Format

Supported CSV columns (auto-detected, semicolon-separated):
email
string
Customer email address
phone
string
Phone number (will be combined with country code)
código país
string
Country code (e.g., 34 for Spain)
nombre
string
First name
apellido
string
Last name
cumpleaños
string
Birth date (DD/MM/YYYY or YYYY-MM-DD)
empresa
string
Company name
cargo
string
Job title
dirección
string
Address
etiquetas
string
Tags (comma-separated)
At least email or phone is required for each customer.

Response

success
boolean
Whether the import completed successfully
report
object
Import summary report

Example Request

curl -X POST https://your-domain.com/api/admin/import-csv \
  -H "Cookie: your-session-cookie"

Example Response

{
  "success": true,
  "report": {
    "details": [
      {
        "file": "molla-clientes.csv",
        "location": "La Tasca Alicante · Centro",
        "imported": 243,
        "errors": 5
      },
      {
        "file": "balmis-clientes.csv",
        "status": "Skipped - Not Found"
      }
    ],
    "totalSuccess": 243,
    "totalErrors": 5
  }
}

Error Response

{
  "error": "Error message",
  "stack": "Error stack trace",
  "status": 500
}

Import Process

For each CSV file:
  1. Read File - Load CSV from project root
  2. Detect Headers - Auto-map columns (supports Spanish and English headers)
  3. Parse Rows - Process up to 5,000 rows per file
  4. Upsert Customer - Create or update customer in global customers table
  5. Link to Location - Create reservation record to link customer to location

Customer Matching Logic

  • If email provided, match by email
  • Otherwise, match by phone
  • If customer exists, merge new data (update birth date, company, job title, address)
  • If new customer, create with source: 'Bulk Import'

Phone Number Formatting

let phone = phoneVal;
if (phone && countryCode) {
  phone = `+${countryCode.replace('+', '')}${phone}`;
}

Birth Date Parsing

Supports two formats:
  • DD/MM/YYYY → converted to YYYY-MM-DD
  • YYYY-MM-DD → used as-is

Limitations

  • Maximum 5,000 rows per CSV file
  • CSV files must be in project root directory
  • Only predefined location mappings are supported
  • Processes files sequentially (not parallel)

Use Cases

  • Initial CRM setup with existing customer data
  • Migrate from CoverManager or other PMS systems
  • Bulk import from marketing campaigns
  • Restore customer data after system migration

Build docs developers (and LLMs) love