Magento CLI Commands: How to Run Product Import in Magento 2 from CLI

- Fire development, Magento 2

Magento 2 Development; Magento 2 tutorial

Welcome to our guide to Magento CLI commands. If you want to optimize your daily routine related to Magento 2 product import, you’ve come to the right place. Below, we shed light on several data transfer optimizations that will help you save tons of time spent on daily chores. Many merchants look for tips on importing products to Magento 2 using the command line interface. Below, you will find the easiest way to do so.

The following article is based on the StackExchange question by Massimo Camoni and the answer by Khoa TruongDinh. However, it extends the solution provided in the discussion. So, let’s see how to run Magento 2 product import via CLI. You will find the Magento 2 CLI commands list for importing and exporting products and other entities on your e-commerce website.

The StackExchange Approach to Magento CLI

According to Khoa TruongDinh, using CLI most efficiently, you cannot import products to Magento 2. Instead, he proposes to set up the Scheduled Import for the Commerce version under System > Data Transfer > Scheduled Imports/Exports. You can read more about the feature here: Data Scheduled Import Export. However, Adobe Commerce is not the only version of the platform. Its more popular variation is Magento 2 Open Source. And we’ve prepared a bunch of Magento CLI commands to import and export data for its users. 

The Improved Import Approach: Magento 2 CLI for Open Source

If you’re using the Open Source version, you should rely on third-party modules, such as the Improved Import & Export Magento 2 extension.

Our module fully supports cron enabling you to create any custom schedule of updates. There is no need to use CLI commands since everything can be configured within the extension’s backend in the most user-friendly manner.

You need to know the standard cron syntax to create a custom update schedule. Alternatively, you can select one of the predefined time intervals to run the update. Besides, you can still run product import asynchronously in manual mode using the corresponding CLI commands.

General extension settings

How to Run Product Import in Magento 2 from CLI

The default import tools of Magento 2 don’t let you use CLI. As you might have guessed, Improved Import & Export solves this problem. The extension allows you enable, disable, and start export processes from the Magento 2 CLI interface. Run the following Magento CLI commands in the Magento 2 root folder:

Also, check the Magento 2 CLI commands list for export:

Note that you have to create corresponding jobs for both import and export processes before using these CLI commands.

Magento CLI Import & Export FAQ

How to disable an import job via CLI in Magento 2?

Use the following command to disable an import job in Magento 2 via CLI:
php -f bin/magento import:job:COMMAND JOB_ID
import:job:disable

How to enable an import job via CLI in Magento 2?

Use the following command to enable an import job in Magento 2 via CLI:
php -f bin/magento import:job:COMMAND JOB_ID
import:job:enable

How to run an import job via CLI in Magento 2?

Use the following command to run an import job in Magento 2 via CLI:
php -f bin/magento import:job:COMMAND JOB_ID
import:job:run

How to disable an export job via CLI in Magento 2?

Use the following command to disable an export job in Magento 2 via CLI:
php -f bin/magento export:job:COMMAND JOB_ID
export:job:disable

How to enable an export job via CLI in Magento 2?

Use the following command to enable an export job in Magento 2 via CLI:
php -f bin/magento export:job:COMMAND JOB_ID
export:job:enable

How to run an export job via CLI in Magento 2?

Use the following command to run an export job in Magento 2 via CLI:
php -f bin/magento export:job:COMMAND JOB_ID
export:job:run

How to automate import and export processes in Magento 2?

Use the Improved Import & Export Magento 2 extension to automate both import and export processes in Magento 2. The module provides a cron scheduler where you can configure the frequency of automated data transfers.

How to import and export data with third-party attributes in Magento 2?

The Improved Import & Export Magento 2 extension provides a user-friendly mapping interface, where you can match all unsupported attributes to ones used in Magento 2. As a result, any third-party data is automatically transformed during import processes and effortlessly transferred into Magento 2. Furthermore, the same tool is suitable for export, working in the opposite direction. In this case, you show what data to use to replace the default Magento 2 attributes, generating the output your partners require.

Final Words

We hope the article was useful and now you can easily master Magento CLI commands for product import and export. Check our Cookbook for other Magento 2 tipsFor further information about the extension, contact us and follow this link:

Get Improved Import & Export Magento 2 Extension