How to get product ID and variant ID with bulk editor

Chad11
Shopify Partner
9 1 1

I am trying to get the ID of the products and variant to create a mini excel spreadsheet.  Is there anyway to grab these products IDs from the bulk editor?  How do I do it? 

Replies 28 (28)

Maris
Shopify Partner
319 5 71

Hi, Charles!

I am not sure if you are open to an app suggestion, but if you are - use the Excelify app to export your products and variants data to Excel - that will include also ID and Variant ID fields.

https://apps.shopify.com/excel-export-import

Maris
Excelify.io

Matrixify (Excelify) | Bulk Import Export Update Migrate | https://matrixify.app
kanishakgautam
Tourist
4 0 3

You can use shopify product id to read json and get product is and sku using below code : 

<?php 
 
ini_set('max_execution_time', 0); // for infinite time of execution 
 
for($i= 1 ;$i<26; $i++){
$pageurl = 'https://apikey:password@your-store.myshopify.com/admin/products.json?limit=250&page='.$i;
$data = json_decode(file_get_contents( $pageurl),true);
if(!empty($data['products'])){
foreach($data['products'] as $product){
$csv_data[] =array(
'Product ID '=>$product['id'],
'Sku'=>$product['variants'][0]['sku']
);
}
}
 }
if(!empty($csv_data)){
outputCsv('get-products-id.csv', $csv_data);
}
 
function outputCsv($fileName, $assocDataArray)
{
    ob_clean();
    header('Pragma: public');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Cache-Control: private', false);
    header('Content-Type: text/csv');
    header('Content-Disposition: attachment;filename=' . $fileName);    
    if(isset($assocDataArray['0'])){
        $fp = fopen('php://output', 'w');
        fputcsv($fp, array_keys($assocDataArray['0']));
        foreach($assocDataArray AS $values){
            fputcsv($fp, $values);
        }
        fclose($fp);
    }
    ob_flush();
}  
?>

 

ntiwari1309
Visitor
3 0 4

I am thinking to get around this issue as well. Basically, all I want is to include the product id and variant id of the products from the regular Shopify product export feature. And we are not going to use Excelify so that means I have to depend on the Shopify product export. It looks like a very straightforward request that Shopify product export should already have. Is there any free app that can include the product id and variant or maybe some other way within Shopify itself?

Matilda
Visitor
2 0 9

I just used EZ Exporter under the 7-day trial & it pulls down the 2 columns you mentioned in under 5 minutes for 210 products.  Mine is just a quick fix, but it fits the bill.  Has integration options if this is useful to you.  Cheers, M

 


@ntiwari1309 wrote:

I am thinking to get around this issue as well. Basically, all I want is to include the product id and variant id of the products from the regular Shopify product export feature. And we are not going to use Excelify so that means I have to depend on the Shopify product export. It looks like a very straightforward request that Shopify product export should already have. Is there any free app that can include the product id and variant or maybe some other way within Shopify itself?


 

https://apps.shopify.com/ez-exporter?utm_campaign=installed&utm_content=contextual&utm_medium=shopif...

EugeniuS
Shopify Partner
15 0 1

You can use shopify product id to read json and get product is and sku using below code

Thank you for this code. Helped to solve my problem with exporting of ID's.

springforthfarm
Visitor
1 0 1

I'd like to use this code, and I understand I need to copy and paste it and update the API key. My question is, where do I copy and paste it TO? Thanks

goingslow65
Visitor
2 0 0

Thanks for the code above, it worked for me with some modification.    If you have a webserver with php installed, you run the php from there.  

goingslow65
Visitor
2 0 0

My main modification to the script above is getting all the variants instead of the first variant.

$fn1 = 'db/products_id.csv'; // output file
if (file_exists($fn1)) {
rename($fn1, rtrim($fn1, ".csv") . date("ymdHi") . ".csv") ; // rename file
}
ini_set('max_execution_time', 30000); // 0 for infinite time of execution
$m = NULL ; // counter
$api_key = 'yourkey' ;
$pw = 'your_password' ;
$store = 'storename' ;
$n_per_page = 250; // number of item per page
for($i= 1 ; $i< 25; $i++){ // number of pages
$pageurl = 'https://' . $api_key . ':' . $pw . '@' . $store . '.myshopify.com/admin/products.json?limit=' . $n_per_page . '&page='.$i;
$data = json_decode(file_get_contents( $pageurl),true);
echo count($data['products']) . ' data size<br>';
if(!empty($data['products'])){
foreach($data['products'] as $product){
foreach($product['variants'] as $variant){
$csv_data[] = array('Product_ID'=>$product['id'],
'Variant_ID'=>$variant['id'],
'Sku'=>$variant['sku']);
++$m;
}
}
}
}
if(!empty($csv_data)){
$fh1 = fopen($fn1, "w") or die("Unable to open file! L#". __LINE__ . " " . $fn1);
// $fh1 = fopen('php://output', 'w');
fputcsv($fh1, array_keys($csv_data['0']));
foreach($csv_data as $row){
fputcsv($fh1, $row);
}
fclose($fh1);
}

