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 nothing changed on the product with respect to my includeFields. Adding title into the set ensured it fired each time.

I recall reading that you can’t use includeFields to tell Shopify to only fire webhooks when those fields changed. However I think Shopify will avoid firing a webhook if nothing has changed in your includeFields within a short timeframe (timeframe unknown).

A safer way to go about it is probably just to include updated_at within your includeFields, then every change should always fire a webhook (provided it passes your filters).

So the final settings that seem to work, are:

  "webhookSubscription": {
    "format": "JSON",
    "includeFields": ["id", "metafields", "status"],
    "metafieldNamespaces": ["internal"],
    "filter": "metafields.value:true AND metafield.key:superapp_product AND metafield.namespace:internal",
    "callbackUrl": "url_here"
  }

I still don’t think this is possible to do via the toml, or via registerWebhooks in the remix template. If I’m correct there, it kinda sucks, but overall if it’s working with a graphql mutation I’m still happy.

If anyone has more knowledge, please feel free!

.

Edit: 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.

1 Like