---
title: "Import and export buyers"
description: "Learn how to download your buyers as a CSV, Excel or JSON file, fill in the sample, and import a file of buyers."
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.certinvo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Import and export buyers

Your buyers can go out as a file and come back in as one: CSV, Excel (`.xlsx`) or JSON. Use it to move a buyer
list from another system, to edit many buyers in a spreadsheet, or to keep a copy.

An import always shows what it would do first. Nothing is saved until you confirm.

## Download the buyers or the sample

In the console, open **Buyers**, then **Import and export**. Under **Download**, choose CSV, Excel or JSON. The
example file is on the **Data files** page, which the same menu links to. Through the API, any key may
download:

```bash
curl -s -o buyers.csv -H "Authorization: Bearer cvo_live_sk_..." "https://<api-host>/v1/data-files/customers?format=csv"
curl -s -o buyers-sample.xlsx -H "Authorization: Bearer cvo_live_sk_..." "https://<api-host>/v1/data-files/customers/sample?format=xlsx"
```

`format` is `csv`, `xlsx` or `json`. Without it, you get CSV. With no buyers saved, the file has only its header row.

The sample holds a few buyers, in the same columns. They are the buyers of invoices the validator accepted. Nobody
typed them.

## The columns

- One row per buyer.
- Each column is the API's field name. A nested field is dotted: `address.city`, `contact.email`, `delivery.to`.
- Each fact a country's rules ask of a buyer has its own column, `facts.<name>`. A yes-or-no fact is `true` or
  `false`.
- `files` is one cell, its ids separated by commas, such as `cii,zugferd-pdf`.
- What VIES and the Peppol registry answered about a buyer has no column. The API asks them each time a buyer is
  saved.
- The CSV is separated by semicolons, in UTF-8 with a byte order mark, so Excel opens it with its umlauts.
- A cell starting with `=`, `+`, `-` or `@` is written with a leading `'`, so a spreadsheet never runs it as a
  formula. An import takes the `'` off again. A plain number, such as `-50.00`, is written as it is.
- The Excel sheet writes every cell as text and formats every column as text, so a postcode like `01067` keeps its
  leading zero, and so does one you type in later.
- The JSON is a list of buyers, as `GET /v1/customers` holds them. An import also takes `{"customers": [...]}`.

## Import a file

1. On **Buyers**, open **Import and export**, choose **Import a file** and pick the file.
2. The import page counts the rows as new, changed, the same and not imported. It names each new and changed buyer,
   and each row it will not import, with its row number, its column and why.
3. Choose **Import**. All new and changed buyers are saved as one new version of the list.
4. If someone changed the buyers meanwhile, the page reads the file again against the new list. Check it and import.

How a row finds its buyer:

- A row with an `id` is that buyer.
- A row with no `id` is the one buyer with that `name`. If none has it, the row is a new buyer, and its id is made
  from its name. If several have it, give the row an id.

What a row changes:

- A column the file has sets that field. An empty cell clears it.
- A column the file lacks keeps what is saved. A file with only `id` and `vatId` changes VAT IDs and nothing else.
- **A buyer the file leaves out is kept.** An import never removes a buyer. Remove one on its own page.

A file with a column no buyer has, such as `iban`, is refused whole, naming the column. A file with neither an `id`
nor a `name` column is refused too.

## Import through the API

Preview first. Any key may preview:

```bash
curl -s -X POST -H "Authorization: Bearer cvo_live_sk_..." -H "Content-Type: application/json" \
  -d "{\"data\": \"$(base64 < buyers.csv)\"}" "https://<api-host>/v1/data-files/customers/previews"
```

The answer has `counts`, one entry per row in `rows`, and `basedOn`, the version of the list it was made against.

Only a signed-in person may import, as only a person may change the buyers. Send the same file with `basedOn` to
`POST /v1/data-files/customers/imports`. A key is refused with 401 `session_required`.

| Status | Code | What happened |
|---|---|---|
| 400 | `invalid_data_file` | The file is no buyers file: not a CSV, Excel sheet or JSON list, or it has a column no buyer has. The message names it. Nothing was read. |
| 400 | `invalid_format` | `format` is not `csv`, `xlsx` or `json`. |
| 409 | `list_changed` | The buyers changed since the preview. Preview the file again. Nothing was saved. |
| 409 | `request_in_progress` | Another import of the same list is being saved at this moment. Preview the file again once it is done. Nothing was saved. |

A file that changes nothing saves nothing. The answer's `version` is then the current one.

Source: https://docs.certinvo.com/how-to/invoices/import-and-export-buyers/index.mdx
