How can I extract value from metafields in flow app for ebay listings?

Solved

How can I extract value from metafields in flow app for ebay listings?

jake_mitchell
Shopify Partner
120 2 66

We're looking to set up a flow where we can turn multiple metafields into a new multi-line text field which we can then push off into ebay listings. 

 

All well and good with every metafield type except dimensions which will always output something like this:

 

- Chest: {"value":32.0,"unit":"INCHES"}

 

If I was working on a theme page I could easily just get the value and unit, but within flow where the usual dot notation breaks down I can't do that. 

 

I've tried simply using the remove filter to get rid of '{"value":' & '"unit"' & the final "}" but that gives an annoying REGEX error. 

Is there a way of extracting the value from a metafield when doing something like this in flow? 

 

the code for the offending bit is below:

 

 

{%- for metafields_item in product.metafields -%}
  {%- if metafields_item.namespace == "prods" and metafields_item.key == "chest" -%}
    <p>
      <strong>- Chest:
      </strong>
      {{ metafields_item.value.value }}</p>
  {%- endif -%}
{%- endfor -%}

 

 

 

The flow is: 

 

- Trigger: product added to store

- Action: update product metafield

Accepted Solution (1)
paul_n
Shopify Staff
1584 172 366

This is an accepted solution.

Yeah, I think including { causes the liquid parser to think liquid is coming. One solution would be to encode the string and then remove the encoded {. 

The output of a dimension looks like this:

 

 

%7B%22value%22%3A5.0%2C%22unit%22%3A%22INCHES%22%7D

 

 

I think removing the %7B and %7D fixes the brackets issue.  

 

{{ mf.value | url_encode | remove: "%7B" | remove: "%7D" | url_decode }}

 

see https://shopify.dev/docs/api/liquid/filters/url_encode

 

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.

View solution in original post

Replies 5 (5)

paul_n
Shopify Staff
1584 172 366

Yeah, sorry that this isn't yet straight-forward. I think you are on the right track with needing to parse the string. You might be able to use split (https://shopify.dev/docs/api/liquid/filters/split) which turns that string into an array. I think I would do something like:

  • Remove { and }
  • Split by comma
  • check if string contains value or unit
  • split by : 
  • output the final string

 

Also, you can use capture or assign in Flow now, which might help this a bit. 

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.
jake_mitchell
Shopify Partner
120 2 66

Thanks @paul_n . Will give it a go with assign or capture. It seemed to be the { and } that were causing me the issues. using remove or replace on them gave me the regex based error. Flow must've thought i was doing something else.

Will give a go at using capture and/or assign and see where I get on.

jake_mitchell
Shopify Partner
120 2 66

Will keep trying but it seems like step 1 is where the issue is always going to happen. As soon as you try to handle the closing } it will always throw up this error. 

 

jake_mitchell_0-1679510270929.png

 

So I can quite happily get it down to 

 

- Chest: 32.0 INCHES} 

 

But as soon as any action is done on } it will always fail. Really strange and possibly unavoidable. 

 

paul_n
Shopify Staff
1584 172 366

This is an accepted solution.

Yeah, I think including { causes the liquid parser to think liquid is coming. One solution would be to encode the string and then remove the encoded {. 

The output of a dimension looks like this:

 

 

%7B%22value%22%3A5.0%2C%22unit%22%3A%22INCHES%22%7D

 

 

I think removing the %7B and %7D fixes the brackets issue.  

 

{{ mf.value | url_encode | remove: "%7B" | remove: "%7D" | url_decode }}

 

see https://shopify.dev/docs/api/liquid/filters/url_encode

 

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.
jake_mitchell
Shopify Partner
120 2 66

Thanks @paul_n  -  that's the one.