Unable to access any shop.metafields values from within a Flow action

ReavoEnd
Visitor
1 0 2

Whenever I try to reference any metafield namespace (i.e. "inventory") under shop.metafields, the linter activates with error message:

"inventory" is invalid. Replace this variable.

However, I have confirmed that this namespace exists by rendering {{shop.metafields.inventory | json}} to one of my Shopify pages via Custom Liquid.

 

Why does this happen, and what can I do to access shop.metafields within Flow?

 

ReavoEnd_0-1664951995727.png

Replies 4 (4)

paul_n
Shopify Staff
796 118 191

You cannot access metafields that way in Flow. The theme liquid does something special to be able to accept those metafield namespaces and keys in that format. In Flow, you currently need to loop over metafields like:

{%- for mf on shop.metafields -%}
{% if mf.namespace == "my_name" and mf.key == "my_key" %}{{ mf.value }}{% endif %}
{%- endfor -%}
Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
Koennn
Excursionist
18 0 22

Hello Paul,

Thanks for this solution! However, I think I do not get it to work.

Screenshot 2023-02-22 at 20.45.45.png

Am I missing something or is it not possible to access custom metafields? See screenshot attached.

 

Kind regards,

Koen 

paul_n
Shopify Staff
796 118 191

mf.namespace == "custom" and mf.key == "maten"

 

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
Koennn
Excursionist
18 0 22

That makes a lot more sense, thanks for the prompt reply