# Export my customers to CSV

URL: /systems/data-and-insights/export-my-data · Id: `guide:export-my-data`

> 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.

An export writes a [Collection](/business/nouns/collection)’s records to a file or your warehouse, once or on a schedule. Fields your [Permissions](/business/nouns/permission) hide come out masked.

Needs: [Customer](/business/nouns/customer)

**Before it runs**

- You leave the chat: Never: it all happens in the chat.

## What you get
- 1 CSV file of every Customer, one row each (File)
- 1 fields your Permissions hide, masked (Permission)

## Your agent does
**For agents**

- Guide: `guide:export-my-data`, status `live`. Page: [/systems/data-and-insights/export-my-data.md](/systems/data-and-insights/export-my-data.md).
- Approval: none. Run it when the founder asks.
- Leaves the chat: never.
- Needs first: [Customer](/business/nouns/customer).
- Run: call the steps in order, each through the API, SDK, CLI or MCP tab below; a later step passes the `$id` an earlier one returns. Each value marked example is the sample business’s: pass the founder’s own.

| Step | Verb | Inputs (type, required, this guide’s value) | Returns |
| --- | --- | --- | --- |
| 1 | [`Collection.export`](/business/nouns/collection/export) (`verb:Collection.export`) | `collection` Collection (an id), required: the `$id` of the first Collection `Collection.list` returns for `where: type = customer`; `to` string, required: example `"csv"` | `file` File, `collection` Collection |

Returns: the last call answers with `file`, `collection` and its `action`, whose `status` is `done`, `pending` (waiting on an Approval or a Worker), `failed`, `canceled` or `refused`:

```json
{
  "api": "https://api.sb/leaseline.app",
  "file": {
    "$id": "https://api.sb/leaseline.app/files/file_1",
    "$type": "File"
  },
  "collection": {
    "$id": "https://api.sb/leaseline.app/collections/collection_1",
    "$type": "Collection"
  },
  "action": {
    "$id": "https://api.sb/leaseline.app/actions/action_1",
    "operation": "Collection.export",
    "status": "done"
  },
  "links": {
    "self": "https://api.sb/leaseline.app/actions/action_1"
  }
}
```

Next: offer “Export every order too”, or “Send it to the warehouse every night”.

Calls: `Collection.export`

Ask:

```text
Export all my customers to CSV.
Download my customer list as a spreadsheet.
Give me a CSV of every customer.
```

API:

```bash
# 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"}'
```

SDK:

```ts
import { $ } from 'startup-builder'

const [collection] = await $.Collection.list({ where: 'type = customer', limit: 1 })
await $.Collection.export({ collection: collection.$id, to: 'csv' })
```

CLI:

```bash
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"}'
```

MCP:

```json
{
  "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](/code/systems/data-editor)
- Nouns: [Collection](/business/nouns/collection), [Customer](/business/nouns/customer), [File](/business/nouns/file)
- Events: [`Collection.exported`](/business/events/Collection.exported)