Skip to content

Export my customers to CSV

Say "export my customers to CSV" and get a file of every Customer, once or on a schedule, with the fields your Permissions hide masked.

For developers

An export writes a Collection’s records to a file or your warehouse, once or on a schedule. Fields your Permissions hide come out masked.

For developers

Needs Customer

What you get

  • 1CSV file of every Customer, one row eachFile
  • 1fields your Permissions hide, maskedPermission

Your agent does

Collection.export
You, to your agent

Export all my customers to CSV.

Download my customer list as a spreadsheet.

Give me a CSV of every customer.

# Look up the Collection: Collection.list
COLLECTION=$(curl "https://api.sb/leaseline.app/collections?where=type%20%3D%20customer&limit=1" \
  -H "Authorization: Bearer $STARTUP_BUILDER_API_KEY" | jq -r '.collections[0]["$id"] | split("/") | last')

# Collection.export
curl -X POST https://api.sb/leaseline.app/collections/$COLLECTION/export \
  -H "Authorization: Bearer $STARTUP_BUILDER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"to":"csv"}'
import { $ } from 'startup-builder'

const [collection] = await $.Collection.list({ where: 'type = customer', limit: 1 })
await $.Collection.export({ collection: collection.$id, to: 'csv' })
COLLECTION=$(npx startup-builder do Collection.list --json '{"where":"type = customer","limit":1}' | jq -r '.collections[0]["$id"] | split("/") | last')
npx startup-builder do Collection.export --json '{"collection":"'"$COLLECTION"'","to":"csv"}'
{
  "name": "do",
  "arguments": {
    "code": "const [collection] = await $.Collection.list({ where: 'type = customer', limit: 1 })\nreturn await $.Collection.export({ collection: collection.$id, to: 'csv' })"
  }
}

Change it

  • Export every order too.
  • Send it to the warehouse every night.
  • Leave out email addresses.

Under the hood

Systems
Data editor
Nouns
Collection, Customer, File
Events
Collection.exported