FeedPupSupplier sync made simple

Magento 2 · CSV automation guide

Magento 2 import CSV programmatically

Magento's admin import is fine for a one-off file. When a supplier updates prices and stock every day, you need a repeatable import. This guide covers the real Magento 2 code paths, the CSV columns that matter, and where Dataflow fits.

Quick answerMagento 2 does not expose a public “CSV import” REST endpoint. Automate imports through the Magento\ImportExport\Model\Import class in a custom CLI command or cron job, or send products through the product REST/bulk API. Dataflow is Magento 1 legacy and is not part of Magento 2.

The CSV Magento 2 expects

Start from a known-good export: System → Data Transfer → Export, choose Products, and use that file as the template. The minimum useful columns are:

ColumnWhy it matters
skuUnique product identity. The importer updates an existing SKU or creates a new one.
nameProduct name shown in the catalog.
attribute_set_codeMust match an existing attribute set, usually Default.
product_typesimple, configurable, virtual and so on.
priceBase price, without currency symbols.
qty, is_in_stockInventory and availability.
websites, visibilityWithout these, the product may import but never appear in the storefront.
category_idsComma-separated category IDs, not category names.
image, small_image, thumbnailImage paths relative to pub/media/import/, or URLs depending on your import settings.

Option 1: automate the built-in importer

The built-in importer is the Magento\ImportExport\Model\Import class. A custom CLI command keeps the same validation, behavior modes and error reporting as the admin screen. The exact command name varies by Magento version; check bin/magento list for import commands, or add your own command.

<?php
use Magento\ImportExport\Model\Import;
use Magento\ImportExport\Model\ImportFactory;

final class SupplierImport
{
    public function __construct(
        private ImportFactory $importFactory,
        private \Magento\Framework\Filesystem $filesystem
    ) {}

    public function run(string $file, string $behavior = Import::BEHAVIOR_APPEND): array
    {
        $import = $this->importFactory->create();
        $import->setData([
            'entity' => 'catalog_product',
            'behavior' => $behavior,
            'import_images_file_dir' => 'pub/media/import',
            'import_field_mapping' => [],
        ]);

        $source = $import->getImportSource()->setData([
            'file_path' => $file,
        ]);

        $result = $import->validateSource($source->getSource());
        if (!$result) {
            return $import->getErrorAggregator()->getAllErrors();
        }

        $import->importSource();
        $import->invalidateIndex();

        return $import->getErrorAggregator()->getAllErrors();
    }
}

Run it from a cron job or a custom bin/magento command. Keep the file in var/import/ or another writable path, and log the error aggregator so a failed row is visible instead of silent.

Option 2: REST API and bulk endpoints

If your source system can send JSON, skip CSV entirely. The product API accepts one product per call, and Magento 2.4 adds asynchronous bulk endpoints for larger batches:

# single product
POST /rest/V1/products
Content-Type: application/json

# asynchronous bulk
POST /rest/async/bulk/V1/products
Content-Type: application/json

[{"product":{"sku":"SKU-1","name":"Chair","price":49.9,"attribute_set_id":4,"status":1,"visibility":4}}]

Bulk endpoints return a batch ID; poll the bulk status endpoint, then reindex. This is a good fit for a PIM or ERP that already emits JSON. For supplier XML feeds, FeedPup handles the mapping and sends the products to Magento without writing a custom importer.

What about Magento Dataflow import?

Dataflow was the Magento 1 import framework: profiles, adapters and a browser-run data flow. Magento 2 replaced it with the ImportExport module and the System → Data Transfer → Import screen. If a guide mentions Dataflow profiles, it is for Magento 1 and will not work on Magento 2. The modern equivalents are the ImportExport model, the admin import and the REST bulk API.

Common Magento CSV import errors

SymptomLikely causeFix
“SKU is not unique”Duplicate rows in one fileDeduplicate by SKU before importing.
Product imports but is invisiblewebsites or visibility is emptySet the website code and visibility (catalog, search, both).
Attribute set not foundWrong attribute_set_codeExport a product and copy its exact attribute set code.
Images missingPath not under pub/media/import/ or URL import disabledUse the correct relative path or enable image URL import.
Prices or stock do not changeWrong behavior or stale indexUse append/replace deliberately, then reindex.
Rows report “invalid value”Attribute code from another attribute setImport the attribute first or remove the unknown column.

When supplier feeds make the CSV manual

A CSV import assumes you already have the right file. A supplier feed is usually XML, changes without notice and uses different field names. Converting it to Magento CSV by hand defeats the point of automation. FeedPup reads XML or CSV, suggests field mappings, lets you review sample values, and can create a small set of disabled draft products before a larger run. It also handles the supplier-specific parts: variants, images and scheduled price/stock checks.

See the Magento 2 supplier XML guide for the end-to-end connection and a verified Magento Open Source 2.4.8 walkthrough.

Import a supplier feed without writing an importer

Connect XML or CSV, review the mapping, test up to 100 draft products.

Try FeedPup free ↗

Magento 2 CSV import FAQ

Does Magento 2 have a REST endpoint for CSV import?

No. REST works with product payloads, not CSV files. Use the ImportExport model in a custom command or cron job, or send products through the product REST/bulk API.

What happened to Magento Dataflow import?

Dataflow was the Magento 1 import framework. Magento 2 uses the ImportExport module and the admin Data Transfer screen. Magento 1 Dataflow guides do not apply to Magento 2.

Can I import configurable products from CSV?

Yes, but it takes multiple rows: the configurable parent plus each simple child variant, with the association columns Magento expects. Export a configurable product first and use that structure.

How do I keep supplier prices and stock updated?

Re-run the import on a schedule, or use FeedPup's scheduled supplier sync where available for your account and integration. Review the run history after each sync.

Do I need to reindex after an import?

Usually yes for price, stock and catalog search. The importer can invalidate indexes; run bin/magento indexer:reindex or let cron process them.