CSV Migration

The migration API lets you bulk-import patients, products, coupons, orders, and subscriptions from CSV files. Imports follow a dry-run → run-live lifecycle to catch errors before any records are written to production.

Job lifecycle

Upload CSV
    │
    ▼
PENDING_VALIDATION  ──▶  VALIDATING  ──▶  VALIDATION_COMPLETE
                                                  │
                              errorRows > 0?      │
                                  No ─────────────┤
                                                  ▼
                                           PENDING_IMPORT  ──▶  IMPORTING  ──▶  COMPLETED
                                                                                    │
                                                                               ROLLED_BACK
                          ┌─────────────── FAILED ◀── any step
StatusMeaning
PENDING_VALIDATIONJob created; queued for dry-run validation
VALIDATINGWorker is parsing and validating the CSV
VALIDATION_COMPLETEDry-run finished; check errorRows before promoting
PENDING_IMPORTLive job created; queued for actual import
IMPORTINGWorker is writing records to the database
COMPLETEDAll records imported successfully
FAILEDUnrecoverable error during validation or import
ROLLED_BACKLive import rolled back via the rollback action

Required import order

When migrating all entity types, import them in this order to satisfy foreign-key dependencies:

  1. PATIENTS
  2. PRODUCTS
  3. COUPONS
  4. ORDERS
  5. SUBSCRIPTIONS

File requirements

  • Format: text/csv with a header row
  • Max file size: 50 MB
  • Encoding: UTF-8

Download blank template files from GET /v2/migration/templates/:type.