Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve all products from a Smart Collection through Shopify API?

Tags:

shopify

What's the best way to retrieve all products from a Smart Collection through Shopify API?

Thanks!

like image 759
Kevin Avatar asked Jun 15 '14 10:06

Kevin


People also ask

How do I collect all collections in Shopify?

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.

How do I see how many items are in a Shopify collection?

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.


2 Answers

Update: API version 2020-04

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.


Pre-2020 solution

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_ids for each of the products in the collection with the specified collection_id.

like image 63
Steph Sharp Avatar answered Nov 01 '22 19:11

Steph Sharp


2020 Update,

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.

like image 25
Codesmith Avatar answered Nov 01 '22 17:11

Codesmith