I have an extension that works with product Ids instead of product SKUs for import for which i need to export product ids along with the SKUs to match the products. As far i have checked there is no option to export product entity_id from magento 2 backend and also the script examples available are with magento 1.9 or lower version. Please suggest if there i a way to accomplish this with custom coding or extension.


2 Answers 2


You may retrieve all of products via API.


use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';

$bootstrap = Bootstrap::create(BP, $_SERVER);

$objectManager = $bootstrap->getObjectManager();
$productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory')->create();


$csvFile = fopen('product_ids.csv', 'w');
fputcsv($csvFile, ['SKU', 'Product ID']);

foreach ($productCollection as $product) {
    fputcsv($csvFile, [$product->getSku(), $product->getId()]);


In this code, we're using the Product\CollectionFactory object to retrieve a collection of products. We then add the sku and entity_id attributes to the collection's selection. We iterate over the collection and write the SKU and product ID values to a CSV file.

Make sure to place this code in a PHP file, locate it in the root directory of your Magento installation, and run it from the command line or by accessing the file through a browser. The resulting CSV file will contain the exported SKUs and product IDs.

Remember to adjust the file permissions as needed and customize the export format according to your preferences.

I hope this meets your requirements!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.