Out now! Check out the Poll results: Do you have a Shopify store?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: Webhook: : Get All Products in a Collect

Webhook: : Get All Products in a Collect

JustinKillian
Shopify Partner
28 0 18

Hi,

 

I want to know how i can retrieve information about Collects and all of its products included in that collect. As from Web-hook documentation i can only see topics regarding collections (add, update and delete). This only give me information about collections, not about products included in that collection.

 

Is there a way i can receive data via web-hooks, which tell me that a new product is added to a collection or it is removed from a collect. 

 

Thanks!

 

 

Replies 16 (16)

SBD_
Shopify Staff
1831 273 421

Hey @JustinKillian,

 

Webhooks will only alert you to an update. You'll need to do an additional call to get the product list. Similar question here.

Scott | Developer Advocate @ Shopify 

JustinKillian
Shopify Partner
28 0 18

Hi @SBD_,

 

Is there a possible way to know from which source product is updated by, like a specific field that let me know that user did some updates from Shopify or used any Third Party apps for editing of their products.

SBD_
Shopify Staff
1831 273 421

Hey @JustinKillian,

 

Unfortunately there's nothing to identify that.

Scott | Developer Advocate @ Shopify 

FrankGooten
Shopify Partner
2 0 0

I registered prouct/update webhook with last API version and it not notified about add/remove from collection. Can you confirm it's working solution?

Mets
Shopify Partner
12 0 4

Same Issue here:

When adding/removing a product to a collection, the "collections/update" Webhook does NOT get triggered somehow...

Any ideas why?

Any solution?

This way I don't have a way to find out when particular collection was updated. 

 

 

_JB
Shopify Staff (Retired)
836 100 223

Hey @Mets,

The solution is to do a separate GET to /admin/api/2019-10/collects.json?collection_id={{collection_id}}  or /admin/api/2020-07/collections/{{collection_id}}.json after you receive the webhook to get the product list. 

JB | Solutions Engineer @ Shopify 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

HunkyBill
Shopify Partner
4853 60 568

This does not seem helpful.

I want to know WHEN a product has been added or removed from a collection.

Ok fine. So the webhook collections/update is useless for this, as it never fires on the addition or removal of a product. Sad. True. Now what?

Poll the collection we are interested in for it's collects, and if they are now different, take action. Are you serious? That is caveman computing.

Can anymore discuss how they have nicely dealt with this scenario? Anyone? All I am seeing is crickets chirping over the years, which is not encouraging. I encourage anyone to speak up and let us know! What am I missing here?

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
IamSantosh
Shopify Partner
8 1 1

I'm also facing the same issue. At every Product Update webhook, I'd to hit two different API ("admin/api/2020-10/custom_collections.json?product_id=632910392" and "/admin/api/2020-10/smart_collections.json?product_id=632910392") for finding Custom and Smart collection associated with the Product.

Is there any way to optimize this flow, as hitting two API at every product update webhook is way expensive and also arising problems for the Rate limit.

HunkyBill
Shopify Partner
4853 60 568

I think you are encouraged to set up a Lambda like exercise there, so that no matter how many product update requests are generated, you execute a small bit of code to do your check. So for example, since you know the ID of the product, you throw away any updates not involving the product. Therefore for that Lambda, no API calls. Only when the ID is a match do you bother to check the collections.

Of course, you could up this complexity by saying, but I need to check Every Product! at which point this becomes pointless.

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
Gregarican
Shopify Partner
1033 86 292

If I'm not mistaken, doesn't the GQL query below list all collections associated with a provided product ID? If it's a smart collection then a rule set would be returned. Whereas if not rule set is returned then it's a hard-coded collection association. Right?

 

{
  product(id: "gid://shopify/Product/4423532412980") {
    id
    title
    collections(first: 5) {
      edges {
        node {
          id
          title
          ruleSet {
            rules {
              condition
            }
          }
        }
      }
    }
  }
}
HunkyBill
Shopify Partner
4853 60 568

first 5 anyway. then you iterate cursors... a bulk download query with a product ID that just includes collections? Of course, that has nothing to do with updates, but you could run a query like that as often as you felt practical.

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
Gregarican
Shopify Partner
1033 86 292

