> For the complete documentation index, see [llms.txt](https://integrations.drivetrain.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://integrations.drivetrain.ai/extending-drivetrain/drivetrain-api/upload-csv-to-list-api.md).

# Upload CSV to list API

Replace all rows of a Drivetrain list with the contents of a CSV file in a single POST request. Covers the endpoint, CSV format rules, the response, and error codes.

Use this API to replace all rows of an existing list in your Drivetrain tenant with the contents of a CSV file, in a single call. The changes are synced to the list's dataset before the API returns.

**Method:** `POST`

**Path:** `https://{your_subdomain}.drivetrain.ai/drive/api/v1/public/lists/{listId}/csv`

**Headers:**

* `apikey` (MANDATORY)
* `Content-Type: text/csv` (MANDATORY). Requests without it are rejected with `415 Unsupported Media Type`.

**Body:** the raw CSV file.

### Path parameters

| Parameter            | Description                                                |
| -------------------- | ---------------------------------------------------------- |
| `listId` (MANDATORY) | The numeric ID of the list whose rows you want to replace. |

To find a list ID, see [How to find a list ID](https://integrations.drivetrain.ai/extending-drivetrain/drivetrain-api/get-list-api.md#how-to-find-a-list-id).

### CSV format

* The first row must be the header row.
* Headers must exactly match the list's columns.
* Leave out formula columns. Don't include them in the CSV.
* Quoted values, such as `"Eng, Platform"`, are supported.
* UTF-8 files with a byte order mark (BOM) are supported. This includes files exported from Excel as **CSV UTF-8**.

### Curl command example

```bash
curl -X POST 'https://{your_subdomain}.drivetrain.ai/drive/api/v1/public/lists/12345/csv' \
  --header 'apikey: {your_apikey}' \
  --header 'Content-Type: text/csv' \
  --data-binary @headcount.csv
```

### Sample response

```json
{"success": true, "rowsUploaded": 342}
```

### Response fields

| Field          | Description                                              |
| -------------- | -------------------------------------------------------- |
| `success`      | `true` when the upload is saved.                         |
| `rowsUploaded` | Number of rows from the CSV that were saved to the list. |

### How the upload works

* **Full replace:** existing rows are deleted and replaced by the rows in the CSV. List settings, such as columns, scenarios, and overrides, are kept.
* **Idempotent:** uploading the same file again gives the same result.
* **All-or-nothing:** if anything in the CSV is invalid, nothing is saved.
* **No empty uploads:** a CSV with headers but no data rows is rejected, because it would empty the list.
* **Sync timing:** the list's dataset is synced before the response returns. Downstream datasets derived from the list rebuild asynchronously right after.

### Validation rules & error handling

| Condition                                                        | Result                                                                                                                  |
| ---------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| CSV headers don't match the list's columns                       | `400 Bad Request`. The response lists the extra headers in `newColHeaders` and the missing ones in `missingColHeaders`. |
| One or more cells fail validation                                | `400 Bad Request`. The response includes `rowErrors`, with details for up to the first 100 rows that have errors.       |
| CSV is empty, has no data rows, or can't be parsed               | `400 Bad Request`                                                                                                       |
| Missing or invalid `apikey`                                      | `401 Unauthorized`                                                                                                      |
| The `apikey` user doesn't have the **Admin** role                | `403 Forbidden`                                                                                                         |
| `listId` not found, or the list belongs to a non-current version | `404 Not Found`                                                                                                         |
| Another edit to this list is in progress                         | `409 Conflict`. Retry the request.                                                                                      |
| `Content-Type` isn't `text/csv` or `text/plain`                  | `415 Unsupported Media Type`                                                                                            |

#### Sample error responses

**Column mismatch**

```json
{
  "success": false,
  "message": "CSV columns do not match the list columns.",
  "newColHeaders": ["Extra"],
  "missingColHeaders": ["Dept"]
}
```

**Cell validation errors**

```json
{
  "success": false,
  "message": "3 row(s) have validation errors.",
  "rowErrors": [
    {"rowIndex": 1, "errors": {"Amount": ["Value is not a number"]}}
  ]
}
```

`rowIndex` is 0-based and doesn't count the header row. For example, `rowIndex: 1` is the second data row in the CSV.

### Related

* [Get list API](https://integrations.drivetrain.ai/extending-drivetrain/drivetrain-api/get-list-api.md)
* [Drivetrain API](https://integrations.drivetrain.ai/extending-drivetrain/drivetrain-api.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://integrations.drivetrain.ai/extending-drivetrain/drivetrain-api/upload-csv-to-list-api.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
