How to find all the collections that your product belongs to on Shopify

Shopify’s REST API is a powerful tool for managing your store. It gives your apps direct access to product catalogues, customer records, and orders for just about any analysis you can imagine. However, the path to the data you need is not always obvious. For instance, it’s easy to find a product inside of a collection, but what if you need a list of collections that your product belongs to?

This is really useful data if you have a lot of product collections, whether they are created by hand or generated automatically. The answer to this question is not found in the Products endpoint of the rest api. There are two endpoints dedicated to collections, Collection, and CustomCollection. The first one retrieves automatic collections, the kind that include products that have special tags or other criteria. CustomCollection covers collections where the products have been added by hand or by a custom app.

You can find custom collections that contain your product by providing the product id.

GET /admin/api/2021-04/custom_collections.json?product_id=632910392

If you are using the Shopify Rest API gem, this line of code will do.

current_collections = ShopifyAPI::CustomCollection.find(:all, :params => {:product_id => shopify_product.id})

This also works for the collect API as well.

GET /admin/api/2021-04/collects.json?product_id=632910392

And here’s the ruby code for that operation.

current_collections = ShopifyAPI::Collection.find(:all, :params => {:product_id => shopify_product.id})

Now that you have the JSON data back from the API, you can pretty much do what you like with it. You can put the collections in separate lists, you can combine them, or you can cross-reference it and remove the product from collections it shouldn’t belong to.

I hope that allows somebody to take little bit more control of their Product Data. If you want to get more tips like these, feel free to subscribe to my newsletter!

What I do in 2021

As part of my 30×500 coursework, I’m supposed to be building clout with my audience by posting educational content. Since already kind of have an audience (Hello, you!) I thought it would be kind of jarring to just start posting random e-commerce advice. Kind of like when people go from posting about their kids to posting about weight-loss supplements? So I’m just going to give a bit of context and talk about what I do for work these days.

Programmer is one word for what I do, but that covers a lot of different jobs I’ve done. I’ve worked on crime mapping programs, soil databases, school enrolment systems, and online car advertisement systems. Each project involved learning new techniques and facing new challenges.

Nowadays, I run a website called Fire-parts.com. It’s the largest online retailer for gas fireplace parts in the US and Canada. I started off working on it as a contract for a previous job, but now I work on it full time.

It’s powered by an e-commerce web software package called Shopify. If you shopped online outside of Amazon, chances are you’ve used it yourself. There are open source software packages like Magento and Woocommerce that you can install yourself on your own rented server, but they require a lot of little tweaks to get working properly. Shopify handles a lot of those features all by itself.

It also has the added benefit of not having as many heavy handed merchant standards as platforms like eBay and Amazon. Although Shopify allows you to connect to those platforms, Amazon in particular has been known to severely punish merchants who ship items late or run out of stock unexpectedly. Getting back online involves a lengthy process of writing letters detailing your process and how “this will never happen again, Mr. Bezos sir”. With Shopify, such matters are settled between you and your customers.

Does it have its limitations? Sure it does, but you can work your way around most of those by using their app platform. There are apps for marketing, product searches, user experience, and a whole lot more. You can even build custom apps yourself to really set your store apart from your competitors.

Fire-parts has one such custom app, and it’s the one that I spend most of my day working on. It’s a searchable database containing manuals for over 10,000 fireplace models. Whereever possible, it scrapes the manuals for part numbers, which we cross reference with our product database. When you find the manual you’re looking for, it will not only display the manual itself, but any instructional videos we have, related documents, and a parts list. Thousands of fireplace professionals all over North America use this system to find the parts that they need. My job is to add new features to this database so it has more models, more parts, a better interface, and a better search engine than any other competing database.

So that is what I do now. I have some special expertise, but I’m always looking to improve. That’s why I enroll in courses like 30×500. Another great way to improve your knowledge is to take what you know, put it in a new context, and help some people with their problems. People have lots of questions about Shopify, so I’ll try to answer a few on this blog and see how it goes. Of course, if you have any questions yourself, Let me know and I’ll try to answer them here too. And as always, you can join my mailing list and you’ll get the answers straight into your inbox.