-
-
Notifications
You must be signed in to change notification settings - Fork 2
CSV module
The CSV module has 4 endpoints:
- create table columns from csv header
- update csv field mapping
- import csv to existing table
- export csv errors to another csv
PUT /tables/{id}/csv-prepare-fields/
{
"file": <file_obj>,
"delimiter": ";"
}
{
"table": "<table_name>",
"import_id": <import_id>,
"fields": [
{
"original_name": "<original_csv_column_name>",
"field_name": "<table_column_display_name>",
"field_type": "<field_type>",
"field_format": "<field_format>"
}
]
}
The fields object from this response can be used to update the field mapping.
<original_csv_column_name> needs to be left untouched - the actual field name from CSV header
<table_column_display_name> is users's desired display name for the final table's column ( will be transformed into "snake_case" for the field_name)
<field_type> should be one of int, float, text, date, enum. In case of enum, during import all values from this column will be mapped as choices into the field.
<field_format> is used and required only for field_type=date, and should be a python datetime format string ( E.g: %d.%m.%Y for a date like 11.05.1989)
POST /tables/{id}/csv-import/{csv_import_pk}/
{csv_import_pk} is the id returned by csv-prepare-fields
{
"fields": [
{
"original_name": "<original_csv_column_name>",
"field_name": "<table_column_display_name>",
"field_type": "<field_type>",
"field_format": "<field_format>"
}
]
}
{
"errors_count": <errors_count>,
"imports_count": <imports_count>,
"errors": [
{
"row": {
"<csv_field_name>": "<csv_field_value>",
},
"errors": {
"<csv_field_name>": "<error_type>"
}
}
]
}
This method will actually do the csv import using the mapped field types. In case of errors, these will be present in the errors key.
<error_type> will specify what kind of error occured (ValueError for wrong field format or type)