-

How to Import Product or Blog Post Data into Drupal from CSV Files? Step by Step

In this article, I'll show you how to import data from CSV files into Drupal. This is often a step in creating a new website, and the solutions shown here will come in handy when transferring data from an old system to a new one. I’ll also demonstrate how to handle such a situation using the Feeds module and its Feeds Tamper extension and walk you through importing data using three types of data as examples: products, users, and blog posts.

You'll see how easy it is to move content into Drupal by mapping the data accordingly and how to manipulate the data with the available modules to customize it to your needs easily.
I encourage you to read the article or watch the episode of the “Nowoczesny Drupal” series (the video is in Polish), where I show you all the steps one by one.

Drupal Feeds module - what is it and how does it work?

The Feeds module allows us to import data from various formats, such as CSV, JSON, XML, and RSS. It lets us easily move large amounts of data into Drupal, which is especially useful when migrating from older systems or integrating Drupal with external data sources.

In this post, we’ll also use the Feeds Tamper module, which extends Feeds' capabilities by allowing us to manipulate the data we import into Drupal. For example, we can split fields, remove unnecessary characters, and modify data structures, giving us complete control over how the data will end up in the system. Feeds Tamper is a key tool when data is inconsistent or needs additional processing before it can be imported.

Together, these two modules - Feeds and Feeds Tamper - create a very flexible and robust solution that makes it easy to work with data in Drupal.

The Feeds module allows you to import data into Drupal from various formats, such as a CSV file.


These modules have already been installed on my system, so let's proceed with a step-by-step demo of the import process and how to use them.

Importing products from a CSV file

We have our sample CSV file, which contains columns with the following data:

  • Title - product name,
  • Category - product category,
  • Description - product description,
  • Tags - tags related to the product,
  • Photos - ID of photos that we previously imported into Drupal media.
     

An example of a simple CSV file with products prepared for the data import into Drupal.


Now, let's move on to Drupal. I'll show examples of the Droopler distribution (it already has content types such as "Product," which has a title, image, content, categories, and tags).

If we have the Feeds module installed, we can find Feeds Type in the menu in the structure and add new Feeds for ourselves.

Configuring the Drupal Feeds module

  1. We go to the "Structure" tab and select "Feeds Type."
  2. We add a new type, "Feeds," and name it "Products."
  3. We set up Fetcher, where we select "Data Source" - "CSV" and specify the type of data we want to import, that is, "Node" and content type "Product."
  4. We configure the Parser so that the data is separated by a comma.
  5. We set the Processor, which will update the existing data the next time the file is imported.
Adding a feed type when configuring the Feeds module in Drupal.


We save the changes and proceed to mapping.

Field mapping for products

A crucial part of the import is mapping fields from the CSV file to corresponding fields in Drupal. This process involves assigning data from CSV columns to specific fields in the content type, such as title, category, content, tags, or images.

Mapping fields for products imported from a CSV file into Drupal is a simple operation.


Here, we have a default list of fields, which the module provides us with, from a given content type for a product. Let's select "Title."

In field mapping, to import product data into Drupal, you need to include a field with a title.


Next, we select the source, i.e., a column from the CSV with the name "title." We select that it’s unique so that we can recognize and update products by it later (in the future, we can change this to ID or product ID).

One element of field mapping in product import is selecting the source from the CSV file.


Then, we select the "Category" field and assign a column with the category name. We can immediately use the field with a reference. Here, I’ll show the example of "name."

A form in Drupal visible while mapping fields according to a CSV file.


Next, we can check the Autocreate option to have Drupal automatically create new categories if they don’t exist in the system.

The following steps are to set tags, media, and descriptions:

  1. Tags: we assign the "Tags" field to the tags column in the CSV file.

If the tags are separated by a semicolon, we can use the Feeds Tamper module to split them into separate entries.

  1. Photos: we assign the "Photos" field to the corresponding media IDs in Drupal.

It’s important to import photos into the system beforehand because the Drupal Feeds module assigns photos based on their ID.

  1. Description: we assign the "Description" field to the corresponding column containing the content of the product description.
    Setting tags, media, and descriptions in Drupal to match data in a CSV file.


Importing data

Once we’ve finished mapping the fields, we can proceed to import the data.

  1. We go to the "Content" tab -> "Feeds."
  2. We click "Add a new channel" and select the Feeds type "Products."
  3. We select the CSV file with the product data and click "Import."
  4. Once it's done, Drupal will let us know the number of imported products. In this example, we received information that two products were imported.

    A message in Drupal indicating that two products were correctly created from a CSV data import.


If tags or other data have been imported incorrectly, we can use the Feeds Tamper module to manipulate the data - for example, to separate tags based on the separator.

Feeds Tamper - when is it worth using?

In some cases, data requires additional processing to be imported correctly into Drupal. This is where the Feeds Tamper module becomes essential, as it allows you to modify the data before importing it.

