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.

How to handle webhooks for fast product listing enabling and disabling

How to handle webhooks for fast product listing enabling and disabling

davidyzeng
Shopify Partner
11 2 2

Hi, I'm trying to manage product listings through webhooks product_listings/add, product_listings/update, and product_listings/remove. From my experience, product_listings/add and product_listings/update fire in less than a second while product_listings/remove takes 5-10 seconds to fire. 

 

The issue this raises is how to deal with someone enabling and disabling a product listing very fast, like click-click-click. product_listings/add and product_listings/update have an 'updated_at' timestamp field so I could compare against the latest timestamp and only respect the most recent timestamp. However, the product_listings/remove webhook only has the data shown below, with no timestamp. Therefore, I am getting these webhooks potentially out of order and I don't know which state the product listing is ultimately in. 

 

A solution that comes to mind is to poll Shopify, but then that kinda defeats the purpose of the product_listings/remove webhook and turns it into like an asynchronous poll request. My questions are:

 

1. Is there a guarantee that the webhooks will always come in correct order? Assume that I can correctly consume them in order received, is the last webhook the true state?

2. Can an 'updated_at' timestamp be added to the product_listings/remove webhook?

 

{
  "product_listing": {
    "product_id": 788032119674292922
  }
}

 From: https://shopify.dev/docs/admin-api/rest/reference/events/webhook?api[version]=2020-04

Replies 2 (2)

HunkyBill
Shopify Partner
4853 60 570

You are stuck in a rut here. First off, there is no real-time way to do your pattern. You cannot know a product listing has changed unless you listen to the webhook, and or, you keep polling for change. So there you have it.

So this begs the question, why are you in such a hurry? What is your use case where you need instant gratification?

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

Hi, thanks for the response. It's not that I'm in a hurry, but more about the UI/UX of the sales channel. I let users enable/disable product_listings in my app and right now the best idea I have is to debounce the clicks with a 5 second delay so that I'm not triggering race conditions with Shopify webhooks. However, this is a worse UX because people should be able to click the enable/disable buttons at will and the app should ideally be able to handle it.