I thought @IamSantosh was looking to just retrieve any assigned collections and smart collections associated with a specific product ID. In this use case the GQL query should suffice. Although totally right, my quickie example just pulls the first 5 collections. A more prime-time solution would involve cursors to iterate through any/all resultant collections!

HunkyBill
Shopify Partner
4853 60 568

Sure, that query would return collections, but the problem is, it cannot return all of them as you cannot know apriori how many there are. Hence the complication with cursors. Hence the bulk option? Anyway, this is a fringe thing to be doing, so it merits less attention and besides, I am sure Shopify will be foisting new collection structures on us to replace the ancient collects approach soon enough. We'll probably be getting a whole slew of new endpoints with V1, V2 and V3 on the near horizon, coming to a terminal near you.

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
HunkyBill
Shopify Partner
4853 60 568

I love how this reply points to a thread where a Shopifier gave out incorrect advice, and while it was pointed out by many as incorrect, no one has as of yet made even a tiny effort to not only answer with correct advice, but to clean up this messy inter-thread fiasco.

So while many Shopifiers tell us in the community to use the forums, when we do, we can be surprised by the whole schebang:

  • good advice, to the point
  • bad advice
  • incorrect advice
  • crickets chirping

Obviously hitting this first objective is ideal, and I am sure it happens often enough, but in the sensitive and technical API forums, watch out for the dreaded last three.

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
Gregarican
Shopify Partner
1033 86 292

@HunkyBill I read that referenced thread, and it seemed to be a prime example of the downside of the forums. 

  1. User posts a question.
  2. A proposed solution is offered, which actually doesn't work when put into practice.
  3. The OP replies that the solution isn't working.
  4. Other users stumble upon the thread and chime in with similar struggles.
  5. *crickets*

Typically, a blind alley that's affecting more than a few clients should result in (depending on the nature of the situation) --- a) an eventual bug fix, b) a new feature request on the roadmap, c) feedback as to a viable workaround, that's not counter-intuitive against the standard framework.

One of the many aspects I admire in this API platform is that it's regularly maintained and updated. Rolling out a new API version every 3 months is a prime example of this. Too bad there isn't an area of the forums for client poll or something. Where upvoted requests are taken into account. We all know of a few gotchas that would be nice to put a stake into finally!    

HunkyBill
Shopify Partner
4853 60 568

Choices are made by management for sure, that satisfy constraints at the time. Is there an able bodied worker able to do the thing? Does the thing matter to one crazy person, or hundreds or more of non-crazy persons? How expensive is said thing to do? How many unintended consequences are there if we do said thing?

No kidding. But this is where frustration kicks in. Shopify is OLD by technical platform measures, a codebase in play since 2005. So 15 years, plus. While few can say they've mastered the whole, many are masters of small domains of it. And the frustration is, even with rolling API improvements, you can still drive tractor trailers through vast empty parking lots where there should be active loading bays.

So you cannot get an event when a product is added to a collection. OK. So you poll. That is nasty, but I guess it is what it is. Today I had a background job finally complete, repricing a single vendor's products (200,000 of them) using GraphQL and 24 hours of time. Wow. And when I dug in to optimize, because I remembered I could do some things in bulk, I found I could only update inventory at a location in bulk, nothing else. And then I was sad. Because one would think, updating prices in bulk would be a most natural thing in the world to support, a thing that is not terrible to implement, compared to inventory quantity with its myriad moving parts. Price is a kind of static attribute. There is nothing about price that is new in Shopify, it goes back to day one Shopify. So yes, I agree, all is fabulous, except when you need certain things and you know for sure, you are not that one crazy person that wants something you just can't have.

We have had polls for features. If you cared to research it, probably more than two versions, but for sure, it has been tried many times. The problem is, polls are often polluted by crazy. It attracts everything from soup to nuts to Monads. And so how do you have them, and keep the quality without being rude. People will upvote or downvote anything, which is why reviews and stars and thumbs up and down are so weird to use as measures. If 99% of all forum users asked for infinite variants, or direct to customer messaging from Apps, would Shopify capitulate and say "Sure!, you can have that, no problem!"... I doubt it.

 

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com