Metafield information copied to media section

Metafield information copied to media section

7675634542
New Member
9 0 0

I would like to set up the following automation in the Shopify Flow-app. I can not manage to figure out how to do it. If it’s doable can someone please explain in detail how to do it?

 

  • When a specific Shopify metafield (https://help.shopify.com/en/manual/custom-data/metafields) is updated (with an url leading to a media file (images, videos, or 3D models))
  • That URL should by Shopify Flow (https://apps.shopify.com/flow) be copied to the media section in the product admin, so the image/media is automatically downloaded to Shopify and appear as an image/video/3D model in the media section (and in the online store).
Replies 13 (13)

EcomGraduates
Shopify Partner
794 68 113

Setting this up in Shopify Flow isn't straightforward as it doesn't directly support copying metafield URLs to the media section. However, you could use a combination of Flow and a custom app or script to achieve this.

  1. Trigger: Use Shopify Flow to trigger when a specific metafield is updated.
  2. Action: Create a custom app or script that listens for this trigger and then uses the Shopify API to download the media file from the URL and upload it to the product's media section.

 If this fixed your issue, likes and accepting as a solution are highly appreciated
|  Build an online presence with our custom-built Shopify Theme: EcomifyTheme
|  Check out our reviews: Trustpilot Reviews
|  We are Shopify Partners: EcomGraduates Shopify Partner



paul_n
Shopify Staff
1509 163 352

There aren't yet any events for when metafields are updated, so Flow can't build a trigger for that yet. Assuming that it's a product metafield, you might be able to instead use a Scheduled time trigger and then use "Get product data" to get recently updated products. You also cannot yet query products by metafields via the API, so you would need to track if you already updated a product somehow. The URL copy part can be done by calling "Send Admin API request" to update the product. 


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.
7675634542
New Member
9 0 0

 

Thank you! For the Mutation i chose "productUpdateMedia". 

 

However, I cannot figure out what to write in the "Mutation inputs".  Can you please help me? What I would like to create (as you know) is that the URL from a specific product metafield is copied to the Media section.

paul_n
Shopify Staff
1509 163 352

Did you look at the linked docs? https://shopify.dev/docs/api/admin-graphql/2024-04/mutations/productUpdateMedia

 

for product id, you would enter productId: "{{ product.id }}"

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.
7675634542
New Member
9 0 0

Thanks! I am still not sure how I make it pick up the ”image/media-URL” from the Metafield? Should I write the name of the Mefafield somewhere? 


(There are brackets and spaces in the Metafield name.)

paul_n
Shopify Staff
1509 163 352

Looking at your original use case, I don't think you are going to be able to copy the actual image from something external to that media. Assuming the media is already uploaded (or external but available via URL) and you want to copy a reference to your product, I think you want this mutation instead:
https://shopify.dev/docs/api/admin-graphql/2024-04/mutations/productCreateMedia 

 

The mutation you have now is for updating existing media on the product

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.
7675634542
New Member
9 0 0

When I try that productId I get an error message. Please see the attached image. 

Flow 2024-07-25.png

 

paul_n
Shopify Staff
1509 163 352

If you are using Get Product Data, you need to loop over the returned products (maybe using For Each step). And then inside that loop with this action, click add a variable and find the product id

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.
7675634542
New Member
9 0 0

I decided to not use Get Product Data (since there seems to be a limit of 100 products).

 

Instead, I would like to update all products from their own metafield to their own media section. I start with a scheduled run. If possible I only want the media section to be updated when the automation is running, if the metafield includes a new URL, to avoid ending up with duplicate images in the media section.

 

Below you can see the automation, so far. I appreciate very much all your help, but unfortunately I don't understand how to set it up.

 

Skärmavbild 2024-07-26 kl. 21.35.34.png

 

 

paul_n
Shopify Staff
1509 163 352

You have to use "Get product data" if you want to use product data in the automation. You can't use a {{ product.id }} because there is no product. To get around the 100 limit, typically you just run it multiple times (on a recurring schedule).

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.
7675634542
New Member
9 0 0

Okey. Now I have problem figuring out what to write in the Mutation input > 

"originalSource": "XXXXXX"

 Here I would like to link to the specific Metafield (which for every product contains different unique Image URL:s). 

So instead of having an URL as the input in "originalSource", I would like to have the specific metafield as the input (which contains the image URL)

 

I have tried to use the data I can find in Settings > Custom data > Products > "Metafield 1" > The value I find in the field below the following text "Namespace and key"

 

When I tried the above I ended up with the follwing error message: "Mutation had user errors: "Image URL is invalid""

 

I understand that there ideally should be an URL, but what should I do if the image URL can be found in the metafield (for every product)

 

So how do I put the metafield as the input in "originalSource"?

paul_n
Shopify Staff
1509 163 352

Not sure what type of metafield you have, so it depends on that. If it's just a URL type on the product, the syntax would be something like:

{{product.imageUrl.value}}

 

Where imageUrl is an "alias" generated by Flow based on your metafield's name. To add that to a workflow, you would choose "Add a variable" and then follow this 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.
7675634542
New Member
9 0 0

Thanks. I will use the flow for all published products when everything seems to be working, but now i firstly will see if it can work as I would like to, for one of the products.

 

So I think I have to modify the syntax below(?):

{{product.imageUrl.value}}

 

I tried by replacing product with that products ID (https://shopify.dev/docs/api/admin-graphql/2024-01/scalars/ID), and also only the products unique figures. In the picture below I use the products ID and imageURL from the examples, but I have of course tried with my actual values.

 

Skärmavbild 2024-07-30 kl. 21.39.27.png

 

As you can see above I am not able to get it to work.

 

I use a single line text product metafield.