Home / Shopware / Product Importing API

As an e-commerce platform, Shopware 6 offers a wide spectrum of features that enables the simple configuration of a shop. A basic part of a shop is invariably the product and its property.A product itself contains many specifications and fields that are required to be filled by the owner, which can also be confusing and frustrating

Since in a shop it is always expected to be a large number of products, insertion one by one throughout the platform can be troublesome and there’s a big possibility of problems occurring. The most optimal possibility is considered the insertion of products through the consumption of API.

The API will contain only the fields that are required to be completed, in which case it will save a lot of time.Consumption of API is best done through the use of the command in Shopware 6, where we do the insertion of all products in a much shorter period compared to the manual insertion.

Mandatory fields for inserting a product are:

• Title
• Product number
• Tax rate
• Price (gross and net)
• Stock

Keep in mind that if you decide to modify your product table, then the obligatory fields will be different, and this is not always recommended. Furthermore, the command should be the console command.

In Shopware 6, a console command is constructed by creating a file name that has to contain the word Command, in our case for example ProductInsertCommand.php.

The command has a default name ex. (API-product:insert) which is used when we run it. By the given default name, it is defined in the service.xml of the plugin, where we declare the class as a console command.

After this step, we run the command: bin/console API-product:insert. If the number of the products is in large quantities and they have images to be inserted, the process of insertion takes more time and it possibly needs to get run more than once because it sends us to a server timeout.

It is recommended that commands like this, should be implemented as cron jobs, since the process of product inserting is a continuous one. Another positive side of inserting the products by API is that it allows the user to make different modifications and conditioning based on their demands. Changing the price from the base price, like giving a discount or redefining the stock will be much easier by API product inserting.

So if you are in doubt about using the API to integrate the products, in most cases we suggest this as a go-to option, especially when the number of products is large. When you are dealing with a small number of products, you do not need to operate with API, you can do that by inserting them manually.

Arrange a free consultation now!