New Shopify Certification now available: Liquid Storefronts for Theme Developers

Second and further pages of Variant are missing product_id when using Shopify Python API

2 0 0

According to the documentation to obtain Product Variant data it is required to provide product_id. This is not very convenient when pulling the Variant data for all products regularly - every day or every few hours. It would require 1 call for each product_id. Apparently there is undocumented easier way to get all the product variants without providing product_id.


I'm using Shopify Python API (tried both 8.4.2 and 12.0.0). In that package I use the shopify.Variant class to get the variants. If product_id is provided in the request, the API path is in this format:


or if explicitly putting the api version


but apparently, when product_id is not provided, the class utilizes the undocumented functionality mentioned above and requests this path:


or with the explicit api version



When I use the python package the second and further pages return results with all the keys in the payload of the first page, besides the product_id, i.e.:

page1 = shopify.Variant.find(**{'limit': 250, 'since_id': 0}) // page one has the first 250 records
page2 = page1.next_page() // page two has the next 250 records
page3 = page2.next_page() // page three has the next 250 records

page1[0].keys() == page2[0].attributes.keys() // evaluates to True for any of the 250 objects in page2
page1[0].keys() == page3[0].attributes.keys() // evaluates to True for any of the 250 objects in page3


I've also pulled the same data using curl and the next_page_url and surprisingly the second and further pages in those responses contain the product_id! I suspect something within the python package functionality is omitting the product_ids from the response.


I cannot provide you with specific examples of the URLs since that is private client's data, but I hope you get enough information from the description above to be able to recreate the issue.



Reply 1 (1)
2 0 0

This is how I test if when using curl and the api urls from the Python Shopify API Variant objects the product_id are present in all pages. Of course in this case there are more than 3 pages of 250 variants each.

Get and save the pages to files:

curl '' -i > variants_p01.json
curl '' -i > variants_p02.json
curl '' -i > variants_p03.json

 Count the number of product_ids in each file:

% cat variants_p01.json| grep -o 'product_id' | wc -l
% cat variants_p02.json| grep -o 'product_id' | wc -l 250
% cat variants_p03.json| grep -o 'product_id' | wc -l 250