Skip to main content

Import a CSV file

Two ways: the Insights app (no code) and the SDK (repeatable, automatable).

Option A: the Insights app​

  1. Create a store source, for example Orders. In its settings set the Document ID to Field and choose orderId, so later uploads update existing rows instead of duplicating them.
  2. Open the source and start Add file.
  3. Select insights-orders.csv from the test data.
  4. Check the analysis: header row, field names and detected types.
  5. Set the field types (see the table in the test data page) and confirm the import.
Separator

The CSV parser expects ; as separator and the header in the first row. Values arrive as text, the field types you set on the source convert them.

Option B: script it with the SDK​

import-insights.mjs (excerpt)
import { readFile } from 'fs/promises'

import sdk from '@scenid/cloud-sdk'

const convert = value => {
if (/^-?\d+(\.\d+)?$/.test(value)) return Number(value)
if (value === 'true') return true
if (value === 'false') return false
return value
}

const [header, ...lines] = (await readFile('insights-orders.csv', 'utf8')).trim().split('\n')
const columns = header.split(';')

const rows = lines.map(line => Object.fromEntries(
line.split(';').map((value, i) => [columns[i], convert(value.trim())])
))

const source = sdk.asAdmin().Insights().Source('Orders')

for (let i = 0; i < rows.length; i += 100) {
const { result } = await source.Doc.batchInsert(rows.slice(i, i + 100))
console.log(result)
}

The full script with a proper CSV parser is in the test data downloads:

node import-insights.mjs service-key.json "Orders" ../insights-orders.csv

Tips​

  • Convert types yourself. CSV has only text. Numbers and booleans should arrive as numbers and booleans. The script above does that.
  • Timestamps in ISO 8601 (2026-08-14T09:30:00Z) map to date-iso.
  • Geo points as "lat,lon" map to geo-point.
  • Repeat safely. With the document ID set to a field (orderId), a second run updates instead of duplicating. Set it before the first import.
  • Upload more later. A store accepts any number of uploads. New rows are added and rows with a known key are updated.
  • Check failures. batchInsert reports invalid rows in result.errors. It does not stop at the first one.