Re: Get product metafield generic_file URL within message in Flow

Get product metafield generic_file URL within message in Flow

ChunkySteveo
Shopify Partner
17 0 6

I've been testing and trying all sorts of combinations to access a generic file (a PDF) which is a metafield "file" value for a product.

 

This is for a flow that will give you the PDF URL of the file on a new order when products in lineItems have them. 

 

I have been able to filter out the order line items, filter down into products, and only show those products that have the metafield reference key "pdf_reference". But when trying to access the ACTUAL URL - I am unable to?

 

I can access the URL within the theme templates, and it's present in user orders in their customer account pages - but when implementing the same idea to (eventually) send them a message/email with the PDF via Shopify Flows after an order has been placed - I cannot access the generic_file object?

 

The most I can get with metafield.value is e.g. "gid://shopify/GenericFile/1234567890987". I have tried looping through the object, looping through the metafield options within "Flow", and can get the values for namespace, key, value and type.


The documents for generic_file (https://shopify.dev/api/liquid/objects#generic_file) do not appear to work within Flow? Or trying various Liquid filters and "hacks" such as "file_reference" or "file_url" only result in failed execution when the Flow triggers.

Can someone help me to the a product metafield URL value with a Flow?

 

Thanks - Steve

 

 

Replies 12 (12)

paul_n
Shopify Staff
1368 153 321

Interesting. Flow recently added the new metafield types and what you are seeing is that what the file type stores is not a URL but a GID reference. That means you need a way to lookup the URL based on the reference (which is what the liquid does). This is not yet possible. 

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.
ChunkySteveo
Shopify Partner
17 0 6

Thanks for getting back and confirming @paul_n  - I had gone round in circles enough to worry that was the final answer! Do you know if there is a plan to add this into Flows? I feel Flows is no where near powerful enough yet to truly generate awesome triggers and actions.

It would be so much more transparent/streamlined and 1000% flexible if you could implement all Liquid code that you can in the theme files - i.e. being able to filter assigned variables, access file metadata (e.g. my issue), utilise objects like "all_products". Being able to manipulate accessible Shopify Objects to output complex results would be so useful!  Currently there is a gap that easily trips you up - as you can do something in the theme Liquid templates, but apply a similar method to filter/manipulate data in Flows, and it ends up not possible.

Steve

paul_n
Shopify Staff
1368 153 321

Most of the things you listed are already possible in Flow liquid. The context in which Flow is using liquid is different than the storefront so things like `all_products` wouldn't just work in Flow. We do have plans to offering getting a list of products into Flow, but it's addressed through a separate action called "Get product data", which is in early access right now. 

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.
ChunkySteveo
Shopify Partner
17 0 6

`all_products` wouldn't just work in Flow. We do have plans to offering getting a list of products into Flow, but it's addressed through a separate action called "Get product data", which is in early access right now. 

Thanks for the tip - i'll see if I can utilise that action to pull out what I can for a product.

ChunkySteveo
Shopify Partner
17 0 6

Where is the action "Get product data" in the Flows @paul_n  - i've looked, but cannot find it anywhere?

paul_n
Shopify Staff
1368 153 321

It in a limited release right now. I would need to enable it for your shop. If you can DM me your myshopify domain, I can get that enabled for you.

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.
FernandoYB
Shopify Partner
3 0 0

Hi Paul_n.

I had the same problem.
I try to retrieve the URL of a file uploaded into an order.
I use this code:

 

{% for metafields_item in order.metafields %}
  {% for references_item in metafields_item.references %}
    Certificazione : {{references_item.GenericFile.url}}
{% endfor %}
{% endfor %}

 


But the result is the GID of file: 

gid://shopify/GenericFile/3682400822916


Any ideas?

 

Thanks, 

 

Fernando

paul_n
Shopify Staff
1368 153 321

You cannot use that .url part. all you can get is the GID. This is because metafields use their own type system, and Flow is currently unaware of it. 

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.
FernandoYB
Shopify Partner
3 0 0

Thanks Paul for your reply.

 

Can you suggets me any other solution, or workaround to obtain the result?

have a nice day,

 

Fernando

 

 

paul_n
Shopify Staff
1368 153 321

I did a bit more exploration on this. I think you can actually output the URL. For example, I updated an image to a "File" type and was able to access the URL for the image with this bit of code:

 

{% for metafields_item in product.metafields %}
  {{metafields_item.reference.MediaImage.image.url}}
{% endfor %}

 

This gave me the CDN link to the file. 

 

I'm not sure what makes a type a "GenericFile" but one possibility is that you have the type wrong. Like maybe it's a single file type and not a list (which uses references vs reference). 

 

Can you show your metafield config screen?

 

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.
Shihas_Sidhique
Shopify Partner
2 0 0

Hi Paul,

 

I want to attach a pdf file in my draft order. I have added a metafield to attach pdf in products. Now I want to display that file url in my draft order email template. Can you please help me out here. The current code look like this:

 

{% for metafields_item in product.metafields %}
{{ line.metafields_item.reference.file.custom.estimate.url }}
{% endfor %}

paul_n
Shopify Staff
1368 153 321

Don't loop over the metafields like that. Follow the instructions here to access the typed metafield as like a file reference: https://help.shopify.com/en/manual/shopify-flow/reference/metafields#get-metafield-data

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.