What's the best way to retrieve all products from a Smart Collection through Shopify API?
Thanks!
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.