# mod\_import\_csv

Source: https://zotonic.com/docs/1414/mod_import_csv

URI: https://zotonic.com/id/1414

Language: en



Module which adds “import CSV” button to the admin status screen.

The dropbox folder of the site is also watched for CSV or XLSX files.

To determine whether it can import a file, it uses a notification:

```erlang
#import_csv_definition{basename, filename}
```

If the notification is not returning anything, it tries to map the columns found in the first row of the CSV file to [resource](/id/doc_glossary#term-resource) column names. CSV/XLSX import module for admin-driven and watched-folder data imports.

Edge import
-----------

CSV files whose first three columns are `subject`, `predicate`, and `object` are imported as edge definitions instead of resources. The values in those columns are looked up as resource names: `subject` and `object` must name existing resources, and `predicate` must name an existing predicate resource.

An optional fourth column named `order` sets the edge sequence number. For example, a tab-separated file can contain:

```text
subject predicate object  order
page_a  author    person_a 1
```

The separator can be a tab or comma, depending on what is detected for the file.

Resource rows can also define edges by using column names that start with `>` or `<`. The text after the marker is the predicate name, and the cell value is the resource name on the other side of the edge.

- `> author` creates an outgoing edge from the imported row resource to the resource named in the cell.
- `< relation` creates an incoming edge from the resource named in the cell to the imported row resource.

For example:

```text
name   title    category  > author  < relation
page_b Page B   text      person_a   page_a
```

This creates `page_b --author--> person_a` and `page_a --relation--> page_b`.

Accepted Events
---------------

This module handles the following notifier callbacks:

- `observe_admin_menu`: Add menu item to 'Content' admin menu using `z_acl:is_allowed`.
- `observe_dropbox_file`: Import recognized CSV (including tab-separated) and XLSX files from the drop folder when an import definition matches.

Delegate callbacks:

- `event/2` with `submit` messages: `csv_upload`.

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/1414?language=en


## API access

- [API help](<https://zotonic.com/api-help>)
- [OpenAPI specification](<https://zotonic.com/openapi.json>)
- [This resource as JSON](<https://zotonic.com/api/agent/resource/1414?language=en>)
