A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
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:
/admin/products/<product_id>/variants.json
or if explicitly putting the api version
/admin/api/2022-04/products/<product_id>/variants.json
but apparently, when product_id is not provided, the class utilizes the undocumented functionality mentioned above and requests this path:
/admin/variants.json
or with the explicit api version
/admin/api/2022-04/variants.json
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].pop('product_id')
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.
Thanks
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 'https://api_key:password@shop.myshopify.com/admin/api/2022-04/variants.json?limit=250' -i > variants_p01.json curl 'https://api_key:password@shop.myshopify.com/admin/api/2022-04/variants.json?limit=250&page_info=eyJ....' -i > variants_p02.json curl 'https://api_key:password@shop.myshopify.com/admin/api/2022-04/variants.json?limit=250&page_info=eyJ....' -i > variants_p03.json
Count the number of product_ids in each file:
% cat variants_p01.json| grep -o 'product_id' | wc -l 250
% cat variants_p02.json| grep -o 'product_id' | wc -l 250
% cat variants_p03.json| grep -o 'product_id' | wc -l 250