echo 'Number of Product Exported = ' . $m . '<br>' ;

Dean_Kara
Visitor
2 0 1

I found this link which was easy to implement, free and provided what was required: https://support.rechargepayments.com/hc/en-us/articles/360009746154-Finding-and-exporting-Shopify-va....  In case the article is taken down at some stage here are the key details.  My URL ended up looking like this https://shopname.myshopify.com/admin/variants.json?fields=id,product-id,title&limit=250&page=6 as I had 6 pages worth of product variants.

Using the JSON URL in Shopify to find variant IDs

Start by adding /admin/variants in your Address Bar following your Shopify URL when logged into your Shopify Dashboard. It should look like this:

https://examplerechargestore.myshopify.com/admin/variants

Add .json to the end of the URL following variants:

https://examplerechargestore.myshopify.com/admin/variants.json

Once the URL is loaded, you should see variant data populated in JSON format on the next screen.  


Modifying JSON URL for more options

You can modify it by adding ?fields=id,product-id,title to show you only the variant ID, product ID, and variant title:

https://examplerechargestore.myshopify.com/admin/variants.json?fields=id,product-id,title

You can modify it further by adding &limit=250 to make sure the view presents all products in your catalog:

https://examplerechargestore.myshopify.com/admin/variants.json?fields=id,product-id,title&limit=49

If you have more than 49 variants, you will need to append page designations such as &page=2 until all products are accounted for in the JSON view. This is based on Shopify's API limit.


Copying and exporting JSON data

Once all variant information is in view, you can copy and paste the JSON data into a free online JSON to CSV converter tool such as JSON to CSV Converter. This will aggregate the data and provide a CSV file with the information organized in columns. You'll need to get the product titles separately and map them to the correct row in the CSV file using the product ID column.


Alternate method - Finding the variant ID using the cart.js 

Alternatively, when the product is added to the cart, you can find the variant ID by adding .js to the end of the cart page URL.

The URL would then look like this: www.website.com/cart.js. 

When .js is added at the end of the cart page URL it automatically opens a new window with line-item properties of the product currently in the cart. Variant iD can then be filtered out of all the line item properties present on that page.

 

 

ScreenStaring
Shopify Partner
56 2 10

We have a  command-line program that exports various product and variant ids to a CSV or to a customizable JSON format.

ScreenStaring
Software Development & Consulting
mokebo-gmbh
Visitor
2 0 0

Hey @Dean_Kara ,

thanks for your clarifications. I try to do the same here to export my variants together with the ID + SKU. As per https://mokebo.myshopify.com/admin/variants/count.json we have over 600 Variants to export which would be 3 API calls, however if im inserting "https://mokebo.myshopify.com/admin/variants.json?limit=250&page=1" i´m getting an error message:

 

"{

}"

 

Can you explain whats happening?


Philip

Swaggerlikeme
Excursionist
43 0 2

This did not work. I created an app and created access token and have api key and API secret key. I entered that into the variables above and nothing came of it. 

Swaggerlikeme
Excursionist
43 0 2

hi thanks for this code. 

$pageurl = 'https://apikey:password@your-store.myshopify.com/admin/products.json?limit=250&page='.$i;

i am on 2023-10 and i have the API Access Token, Api Key and Api Secret Key. 

Ive tried combinations but to no avail. 

 

