I have used the Shopify product creation webhook, but when I create a product with multiple variants, it does not return all the variants.
It only provides me with one variant.
This issue occurs occasionally, but we cannot fully rely on the webhook, correct? The same issue is mentioned here:
https://community.shopify.com/c/shopify-apps/incomplete-data-received-from-product-create-webhook/td-p/2469436
Hi @Sabin_Bhattarai,
I think what’s happening is that it take several API calls to create the product. The first API call creates the product and then another API call right afterwards adds variants to the product.
The gap between these two API calls isn’t noticeable on the admin but you’ll receive two separate webhooks:
products/create
- when the product with one variant is created
products/update
- when the variants are added to a product right afterwards
There’s two ways I can think of to handle this:
- either listen for the
products/update
webhook as well to get the variants
- when you receive a
products/create
webhook, wait a little bit and then retrive the whole product from the GraphQL API. (If you do this, use some kind of background processing/worker to retrieve the GraphQL data so you don’t slow down your webhook processing)
Best,
Daniel
Hello!
I wanted to confirm the answer @Daniel_Ablestar provided is complete and correct. On admin, a separate API call creates the variants for a product. The first API call to create the product only creates the default variant - ie. the first variant that is included in the products/create
webhook.
Either approach suggested will enable you to retrieve all variants for a newly created product.
1 Like