Import Export Plugin
This plugin adds features that give admin users the ability to download or create export data as an upload collection and import it back into a project.
Core Features
- Export data as CSV or JSON format via the admin UI
- Download the export directly through the browser
- Create a file upload of the export data
- Use the jobs queue for large exports
- (Coming soon) Import collection data
Installation
Install the plugin using any JavaScript package manager like pnpm, npm, or Yarn:
Basic Usage
In the plugins
array of your Payload Config, call the plugin with options:
Options
Property | Type | Description |
---|---|---|
| string[] | Collections to include Import/Export controls in. Defaults to all collections. |
| boolean | If true, enables debug logging. |
| boolean | If true, disables the download button in the export preview UI. |
| boolean | If true, forces the export to run synchronously. |
| boolean | If true, disables the save button in the export preview UI. |
| string | Forces a specific export format ( |
| function | Function to override the default export collection; takes the default export collection and allows you to modify and return it. |
Field Options
In addition to the above plugin configuration options, you can granularly set the following field level options using the custom['plugin-import-export']
properties in any of your collections.
Property | Type | Description |
---|---|---|
| boolean | When |
| function | Custom function used to modify the outgoing csv data by manipulating the data, siblingData or by returning the desired value. |
Customizing the output of CSV data
To manipulate the data that a field exports you can add toCSV
custom functions. This allows you to modify the outgoing csv data by manipulating the data, siblingData or by returning the desired value.
The toCSV function argument is an object with the following properties:
Property | Type | Description |
---|---|---|
| string | The CSV column name given to the field. |
| object | The top level document |
| object | The object data that can be manipulated to assign data to the CSV |
| object | The document data at the level where it belongs |
| unknown | The data for the field. |
Example function:
Exporting Data
There are four possible ways that the plugin allows for exporting documents, the first two are available in the admin UI from the list view of a collection:
- Direct download - Using a
POST
to/api/exports/download
and streams the response as a file download - File storage - Goes to the
exports
collection as an uploads enabled collection - Local API - A create call to the uploads collection:
payload.create({ slug: 'uploads', ...parameters })
- Jobs Queue -
payload.jobs.queue({ task: 'createCollectionExport', input: parameters })
By default, a user can use the Export drawer to create a file download by choosing Save
or stream a downloadable file directly without persisting it by using the Download
button. Either option can be disabled to provide the export experience you desire for your use-case.
The UI for creating exports provides options so that users can be selective about which documents to include and also which columns or fields to include.
It is necessary to add access control to the uploads collection configuration using the overrideExportCollection
function if you have enabled this plugin on collections with data that some authenticated users should not have access to.
The following parameters are used by the export function to handle requests:
Property | Type | Description |
---|---|---|
| text | Either |
| number | The max number of documents to return |
| select | The field to use for ordering documents |
| string | The locale code to query documents or |
| string | Either |
| string[] | Which collection fields are used to create the export, defaults to all |
| string | The slug to query against |
| object | The WhereObject used to query documents to export. This is set by making selections or filters from the list view |
| text | What to call the export being created |