Hi,
I have a shopify app that subscribes to the products/update webhook. Today I’m trying to use the include_fields feature of the webhook to add the field variantsCount to the payload, but I couldn’t get it to work. I tried with variantsCount and variants_count but none is working.
That’s how I did it in the app toml file:
[[webhooks.subscriptions]]
topics = ["products/update"]
uri = "redactec"
include_fields = ["id", "variants_count"]
You’ll probably recommend that I use the variants_guid and get the length of the array, but I’m actually trying to cut down the payload size to the minimum. The reason is that data transfer comes at a cost, and variants_guid adds a lot of unnecessary bytes to the payload that are billed by the network provider. We’re receiving a high volume of webhooks and some merchants have a lot of variants on a single product, so it sums up rather quickly.
Having access to variants_counthere would be ideal.
Thanks in advance for any help on this one.
Hi @Soufiane_Ghzal
The variants_count field from the product Liquid Object, is unfortunately not included in the products/update webhook payload.
You can see the available fields in the payload sample on the Webhook Referrence page for more info on what fields can be requested specifically for webhooks.
I know it’s not ideal, but as you mentioned the best way to get the variant count from the webhook, is to count the records in the variant_gids array that is returned in the webhook payload.
Alternatively, you can save on data usage by making an Admin API call to only get the product variant count by request, so you’re not receiving the variant_gids array in every single webhook, and can only make the API call to get the variant count when you need it.
Here’s some documentation on the queries you can use to retreive the variant count from specific products on demand.
I’ll also be submitting some feedback internally on your behalf that you would like to see the variant_count field returned with product webhooks in the future. While I can’t guarantee when or if this will be added, I can assure you that we take all of our partner and merchant feedback into great value when determining future features and platform updates!
Hi @Kellan-Shopify thanks for your answer, that would be absolutely great if the feature request is accepted and variants_count is added to the webhook! 
@Kellan-Shopify a quick follow up to my previous message, sending a graphql request for every single webhook we receive in order to fetch the variants count is not an option, the volume of webhook is too high and the latency of the graphql api is too high
Hi @Soufiane_Ghzal,
I appreciate the additional context, I will be sure to include this in the feedback we’ve submitted to our developers internally on this topic.