What's your biggest current challenge? Have your say in Community Polls along the right column.

Re: How to include variant metafields in webhook?

How to include variant metafields in webhook?

laketuna
Tourist
5 0 5

I'm able to configure a webhook for the "products/update" topic that sends my app both product and variant data. Webhooks fire as expected when I update products and variants and their metafields.

 

The issue is when you configure "metafield_namespaces" on the webhook, they are for the products and not the variants. Is it possible to configure the webhook to return the variant metafields?

 

Replies 7 (7)

triple
Excursionist
12 0 10

any update on this?  Having the same issue.

laketuna
Tourist
5 0 5

I believe I ended up just unfortunately making extra API calls to fetch the variant data.

triple
Excursionist
12 0 10
We may have to do the same thing, unfortunately.

In the data Shopify sends, there is a key in each variant called
"metafields", but it is always empty and there is absolutely nothing in the
docs about that.

Can someone from Shopify team reply please?
Jason_T
Shopify Partner
23 0 4

Hi, sorry to side track,

 

but how did you manage to trigger the product/update webhook when updating a variant's metafield?

 

I was able to trigger for product level metafield but not variant level metafield. Appreciate any tips you could provide!

 

 

Linkcious automatically generates related products, up-sells, and cross-sells your entire catalog across your sites much like Amazon's related products. The best part is Linkcious can be used on external sites as well. Use Linkcious on your blog and you will see "Amazon like" related products from your ecommerce store on your blog.

JohnWF
Shopify Partner
16 0 6

Hey guys! For anyone looking at this in the present day, I figured it out for me - if you include the variant metafield namespace in your "metafieldNamespaces" array when making the webhook, those webhooks will turn up in "metafields" in "variants". I tried subscribing with no metafieldNamespaces - nothing. I tried with the variant metafield namespace - voila.

internetperson1
Shopify Partner
2 0 1

Hi John, can you share the syntax please

JohnWF
Shopify Partner
16 0 6

Hey @internetperson1 , my request body ended up looking like this:

{
  query: '\n' +
    '    mutation webhookSubscriptionCreate($topic: WebhookSubscriptionTopic!, $webhookSubscription: WebhookSubscriptionInput!) {\n' +
    '      webhookSubscriptionCreate(topic: $topic, webhookSubscription: $webhookSubscription) {\n' +
    '        webhookSubscription {\n' +
    '    id\n' +
    '    endpoint\n' +
    '    callbackUrl\n' +
    '  }\n' +
    '        userErrors {\n' +
    '          field\n' +
    '          message\n' +
    '        }\n' +
    '      }\n' +
    '    }\n' +
    '  ',
  variables: {
    topic: 'PRODUCTS_UPDATE',
    webhookSubscription: {
      callbackUrl: 'https://etc.',
      format: 'JSON',
      includeFields: [ 'id', 'variants' ],
      metafieldNamespaces: [ 'loyalty' ]
    }
  }
}

to get variant metafield of variant.metafields.loyalty.points.

Here's the query more readable, which is just passing in the variables:

mutation webhookSubscriptionCreate($topic: WebhookSubscriptionTopic!, $webhookSubscription: WebhookSubscriptionInput!) {
webhookSubscriptionCreate(topic: $topic, webhookSubscription: $webhookSubscription) {
webhookSubscription {
id
endpoint
callbackUrl
}
userErrors {
field
message
}
}
}