To use Feeds Tamper, we go to the "Structure" tab, then select our Feeds type, for example, "Products." Here, we can add various data manipulation options for individual fields. Feeds Tamper offers many tools, such as the use of regular expressions (regex) or the explode function, which allows us to separate data based on a specific separator.

For example, for the "Tags" field, which is separated by a semicolon in the CSV file, we can add an explode operation to separate the tags into separate entries. For the "Photos" field, where photos are separated by a comma, we set the appropriate data manipulation so that Drupal can correctly recognize each photo. After applying these operations, we return to the import process and continue it, being sure that the data will be correctly imported and assigned to the appropriate fields.

Manipulating data in this way is extremely useful when the data is complex or needs to be transformed to fit Drupal's structure.

Importing users from a CSV file

Now, let's move on to importing users. Our CSV file contains data such as:

  • E-mail - the user's e-mail address,
  • Username - user login,
  • Role - the role assigned to the user,
  • Status - whether the user is active or not in the CMS.

We go once again to the "Structure" tab - > "Feeds Type" and add a new import type named "Users." We choose "Data Source - CSV" and data type "Users." In the processor settings, we select "Update existing users" to avoid duplicates.

The step of importing user data from a CSV file into Drupal using the Feeds module.


We’ll be updating existing users, so we’re moving on to mapping.

Field mapping for users

When importing users, we have fewer fields to map:

  1. Email: we assign an e-mail column to the "E-mail" field in Drupal. This field must be unique because each user must have a unique email address.
  2. User name: we assign the user name to the corresponding column.
  3. Role: we assign a role to the user role column. We can choose whether we want to assign the role based on label or ID.
  4. Status: we assign a status that determines whether the user is active or blocked.
The process of mapping fields for users when importing from a CSV file into Drupal.


At this point, we have two "Feed Types": "product" and "users." We’ll take care of importing users.

Importing users

We go to the "Content" tab -> "Feeds." We add a new channel for users, select the CSV file and click "Import."

Adding a new user feed in Drupal using the Feeds module for import.


Once the process is complete, we check that users have been correctly added with the correct roles and statuses.

Verifying that user data has been correctly added to the Drupal system from CSV.


As you can see, importing users into the Content Management System is simple and can be done quickly.

Importing blog posts from a CSV file

The last example is importing blog content. As with products and users, we use a CSV file containing the following fields:

  • Title - we assign the title of the blog,
  • Teaser - we introduce a summary of the content,
  • Content - we assign content to the corresponding paragraph in Drupal (full HTML),
  • Photos - we map photos based on the ID from the CSV,
  • Category - add a category based on the name, and the system will automatically create new categories if they don’t exist.

    Importing the content of a blog article into Drupal from a CSV file containing the relevant columns.


Configure the Drupal Feeds module for blog posts

Under "Structure" -> "Feeds Type" we add a new import type, which we’ll call "Blog posts."

Configuring the Drupal Feeds module for importing blog articles from a CSV file.


This is an import from a CSV file into a node that will fall into blog posts.

Drupal settings screen, showing the import of articles from a CSV file into the corresponding node.


As in the case of products and users, we assign ourselves these fields, then set the data and select the blog category. Next, we refer by name and new categories are created.

Save. Then we go to create a new Feed, a new channel. We already have the blog posts.

At the very end, we select a file for ourselves and import it. When the import is complete, we see that the blog posts are correctly imported, with correctly assigned categories and images.

A message in Drupal indicating that three blog articles have been correctly imported from CSV.


All items are displayed correctly; we can also see in the listing that everything looks nice.

The created website in Drupal with imported blog posts from a CSV file with the Feeds module.


Importing data into Drupal - summary

The Feeds module and the Feeds Tamper extension are comprehensive tools that make it easy to manage large amounts of data. With them, we can automate the process of migrating and importing content, which saves a lot of time and work. Whether we are importing products, users, or blog posts, we can customize the process by mapping data from a CSV file to the appropriate fields in Drupal.

Key steps in the import process:

  • Configuring the Feeds module: specify the data source and content type and set the parser and processor to process the data as required.
  • Field mapping: assigning columns from the CSV file to the corresponding fields in Drupal, which allows for an accurate representation of the data structure.
  • Data manipulation with Feeds Tamper: the ability to transform data before import (e.g., separating tags or handling multimedia), which is extremely useful for more complex data formats.

It's worth remembering that the Feeds Tamper module allows additional control over imported data, which is especially useful when the data needs to be adjusted - for example, when tags are stored in a single field or images are separated by commas.

If you’re planning to migrate your data to Drupal or manage a large amount of content, the Feeds module and its extension are indispensable tools that will allow you to automate many processes, avoid errors, and save valuable time. What's more, the ability to update existing data makes the process efficient and flexible. Do you need further assistance with these processes? Our Drupal agency experts can help you optimize your work with this CMS.  

migrate Drupal 7 website Droptica