Pulling a file from product metadata into a order notification email template

I’m offering a workshop as a product. I’m storing a .ics file in metadata attached to the product. I’m trying to link to the .ics file from the order_confirmation email template through an “Add To Calendar” link.

{% assign ics_file = line_item.product.metafields.custom.calendar_file_link %}
{% assign ics_file_link = ics_file | file_url %}

but I only end up with

https://cdn.shopify.com/s/files/1/555/555/555/files/gid://shopify/Gene=
ricFile/00001242285000?641

Which obviously isn’t right and I can’t seem to find the right documentation that will help me out.

Thanks~

Hello @JayMorgan ,

This often happens when the metafield isn’t set up with the correct file type. Here are a couple of suggestions:

  • Double-check that your custom metafield (namespace custom, key calendar_file_link) is defined as a file type in your Shopify settings. The file_url filter only converts a file object into a proper URL if the metafield is correctly set up. If it’s not, you’ll end up with that GID string instead of a usable link.
  • If the metafield is set up correctly and you’re still getting the GID, consider re-uploading your .ics file directly to Shopify’s Files section and then storing the URL as plain text in your metafield. This way, you can reference the exact URL you need in your order confirmation email.
4 Likes

Thanks for the reply.
I don’t see anywhere to define the file as a .ics file so I did as you recommended and just uploaded the file then put the url to the file in a metafield and even though it’s more steps it’s working.