Also im trying this from an external server that has php support. I get the following error:
Warning: file_get_contents(https://...@mystore.myshopify.com/admin/products.json?limit=250&page=1😞 Failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /storage/ssd3/482/21709482/public_html/Product-ID.php on line 7

 

Rahul3007
Visitor
1 0 2

Hey,

I found the best way to get product ID in bulk. We can simply export products from Google Merchant. The "id" field in it has the product ID. 

Rahul3007_0-1606062564859.png

4347322466422

This is the product ID

Wui
Tourist
4 0 2

Thanks a lot! I think this is the most efficient way if you are not comfortable with json or any coding like I am. I have 530 ids in my store and edit the product ID with google sheet takes less than 10 seconds. 

AMoffatt
Visitor
2 0 5

It's been since 2018 and there isn't a way to export ID's?? Why do we need an app or code to do such a straightforward task? Shopify support, please add this as a feature; it's pretty straightforward.

xamy
Tourist
6 0 14

Not sure if anyone's still looking for a solution but I finally found one!

  1. Go to analytics > reports
  2. Under inventory click ABC analysis by Product 
  3. Edit the columns to show IDs or whatever info you need
  4. Export

Hope this helps

Zerg
Visitor
1 0 0

es wird nur für die letzte 28 Tagen die Daten angezeigt, d.h. Das du nur ein Teil der Daten bekommst.

Hilft es nicht. =(

howard3849
Tourist
3 0 2

OMG, you have the most simplest solution! You rock!

pkehela
Visitor
1 0 0
Click to expand...
 

Hi Guys, i didn´t get any response to my question above. We have more then 250 variants we want to JSON export but the URL in the way the documentation tells it is just not working. thats what i´m trying:

 

https://XXXX.myshopify.com/admin/variants.json?fields=id,sku,product-id,title&page=2

 

and thats what the results says:

"page: "page cannot be passed. See https://shopify.dev/api/usage/pagination-rest for more information.""

 

any idea what´s wrong?

ScreenStaring
Shopify Partner
56 2 10

@pkehela wrote:
Click to expand...
 

Hi Guys, i didn´t get any response to my question above. We have more then 250 variants we want to JSON export but the URL in the way the documentation tells it is just not working. thats what i´m trying:

 

https://XXXX.myshopify.com/admin/variants.json?fields=id,sku,product-id,title&page=2

 

and thats what the results says:

"page: "page cannot be passed. See https://shopify.dev/api/usage/pagination-rest for more information.""

 

any idea what´s wrong?


The page parameter is not supported in the API version you are using. If you follow the link in the error you will see: 

Cursor-based pagination is supported only in version 2019-07 of the API and above. It replaces page-based pagination for the endpoints listed below.


The link contains information on how to use cursor-based pagination instead of page. 

 

I would recommend use the program I mentioned earlier to export your IDs. 

 

ScreenStaring
Software Development & Consulting
Rotozuk
Visitor
1 0 0

Worked great!! Thank you for sharing!! New to Shopify and needed this data for bringing stuff in from our old site. You rock!

Jason_BFK
New Member
5 0 0

Xamy's solution using the built-in reports worked very well

 

MrBrady
Shopify Partner
6 0 0

Works great! Thank you.

Wvv
Excursionist
14 0 7

Thank you!!!

quikcamo
Shopify Partner
1 0 0

You are a hero! Thank you!

todd-g
Visitor
1 0 0

These were all helpful but not quite what I needed, which was everything from the typical export BUT with product IDs. What worked for me was combining the data

1) Grabbing the admin/variants.json, downloading, converting to csv (just google json to csv there is a free converter)

2) Typical full product export

3) Bring both into Google Sheets and sort both by SKU (the best unique field that is in both exports from above), then combine the columns into one sheet, do a visual check to make sure it all lines up.

ScreenStaring
Shopify Partner
56 2 10

@todd-g wrote:

These were all helpful but not quite what I needed, which was everything from the typical export BUT with product IDs. What worked for me was combining the data

1) Grabbing the admin/variants.json, downloading, converting to csv (just google json to csv there is a free converter)

2) Typical full product export

3) Bring both into Google Sheets and sort both by SKU (the best unique field that is in both exports from above), then combine the columns into one sheet, do a visual check to make sure it all lines up.


I would suggest using the Shopify ID Export program in combination with xsv:

 

shopify_id_export -t access-token your-shop.myshopify.com

This will output a file named your-shop.csv. You can take this file and the product export from the Shopify Admin and combine them via the xsv program: 

 

xsv join 'Variant SKU' export-from-shopify.csv SKU your-shop.csv > with-product-and-variant-ids.csv

 with-product-and-variant-ids.csv will have a 2 SKU columns (SKU and Variant SKU). If this is a problem one can be filtered out using xsv:

 

xsv join 'Variant SKU' export-from-shopify.csv SKU your-shop.csv | xsv select '!SKU' > with-product-and-variant-ids.csv.  

This will remove the SKU column, leaving Variant SKU

ScreenStaring
Software Development & Consulting