metafields in webhook filtering includeFields

I've added my metafields to the includeFields so I can filter for them like so:
shopify: {
shopifyFilter: "variants.metafields.$app.my-app.key1:* OR variants.metafields.$app.my-app.key2:*",
includeFields: [
"id",
"body",
"category",
... more product fields
"variants.title",
... more variant fields
"variants.metafields.$app.my-app.key1",
"variants.metafields.$app.my-app.key2",
... more metafields
]
}
shopify: {
shopifyFilter: "variants.metafields.$app.my-app.key1:* OR variants.metafields.$app.my-app.key2:*",
includeFields: [
"id",
"body",
"category",
... more product fields
"variants.title",
... more variant fields
"variants.metafields.$app.my-app.key1",
"variants.metafields.$app.my-app.key2",
... more metafields
]
}
But now I can see the fields are no longer registered when viewing the schema (attached). Docs mention that all fields to be filtered must be in the includeFields array, but this appears to have deregistered it in schema. What have I done wrong?
No description
34 Replies
Anthony
AnthonyOP•5w ago
removing all includeFields, seems to allow gadget to register the namespace as normal, however the filter does not seem to work as expected - no webhooks get through it that should be passing.
Chocci_Milk
Chocci_Milk•5w ago
Do you mind sharing the app url? Then I can take a look at what might be the issue
Anthony
AnthonyOP•5w ago
Let me change branches first, one moment. I can't seem to get any of the webhook filter changes to update now - hmm
Chocci_Milk
Chocci_Milk•4w ago
I'm not personally having issues but I've only just set the filter and includes fields Gonna test now I got an update
Chocci_Milk
Chocci_Milk•4w ago
No description
Chocci_Milk
Chocci_Milk•4w ago
No description
Chocci_Milk
Chocci_Milk•4w ago
This was 2 changes. Changed from null to test 1 to test 2
No description
Chocci_Milk
Chocci_Milk•4w ago
No description
Chocci_Milk
Chocci_Milk•4w ago
It looks like my webhook payload is the full payload though
Anthony
AnthonyOP•4w ago
My case is slightly different with metafields on the Variant, so not sure if that is where the issue comes in also with an app namespace included
Anthony
AnthonyOP•4w ago
I'm not able to get the filters or include fields to register at all right now - so not sure if my app is bugged now?
No description
Chocci_Milk
Chocci_Milk•4w ago
Is that the correct syntax for app owned metafeilds in filters?
Anthony
AnthonyOP•4w ago
According to the Shopify dev assistant, it is. I wasn't able to find specific examples in docs anywhere.
Chocci_Milk
Chocci_Milk•4w ago
I wonder if its $app-namespace.key Or even just $app:namespace like how you define it
Anthony
AnthonyOP•4w ago
$app:namespace was definitely incorrect as the call would come back with an error from Shopify. Can't the : apparently. trying the - now
Chocci_Milk
Chocci_Milk•4w ago
For variants, I think that its correct the way you put it
No description
Chocci_Milk
Chocci_Milk•4w ago
Shopify really needs to improve their docs
Anthony
AnthonyOP•4w ago
registering this in the includeFields "variants.metafields.$app-my-app.key1", Causes the gadget registration to flag as not registered, and also the metafields don't come through on the webhook - so I don't believe that's it.
Shopify really needs to improve their docs
I wasn't sure registering metafield based filters was something on your end or their end because of this. Shopify dev assistant seemed to be pretty sure on the syntax but had no references... haha. Not mentioned in the gadget docs either.
Chocci_Milk
Chocci_Milk•4w ago
It looks like I was actually wrong. My filters aren't working
Anthony
AnthonyOP•4w ago
I've also tried using the rationalised namespace in the filter (with the app id), and that doesn't work either. Maybe this is not actually supported by Shopify?
Chocci_Milk
Chocci_Milk•4w ago
Shopify Developer Community Forums
Webhook filter by metafield
Ok so it turns out it does work! You need to set includeFields and include metafields within it. I was doing this, but where it was going wrong is that I was setting includeFields to a small set for testing - i.e. id, metafields, status. Then to try to fire the webhook, I was updating the product title. Shopify wasn’t firing the webhook as n...
Chocci_Milk
Chocci_Milk•4w ago
I'm about to test it myself
Anthony
AnthonyOP•4w ago
This appears to be working (but its the end of a long day, so I could be hallucinating).
shopifyFilter: "variants.metafields.key:my_key AND variants.metafields.namespace:app--1234567890--my_app AND variants.metafields.value:*"
shopifyFilter: "variants.metafields.key:my_key AND variants.metafields.namespace:app--1234567890--my_app AND variants.metafields.value:*"
Chocci_Milk
Chocci_Milk•4w ago
Its super weird that metafields are sent regardless of change
Anthony
AnthonyOP•4w ago
I've left includeFields empty for now
Chocci_Milk
Chocci_Milk•4w ago
Is it working for you? I just want to make sure that you don't get webhooks that you don't want
Anthony
AnthonyOP•4w ago
It looks like the filter above works so we only get webhooks that fulfill the filter. It doesn't look like includeFields works, even when using the rationalised namespace - maybe there's something wrong there. Gadget also doesn't recognise the field as registered when using the rationalised namespace So i'll have to test more The filter is the bigger win at least. includeFields and getting rid of updated_at is just a bonus Thanks for your help - really appreciate it! Some shortfalls I'd love your help with when you're next available please Antoine. 1. Gadget can't do variables in the shopifyFilter. Given we need to use the rationalised namespace with the app id - when setting the shopifyFilter to a variable or using literals so we can conditionally set the app id based on an env variable - gadget doesn't think it's valid: "options" is not a valid object 2. Using a Shopify Filter with rationalised namespace causes Gadget to think the app namespace is no longer registered in the field schema UI (even though the webhook registration call to shopify shows the app namespace being registered) 3. I still haven't found a way to use the rationalised namespace or app namespace in the includedFields that Gadget likes. I'm thinking this is just a shortfall currently? I'd love to go live with these webhook filters but am concerned the above means something actually isn't correct.
muchi
muchi•4w ago
Hi Anthony, could you provide some more context/steps to reproduce the issues you're seeing? What does "rationalised namespace" refer to? From where do you see "options" is not a valid object?
Anthony
AnthonyOP•4w ago
All of our metafields use app reserved namespaces, so they are registered as $app:our_namespace In webhooks and in Shopify, this rationalises out to replace the $app, with our app id eg app--123456789--our_namespace When trying to apply the webhook filters in the action files in Gadget, after much testing, it only works if we apply the filter as the rationalised namespace ie. app--123456789--our_namespace instead of $app:our_namespace . It looks like this might just be a Shopify limitation. The filter below works as expected: shopifyFilter: "variants.metafields.key:my_settings AND variants.metafields.namespace:app--123456789--our_namespace AND variants.metafields.value:*", However, given the app id is specific to the environment - Id like to use a variable here so when we deploy, it works as expected and uses the production app id. Using either of these options does not work and makes Gadget show a global error in the 'problems'/ terminal area in the editor.
const filter = `variants.metafields.key:my_settings AND variants.metafields.namespace:app--${process.env.APP_ID}--our_namespace AND variants.metafields.value:*`;
export const options = {
actionType: "create",
triggers: {
api: false,
shopify: {
shopifyFilter: filter,
}
},
};
const filter = `variants.metafields.key:my_settings AND variants.metafields.namespace:app--${process.env.APP_ID}--our_namespace AND variants.metafields.value:*`;
export const options = {
actionType: "create",
triggers: {
api: false,
shopify: {
shopifyFilter: filter,
}
},
};
or this:
shopifyFilter: `variants.metafields.key:my_settings AND variants.metafields.namespace:app--${process.env.APP_ID}--our_namespace AND variants.metafields.value:*`,
shopifyFilter: `variants.metafields.key:my_settings AND variants.metafields.namespace:app--${process.env.APP_ID}--our_namespace AND variants.metafields.value:*`,
I can send through a Loom as a DM of the actual issue in our app environment if preferred?
muchi
muchi•4w ago
Got it, thanks for the additional context! Will take a look into this for you. A Loom would be helpful to make sure I'm seeing the same thing as you're referring to also! So after some investigation I can tell you two things: 1. Shopify themselves don't support webhook filters using the $app:namespace shorthand: https://community.shopify.dev/t/is-there-a-way-to-use-app-in-filter/6123 2. The shopifyFilter in the options actions object must be static, as it's evaluated at buildtime not runtime. So passing variables in it will not work Unfortunately the only way I can think of to make this work right now would be to hardcode the string filter for the production app, deploy to your production environment, and change it back to point to your development app in your development environment. Definitely not ideal(sorry!) and hopefully Shopify can support the $app:namespace metafield shorthand soon!
Anthony
AnthonyOP•4w ago
Thanks so much for that info Jenny - I really appreciate it. What about using the metafield inside the includeFields? I'd like to optimise the includeFields too, but if I add the rationalised metafield there, Gadget doesn't consider the metafield as registered (because the field in the schema is set up to use the $app:namespace?
muchi
muchi•4w ago
No problem! And I'm not sure exactly why you need the rationalized metafield in the includeFields- if you have metafields on your model Gadget registers your webhook subscriptions with the metafield namespaces included. I'm also not sure if you can even specify $app:namespace in the includeFields-it would be strange that Shopify supports that and not in the filter itself 🤔 From this post Anotine shared earlier: https://community.shopify.dev/t/webhook-filter-by-metafield/17301/2
You don’t actually need includeFields to be specified. If you set metafieldNamespaces then it will automatically include metafields in the payload, and that’s enough to be able to use filters on it.
You don’t actually need includeFields to be specified. If you set metafieldNamespaces then it will automatically include metafields in the payload, and that’s enough to be able to use filters on it.
Anthony
AnthonyOP•4w ago
Thanks Jenny. Appreciate the info and help.
muchi
muchi•4w ago
Glad it helps! 🙂

Did you find this page helpful?