Strapi Plugin Import Export Entries
Import/Export data from and to your database in just few clicks.
Features
Import
- Import data directly from the Content Manager
- Import data from CSV and JSON file or from typing raw text according to user permissions
- Import contents to collection type (NOT single type yet)
Export
- Export data directly from the Content Manager
- Export CSV and JSON contents according to user permissions
- Download files or copy exported data to clipboard
- Filter & sort data using Content Manager filters & sorting
Screenshots
Table Of Content
Requirements
Strapi v4 is required.
Installation
- Download
yarn add strapi-plugin-import-export-entries
or
npm i strapi-plugin-import-export-entries
- Enable the plugin
Add in the file config/plugins.js
:
module.exports = ({ env }) => ({
//...
"import-export-entries": {
enabled: true,
},
//...
});
- Update the config of the
security
middleware:
The security
middleware needs to be configured to enable the use of the great Monaco code editor.
In the file config/middlewares.js
, replace:
module.exports = [
//...
"strapi::security",
//...
];
with
module.exports = ({ env }) => ({
//...
{
name: "strapi::security",
config: {
contentSecurityPolicy: {
useDefaults: true,
directives: {
// Enable the download of the Monaco editor
// from cdn.jsdelivr.net.
"script-src": ["'self'", "cdn.jsdelivr.net", "blob:"],
upgradeInsecureRequests: null,
},
},
},
},
//...
});
Rebuild The Admin Panel
New releases can introduce changes to the administration panel that require a rebuild. Rebuild the admin panel with one of the following commands:
yarn build --clean
or
npm run build --clean
Usage
Once the plugin is installed and setup, the functionnalities are accessible on the content management page of a collection.
Import Example
Let's consider some data that represents yoga courses. We have a course
table where each course
refers to a beautiful_place
(stored in the beautiful_place
table).
Here we are importing the following 3 entries to the course
table.
CSV data
"id","type","beautiful_place","description","name","createdAt","updatedAt","createdBy","updatedBy"
"1","vinyasa","{""id"":2,""name"":""Machu Picchu"",""description"":""The strength of the Incas with the chill of the alpacas."",""createdAt"":""2022-06-06T21:51:45.787Z"",""updatedAt"":""2022-06-06T21:51:45.787Z"",""locale"":""en""}","All you need is your mat and an Alpaca.","Alpaca Flow","2022-06-06T21:52:34.046Z","2022-06-06T21:52:34.046Z","{""id"":1,""firstname"":""Patrick"",""lastname"":""Beach"",""username"":null,""email"":""[email protected]"",""password"":""$2a$10$iUGfsRyOQJ3h.mss2xwgmu42UBtOkLsyX8MxpCRAOlDSHq2/IZlRu"",""resetPasswordToken"":null,""registrationToken"":null,""isActive"":true,""blocked"":false,""preferedLanguage"":null,""createdAt"":""2022-05-23T19:16:33.057Z"",""updatedAt"":""2022-06-06T21:43:12.901Z""}","{""id"":1,""firstname"":""Patrick"",""lastname"":""Beach"",""username"":null,""email"":""[email protected]"",""password"":""$2a$10$iUGfsRyOQJ3h.mss2xwgmu42UBtOkLsyX8MxpCRAOlDSHq2/IZlRu"",""resetPasswordToken"":null,""registrationToken"":null,""isActive"":true,""blocked"":false,""preferedLanguage"":null,""createdAt"":""2022-05-23T19:16:33.057Z"",""updatedAt"":""2022-06-06T21:43:12.901Z""}"
"2","ashtanga","{""id"":1,""name"":""Boracay White Beach"",""description"":""Sea, Stretch and Sun!"",""createdAt"":""2022-06-06T21:49:35.227Z"",""updatedAt"":""2022-06-06T21:53:56.648Z"",""locale"":""en""}","Head in the stars, feet in the sand.","Sun Salutation","2022-06-06T21:55:35.088Z","2022-06-06T21:55:35.088Z","{""id"":1,""firstname"":""Patrick"",""lastname"":""Beach"",""username"":null,""email"":""[email protected]"",""password"":""$2a$10$iUGfsRyOQJ3h.mss2xwgmu42UBtOkLsyX8MxpCRAOlDSHq2/IZlRu"",""resetPasswordToken"":null,""registrationToken"":null,""isActive"":true,""blocked"":false,""preferedLanguage"":null,""createdAt"":""2022-05-23T19:16:33.057Z"",""updatedAt"":""2022-06-06T21:43:12.901Z""}","{""id"":1,""firstname"":""Patrick"",""lastname"":""Beach"",""username"":null,""email"":""[email protected]"",""password"":""$2a$10$iUGfsRyOQJ3h.mss2xwgmu42UBtOkLsyX8MxpCRAOlDSHq2/IZlRu"",""resetPasswordToken"":null,""registrationToken"":null,""isActive"":true,""blocked"":false,""preferedLanguage"":null,""createdAt"":""2022-05-23T19:16:33.057Z"",""updatedAt"":""2022-06-06T21:43:12.901Z""}"
"3","vinyasa","{""id"":2,""name"":""Machu Picchu"",""description"":""The strength of the Incas with the chill of the alpacas."",""createdAt"":""2022-06-06T21:51:45.787Z"",""updatedAt"":""2022-06-06T21:51:45.787Z"",""locale"":""en""}","This place needs some serious renovation. Let's do it.","Inca Strength Journey","2022-06-06T21:58:39.571Z","2022-06-06T21:58:39.571Z","{""id"":1,""firstname"":""Patrick"",""lastname"":""Beach"",""username"":null,""email"":""[email protected]"",""password"":""$2a$10$iUGfsRyOQJ3h.mss2xwgmu42UBtOkLsyX8MxpCRAOlDSHq2/IZlRu"",""resetPasswordToken"":null,""registrationToken"":null,""isActive"":true,""blocked"":false,""preferedLanguage"":null,""createdAt"":""2022-05-23T19:16:33.057Z"",""updatedAt"":""2022-06-06T21:43:12.901Z""}","{""id"":1,""firstname"":""Patrick"",""lastname"":""Beach"",""username"":null,""email"":""[email protected]"",""password"":""$2a$10$iUGfsRyOQJ3h.mss2xwgmu42UBtOkLsyX8MxpCRAOlDSHq2/IZlRu"",""resetPasswordToken"":null,""registrationToken"":null,""isActive"":true,""blocked"":false,""preferedLanguage"":null,""createdAt"":""2022-05-23T19:16:33.057Z"",""updatedAt"":""2022-06-06T21:43:12.901Z""}"
Or the JSON equivalent:
JSON data
[
{
"id": 1,
"type": "vinyasa",
"description": "All you need is your mat and an Alpaca.",
"name": "Alpaca Flow",
"createdAt": "2022-06-06T21:52:34.046Z",
"updatedAt": "2022-06-06T21:52:34.046Z",
"beautiful_place": {
"id": 2,
"name": "Machu Picchu",
"description": "The strength of the Incas with the chill of the alpacas.",
"createdAt": "2022-06-06T21:51:45.787Z",
"updatedAt": "2022-06-06T21:51:45.787Z",
"locale": "en"
},
"createdBy": {
"id": 1,
"firstname": "Patrick",
"lastname": "Beach",
"username": null,
"email": "[email protected]",
"password": "$2a$10$iUGfsRyOQJ3h.mss2xwgmu42UBtOkLsyX8MxpCRAOlDSHq2/IZlRu",
"resetPasswordToken": null,
"registrationToken": null,
"isActive": true,
"blocked": false,
"preferedLanguage": null,
"createdAt": "2022-05-23T19:16:33.057Z",
"updatedAt": "2022-06-06T21:43:12.901Z"
},
"updatedBy": {
"id": 1,
"firstname": "Patrick",
"lastname": "Beach",
"username": null,
"email": "[email protected]",
"password": "$2a$10$iUGfsRyOQJ3h.mss2xwgmu42UBtOkLsyX8MxpCRAOlDSHq2/IZlRu",
"resetPasswordToken": null,
"registrationToken": null,
"isActive": true,
"blocked": false,
"preferedLanguage": null,
"createdAt": "2022-05-23T19:16:33.057Z",
"updatedAt": "2022-06-06T21:43:12.901Z"
}
},
{
"id": 2,
"type": "ashtanga",
"description": "Head in the stars, feet in the sand.",
"name": "Sun Salutation",
"createdAt": "2022-06-06T21:55:35.088Z",
"updatedAt": "2022-06-06T21:55:35.088Z",
"beautiful_place": {
"id": 1,
"name": "Boracay White Beach",
"description": "Sea, Stretch and Sun!",
"createdAt": "2022-06-06T21:49:35.227Z",
"updatedAt": "2022-06-06T21:53:56.648Z",
"locale": "en"
},
"createdBy": {
"id": 1,
"firstname": "Patrick",
"lastname": "Beach",
"username": null,
"email": "[email protected]",
"password": "$2a$10$iUGfsRyOQJ3h.mss2xwgmu42UBtOkLsyX8MxpCRAOlDSHq2/IZlRu",
"resetPasswordToken": null,
"registrationToken": null,
"isActive": true,
"blocked": false,
"preferedLanguage": null,
"createdAt": "2022-05-23T19:16:33.057Z",
"updatedAt": "2022-06-06T21:43:12.901Z"
},
"updatedBy": {
"id": 1,
"firstname": "Patrick",
"lastname": "Beach",
"username": null,
"email": "[email protected]",
"password": "$2a$10$iUGfsRyOQJ3h.mss2xwgmu42UBtOkLsyX8MxpCRAOlDSHq2/IZlRu",
"resetPasswordToken": null,
"registrationToken": null,
"isActive": true,
"blocked": false,
"preferedLanguage": null,
"createdAt": "2022-05-23T19:16:33.057Z",
"updatedAt": "2022-06-06T21:43:12.901Z"
}
},
{
"id": 3,
"type": "vinyasa",
"description": "This place needs some serious renovation. Let's do it.",
"name": "Inca Strength Journey",
"createdAt": "2022-06-06T21:58:39.571Z",
"updatedAt": "2022-06-06T21:58:39.571Z",
"beautiful_place": 2,
"createdBy": {
"id": 1,
"firstname": "Patrick",
"lastname": "Beach",
"username": null,
"email": "[email protected]",
"password": "$2a$10$iUGfsRyOQJ3h.mss2xwgmu42UBtOkLsyX8MxpCRAOlDSHq2/IZlRu",
"resetPasswordToken": null,
"registrationToken": null,
"isActive": true,
"blocked": false,
"preferedLanguage": null,
"createdAt": "2022-05-23T19:16:33.057Z",
"updatedAt": "2022-06-06T21:43:12.901Z"
},
"updatedBy": {
"id": 1,
"firstname": "Patrick",
"lastname": "Beach",
"username": null,
"email": "[email protected]",
"password": "$2a$10$iUGfsRyOQJ3h.mss2xwgmu42UBtOkLsyX8MxpCRAOlDSHq2/IZlRu",
"resetPasswordToken": null,
"registrationToken": null,
"isActive": true,
"blocked": false,
"preferedLanguage": null,
"createdAt": "2022-05-23T19:16:33.057Z",
"updatedAt": "2022-06-06T21:43:12.901Z"
}
}
]
The import will produce the following result:
-
For the 1st entry:
- Find the relation
beautiful_place
with id2
.
If it exists in db, the relation entry is updated in db with the imported data. If it doesn't, the relation entry is created in db with the imported data. - Update the
createdBy
andupdatedBy
fields with the id of the user importing the data. - Create the
course
with the rightbeautiful_place
id.
- Find the relation
-
For the 2nd entry: same process
-
For the 3rd entry:
- The relation
beautiful_place
is a number. Since the relation already exists in db, thecourse
will be linked to the rightbeautiful_place
. If the number was referring to the id of a non existentbeautiful_place
, the relation would fallback tonull
. - Same last 2 steps as the 1st entry.
- The relation
Author
Baboo - @Baboo7
Acknowledgments
This plugin (and especially this README) took strong inspiration from the strapi-plugin-import-export-content from EdisonPeM.