What's the best way to retrieve all products from a Smart Collection through Shopify API?
Thanks!
On collection page, fetch all the collections. If your current collection handle is t-shirt and your sub collection handle is linen-t-shirt. Check for all the collections which contains current collection handle, then show the details.
Shopify doesn't include the number of products in your catalog under the products section of the content management system. To find out how many products you have in your catalog you'll need to open a new page in your browser and enter the URL: https://your-store-name.myshopify.com/admin/products/count.json.
See Codesmith's answer below. As of API version 2020-04, you can now use a smart collection id with the collections endpoint:
GET /admin/api/2020-04/collections/{collection_id}/products.json
See the Collection API docs for more info.
From the SmartCollection page in the Shopify API docs:
Smart Collections also use collects to connect a product to that smart collection.
And on the Collects page:
List only collects for a certain collection
GET /admin/collects.json?collection_id=841564295 HTTP/1.1 200 OK { "collects": [ { "collection_id": 841564295, "created_at": "2014-05-23T14:16:47-04:00", "featured": false, "id": 1071559648, "product_id": 921728736, "sort_value": "0000000001", "updated_at": "2014-05-23T14:16:47-04:00", "position": 1 }, ... ] }
The collects contain the product_id
s for each of the products in the collection with the specified collection_id
.
For the latest API (2020-04 as of now), you can simply use the /collections/
endpoint, using the Smart Collection ID:
GET https://<shopname>.myshopify.com/admin/api/2020-04/collections/<smart collection id>/products.json
More details can be found in Shopify's Collection API Docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With