Get total products in a collection rest api

bajwa_rajat
Shopify Partner
13 0 1

Hey, 
Is There any wayto get total number of products in a collection via API. Collection can be custom or smart , but I just want to retrieve total number of products in a collection.
My concern is that I want to get all empty collections on store, whether it be custom or smart, all collections with zero number of products in them.

Thanks in advance.

0 Likes
LittleVentures
Shopify Partner
45 10 10

Yes, you can use the collects count endpoint as referenced here:

https://help.shopify.com/en/api/reference/products/collect

 

The format you are looking for is:

/admin/api/2020-01/collects/count.json?collection_id=841564295

 Hope that helps.

 

 

Regards,

Tom

Shopify Partner & Developer
If it's a problem you can't solve the job is not too small - get in touch
littleventures.net
contact@littleventures.net

Print or download a PDF catalog for your store in minutes - Shop-2-Doc
0 Likes

It cannot work for smart collections. It will give an error like this: 

{
"errors": "Cannot load count for Collects belonging to a SmartCollection"
}

Any fix to get the number of products under a collection?

SPO - SEO App to research keywords & edit social link preview
BYOB - Build Your Own Bundles
0 Likes
weavesmart1
New Member
1 0 0

Try This:

admin/api/2021-01/products/count.json?collection_id=12345678

0 Likes