Webhook

I’m using webhook product/update and want to get changes to only a specific part of the product (for example price, title, etc.) is it possible to do this? If this is possible, what kind of query is needed?

Hi @Test_test

I see that you’re trying to use the product/update webhook in Shopify to track changes for only specific fields like price or title. That’s a great way to optimize your webhook usage instead of processing every update.

Can You Track Specific Product Changes with Webhooks?

Short answer: No, Shopify’s webhooks do not allow filtering specific fields directly. The product/update webhook fires whenever any part of the product is updated, meaning you will receive a full payload with all product details, not just the changed field.

What’s the Best Way to Detect Specific Field Changes?

Since Shopify does not provide field-specific filtering, you need to handle this on your end. Here’s how:

1-Store a Copy of the Previous Product Data

  • Save product details (like price, title) in your database when receiving the webhook.

2-Compare Incoming Webhook Data with Stored Data

  • When a new webhook event is received, compare the relevant fields (e.g., price, title) with the stored data.
  • If the field has changed, process the update; otherwise, ignore it.

Example Code (Node.js & Express)

If you’re using Node.js, here’s a simple way to check if the price has changed before taking action:

app.post(‘/webhook/product-update’, async (req, res) => {

const productData = req.body;

const productId = productData.id;

// Fetch previous product data from your database

const previousProduct = await getProductFromDB(productId);

if (previousProduct.price !== productData.variants[0].price) {

console.log(“Price has changed:”, productData.variants[0].price);

// Perform your action here

}

res.sendStatus(200);

});

This logic can be applied to any field, like the title or description.

Alternative: Use Shopify’s GraphQL Admin API

Another option is to periodically check for changes using the GraphQL Admin API and filter specific fields.

Example query to check for price changes:

{

product(id: “gid://shopify/Product/1234567890”) {

variants(first: 5) {

edges {

node {

id

price

}

}

}

}

}

This can be scheduled to run at intervals if real-time tracking isn’t necessary.

Let me know if you need more details!
Best regards,
Daisy.