This repository was archived by the owner on Sep 7, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
CSV module
kenn22 edited this page Sep 7, 2020
·
7 revisions
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
POST /api/csv-imports/
{
"file": <file_obj>,
"delimiter": ";"
}
{
"import_id": <import_id>,
"fields": [
{
"original_name": "<original_csv_column_name>",
"display_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 thefield_name) -
<field_type>should be one ofint,float,text,date,enum. In case ofenum, during import all values from this column will be mapped as choices into the field. -
<field_format>is used and required only forfield_type=date, and should be a python datetime format string ( E.g:%d.%m.%Yfor a date like11.05.1989)
POST /tables/
{
"database": <database_id>,
"name": "<table_name>",
"import_id": <csv_import_id>,
"fields": [
{
"original_name": "<original_csv_column_name>",
"display_name": "<table_column_display_name>",
"field_type": "<field_type>",
"field_format": "<field_format>"
}
]
}
<csv_import_id> is the id returned by csv-prepare-fields
{
"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 occurred (ValueError for wrong field format or type)
PUT /tables/{id}/csv-manual-import/
{
"file": <file_obj>,
"delimiter": ";"
}
{
"import_id": <import_id>,
"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 import the uploaded file into specified table, and will return the same response as previous method.
GET /csv-imports/{id}/export-errors/