/CSV-to-Drupal

Example code for parsing a local CSV file and importing the data into Drupal via JsonApi

Primary LanguageJavaScript

Example CSV import into Drupal

This is just some example code for taking a local CSV file and importing each row as a node into Drupal.

Setup

  1. Ensure Drupal is ready to import data.

On the drupal site be sure to have the JSON:API and HTTP Basic Authentication modules enabled.

Then on the JsonAPI config page /admin/config/services/jsonapi, "Accept all JSON:API create, read, update, and delete operations." needs to be selected.

  1. Installation of Node.js packages.
npm install
  1. Edit the index.js file to reflect your custom info.

Change variable values for the CSV file location, Url, Username/Password, and Drupal Entity Type.

Add any Fields needed by the Drupal entity into the prepareNodes() function.

Running the Import

  1. Test the CSV parsing.
npm test
  1. Import the files into Drupal.
npm start