Endpoint
Request Body
An array of CSV rows, where each row is an array of values. The first row (header) is automatically skipped.
CSV Format
The CSV data should have the following column structure:Column 0 - Not used (typically ID or row number)
Column 1 - Task name/title
Column 2 - Due date in ISO 8601 format (e.g.,
"2026-03-15T10:00:00Z")Column 3 - Task status (e.g.,
"pending", "in-progress", "completed")Column 4 - Additional information/notes
Column 5 - Is finished (
"true" or "false")Column 6 - Task column/category
Response
Returns
"Successful!" when all tasks are imported successfully.Returns
"Invalid!" if the import fails.CSV Example
Here’s an example CSV file:Example Request
Response Example
Error Response
Behavior Notes
The first row of the CSV (header row) is automatically skipped using
file.file.shift(). Make sure your CSV includes a header row.The
is_finished field is converted from string to boolean: "true" becomes true, anything else becomes false.After successfully importing tasks, emit a
database-change event via Socket.io to notify other clients. See Real-time Updates for details.Data Mapping
The endpoint maps CSV columns to database fields as follows:Preparing CSV Files
From Spreadsheet Software
When exporting from Excel, Google Sheets, or similar:- Arrange columns in the correct order (ID, Task, Due Date, Status, Notes, Finished, Column)
- Format dates as ISO 8601 strings
- Use “true” or “false” for the Finished column
- Export as CSV
Programmatic CSV Generation
Error Scenarios
Common reasons for import failure:- Invalid date format in column 2
- Missing required columns
- CSV not properly formatted as nested arrays
- Database connection issues
- Constraint violations (though unlikely with the current schema)
Performance Considerations
Alternative: Batch Import
For better performance with large datasets, you could modify the endpoint to usecreateMany:
Complete Import Workflow
Related Endpoints
- Create Task - Create individual tasks
- Get Tasks - Retrieve imported tasks
Source Reference
Implementation:src/routes/api/(exportimport)/importcsv/+server.ts:5