Odd webhook behavior around item weight

I have an app that needs to get the weight of items.

I know shopify has recently moved the weight value and weight unit properties into Inventory Item. I won’t discuss the value of having done that.

If I open a product and update just the weight of the object, then save, I will receive a product/update webhook, but without the inventory item.

If I just change the weight unit, say pounds to kilograms, then I receive an inventory item update event, with the weight values, but nothing to tie it back to the product variant id.

Is this expected behavior, or have I just missed something obvious?

Thanks in advance.

I think there is a bit of misunderstanding here.
A product has multiple product variants, there is a one to many relationship here.
Then each variant has an inventory item, again a one to one relationship here.

The weight is a property on the inventory item, not on the product variant.

You can get from an inventory item to a product variant using the IDs.
For example, if you have the inventory item id, you can then lookup the product variant InventoryItem - GraphQL Admin

If you have the product variant id, you can look up the inventory item as well the other way around.

For the webhooks, the product/update webhook no longer contain weight as per the changelog Product Variant Field Cleanup - Shopify developer changelog

Inventory Item Update webhooks will now contain your weight information, you can always lookup the product variant by the API using the ID on the webhook. Or the webhook also contains SKU.

Hope that helps!

Could you try recreating the webhooks and see if the behavior is the same (ie, not receiving a inventory_items/update webhook when you just update the weight?

I’ve tried it on a test store and when I just update the weight value in the admin (and leave the unit untouched) I receive both a inventory_items/update and products/update webhook message with the inventory webhook containing the new weight.

If I just change the weight unit the same thing happens, I get two webhook messages inventory_items/update and products/update. The order of these messages isn’t guaranteed to be the same but it should have all the information you need.

Thank you for your assistance, but that is how I understand things sit together, the issue for me has simply been the way that the updates seem to be handled.

Cheers

Thanks for looking into this.

I have tried recreating the webhook several times, and my experience has simply differed from yours. As I’m still developing, I log every webhook I get and if I edit the weight, so far I’ve only recieved a product/update. If I edit the weight unit, then I only get an inventory_items/update.

So, here’s what I’m going to do - I’m going to clean everything, rebuild everything I can rebuilt, reboot my computer and try again.

As it’s 1 in the morning, I’ll do this tomorrow and get back to you.

Thanks for your help.

So, after rebooting everything, it didn’t work.

After making a new test project, it DID work, so I’m assuming there’s something wrong with the first one.

Thanks for your assistance.

No problem, glad you got it working!