Import / export data
Node.js version: 8.9.4 npm version: 5.6.0 Strapi version: latest Operating system: Windows 10
Do you want to request a feature or report a bug? request a feature
Is there a simple way to upload data from csv file? For example, I would like to create new API called "products" with couple of features (size, color and so on). I do not want to add entry by entry, but prefer to upload all the products from csv file.
Is that currently possible or I need to create a plugin/develop it by myself/etc?
@Jakku7 very good idea. I think import/export from/to CSV, JSON and some other general format can be very useful.
/CC: @lauriejim, @Aurelsicoko
Hi ! Actually the best way is to create a Short script that convert your CSV data in an array of JSON object and then to loop on and make await strapi.services.product.add(entryObject);
Or find a tools that make directly an import in your database.
@lauriejim; For users who are fresh to the node ecosystem, could you do explain how they would hook a script in and be able to use that await strapi.services.product.add(entryObject); successfully?
i'd like to bump this feature request. export and import with csv would be great
I also 2nd this, it would be extremely helpful to be able to dump data from csv in quickly (export would also be very helpful but I digress, stability > feature additions)
@derrickmehaffy @kitsunekyo Did you up-vote the feature on the vote page? We're currently working on the issues which are causing the feeling that Strapi is unstable. We need to stabilize all the work we've done during the last months to get back to the development new features then.
sure :) was just wondering how you'd propose us to maybe help building such features. as this is open source after all
feel free to close the issue though if the intent is to build this inhouse for you.
@Aurelsicoko If it were 'import existing data' instead of just CSV import, it would probably be ranked higher. Many of us know how convert our existing data to CSV and import, but others might only vote if they see more general terms.
@kitsunekyo @Joshfindit If you want to help us, feel free to reach me on Slack (@aureliengeorget), it would be a pleasure to discuss with you about this feature and how we could integrate it in the Content Manager plugin. The goal is to define what we want exactly and where we should implement it in the codebase and the UI.
+1 Import/export a resource or all app resources is significant feature in many projects. For example - cloning a base project backend.
Thanks to everyone for reminding us that you're waiting for this kind of features, I added it to my personal list of the important things to do to make Strapi a better product. I hope we will be able to release it this year πͺ
@Aurelsicoko This issue can probably be closed in favor of https://portal.productboard.com/strapi/c/23-import-export-data
@derrickmehaffy Thank you π
Don't hesitate to give us more insights... This feature is critical and we need to understand all the use cases to build it correctly (https://portal.productboard.com/strapi/c/23-import-export-data).
I'd like to second that. End-clients like to have the ability to export their data for use in other CRMs. I believe keystoneJS has this out the box, so I think it would be good to follow suit on this!
For one-time export I used something like that:
const _ = require('lodash');
const request = require('request');
const parse = require('csv-parse');
var strapi = require('strapi')();
var fs = require('fs');
// const remoteLink = "..."
const localFile = "./data.csv"
async function fetchData() {
return new Promise( resolve => {
data = []
header = null;
// source = request(remoteLink)
source = fs.createReadStream(localFile)
source.pipe(parse()).on('data', (row) => {
if(!header) { header = row; return; }
row = row.map(item=>item=='N/A' ? '' : item);
data.push(_.zipObject(header, row))
}).on('end', () => {
resolve(data);
});
});
}
async function initStrapi() {
await strapi.load();
await strapi.runBootstrapFunctions();
return strapi;
}
async function main() {
var [strapi, data] = await Promise.all([initStrapi(),fetchData()])
for(var i=0;i<data.length;i++) {
await strapi.services.shop.create(data[i]);
}
}
main()
How kind of you! Thank you so very much!
Prior to this, my workaround was to export directly from the the database I prefer this solution because I can wire it to a custom button on the dashboard!
On Jul 8, 2019, at 8:08 PM, Pavel Razumovskiy [email protected] wrote:
For one-time export I used something like that:
const _ = require('lodash'); const request = require('request'); const parse = require('csv-parse'); var strapi = require('strapi')(); var fs = require('fs');
// const remoteLink = "..." const localFile = "./data.csv"
async function fetchData() { return new Promise( resolve => { data = [] header = null; // source = request(remoteLink) source = fs.createReadStream(localFile) source.pipe(parse()).on('data', (row) => { if(!header) { header = row; return; } row = row.map(item=>item=='N/A' ? '' : item); data.push(_.zipObject(header, row)) }).on('end', () => { resolve(data); }); }); }
async function initStrapi() { await strapi.load(); await strapi.runBootstrapFunctions(); return strapi; }
async function main() { var [strapi, data] = await Promise.all([initStrapi(),fetchData()]) for(var i=0;i<data.length;i++) { await strapi.services.shop.create(data[i]); } } main() β You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/strapi/strapi/issues/744?email_source=notifications&email_token=ABLSSB7ZP3Q2NONMFUKSKPTP6PJI7A5CNFSM4ETUKFR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZOWLEA#issuecomment-509437328, or mute the thread https://github.com/notifications/unsubscribe-auth/ABLSSB6H6VWY47JLPLDA4MTP6PJI7ANCNFSM4ETUKFRQ.
Hi Everyone, I was looking for something similar and stumbled upon this plugin someone has written that seems to do the job.
https://github.com/jbeuckm/strapi-plugin-import-content
Note @JStyle21 that plugin was built for the alpha and may not work with the beta.
Thanks for pointing that out @derrickmehaffy , but it still should be easier to redo than do it from scratch or wait for this feature to be added.