strapi icon indicating copy to clipboard operation
strapi copied to clipboard

Import / export data

Open Jakku7 opened this issue 8 years ago β€’ 43 comments

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 avatar Mar 05 '18 19:03 Jakku7

@Jakku7 very good idea. I think import/export from/to CSV, JSON and some other general format can be very useful.

/CC: @lauriejim, @Aurelsicoko

mnlbox avatar Mar 06 '18 16:03 mnlbox

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 avatar Mar 15 '18 13:03 lauriejim

@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?

Joshfindit avatar Apr 18 '18 17:04 Joshfindit

i'd like to bump this feature request. export and import with csv would be great

kitsunekyo avatar Apr 23 '18 13:04 kitsunekyo

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 avatar Apr 23 '18 13:04 derrickmehaffy

@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.

Aurelsicoko avatar Apr 23 '18 16:04 Aurelsicoko

sure :) was just wondering how you'd propose us to maybe help building such features. as this is open source after all

kitsunekyo avatar Apr 23 '18 17:04 kitsunekyo

feel free to close the issue though if the intent is to build this inhouse for you.

kitsunekyo avatar Apr 23 '18 17:04 kitsunekyo

@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.

Joshfindit avatar Apr 23 '18 20:04 Joshfindit

@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.

Aurelsicoko avatar Apr 24 '18 08:04 Aurelsicoko

+1 Import/export a resource or all app resources is significant feature in many projects. For example - cloning a base project backend.

coolemur avatar Aug 29 '18 13:08 coolemur

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 avatar Sep 06 '18 09:09 Aurelsicoko

@Aurelsicoko This issue can probably be closed in favor of https://portal.productboard.com/strapi/c/23-import-export-data

derrickmehaffy avatar Nov 09 '18 21:11 derrickmehaffy

@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).

Aurelsicoko avatar Nov 11 '18 14:11 Aurelsicoko

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!

BriantAnthony avatar Jun 05 '19 00:06 BriantAnthony

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()

1um avatar Jul 09 '19 00:07 1um

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.

BriantAnthony avatar Jul 09 '19 00:07 BriantAnthony

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

JStyle21 avatar Jul 10 '19 23:07 JStyle21

Note @JStyle21 that plugin was built for the alpha and may not work with the beta.

derrickmehaffy avatar Jul 11 '19 05:07 derrickmehaffy

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.

JStyle21 avatar Jul 11 '19 06:07 JStyle21