import_data
Imports rows from CSV or JSON files into one Directus collection or multiple related collections at once; supports merge/upsert, dry-run previews, and confirmed deletion.
Instructions
Imports rows from a CSV or JSON file into one collection, or into several related collections at once from a flat multi-collection file. Use it when the data is in a file; bulk_operations takes payloads already in memory and create_item a single row. Subject to the Directus IMPORT_MAX_FILE_SIZE limit (50mb by default).
Single-collection: pass collection, and the file is a plain array of rows. Batch (Directus 12.2+): omit collection, and the file MUST be a JSON array of { "collection": string, "items": object[] } entries, e.g. [{"collection":"authors","items":[{"name":"Ann"}]},{"collection":"articles","items":[{"title":"Hi","author":1}]}]
Writes immediately and is not a transaction, so a failure partway leaves earlier rows imported. mode merge upserts instead of inserting, dry_run reports the changes without writing, and only dangerously_allow_delete together with confirm lets rows absent from the file be deleted.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "import_data"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| mode | No | Batch import only. 'add' inserts, 'merge' upserts. Default: add. | |
| confirm | No | Confirm a destructive import | |
| dry_run | No | Batch import only. Report the changes without writing. | |
| filename | No | Filename for the upload; its extension selects the parser (.csv or .json) | |
| file_data | No | Base64-encoded file contents (alternative to file_path) | |
| file_path | No | Path to a local .csv or .json file | |
| collection | No | Target collection. Omit for a multi-collection batch import, in which case the file must be an array of { collection, items } entries rather than a bare row array. | |
| dangerously_allow_delete | No | Batch import only. Permit deletion of rows absent from the file. Requires confirm. |