Solved

Trying to add images to metafields in shopify workflow, need file reference string for my images

Filiph2
Excursionist
14 1 2

Hi, as the title says. Where can I find these "file reference strings" that the shopify workflow gives me as an error when trying to update a metafield with an image.

 

I need somthing that looks like this: "gid://shopify/ MediaImage/123" apparently.

 

This should be able to be added to the value box within the shopify workflow in order for the workflow to know what file to update the metafield with.

 

This is the exact error message: "Got error updating metafield: "Value must be a file reference string." For value: "gid://shopify/ MediaImage/barbecue-128.png""

 

where "barbecue-128.png" is just the file- name of the image i'm trying to upload.

 

Image of the workflow

shopify workflow.png

Accepted Solutions (2)
paul_n
Shopify Staff
1010 133 240

This is an accepted solution.

That id was specific to my shop. I got it by running the query I showed above, and the file was in the "content" area of the Admin. Once you attach it to a metafield, but it's still referencing the original ID so you can point many products to the same image.

 

Make sure you clear any whitespace around the GID and just doublecheck it's correct. 

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

Filiph2
Excursionist
14 1 2

This is an accepted solution.

Hi Paul! Thanks for the help, I didn't use exactly what you said but I found a simpler way. I'll give you the accept as solution.

 

To anyone else wondering, to get the specific ID for the image that is universal for the store and not only for the specific product. Simply add the image to any product on the metafield that you want to add, using the bulk editor. Then, in bulk editor, highlight the metafield and press control + C to copy it. That will give you the reference string that is universal for your specific store.

 

You can use this string to automate adding images to metafields with shopify Flow.

View solution in original post

Replies 9 (9)

paul_n
Shopify Staff
1010 133 240

This is more of a metafields questions I think than a Flow question, but I see a few places where images have different gids. If it's a product image, i see `gid://shopify/ProductImage/28038xxxx`.  You can see that actual id by going to the product page and adding `.json` to the end of the URL. 

 

Where did you upload this image?

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.
Filiph2
Excursionist
14 1 2

Thanks for taking the time to reply Paul!

 

I’ll try what you said first thing in the morning. Although I don’t really want to upload it to my product- images, that would require manually uploading every image (or use flow to do it I guess), and therefore ruining the whole automation process of updating metafields that I’m trying to achieve here. I only want the image on the metafield, to then display this image, which is an icon, to the “product grid” of my website, just to give you a bit more context.

 

I’ve just uploaded the image to the “files” under “content” in Shopify. So it is no specific position in the website, just on the server so to speak.

 

I figured if I could just get the file reference string for that specific image I would be able to automate my flow just by having to upload it to the “file” section in Shopify.

paul_n
Shopify Staff
1010 133 240

Ok, I'm not sure you can find that ID in the UI...I'm checking but haven't heard back. Assuming no, I used the app GraphiQL to query this object in my store to get the ID:

 

{
  files(first:10) {
    nodes {
      __typename
      alt
      ... on MediaImage {
        id
      }
    }
  }
}

 

 

My ID has this format: "gid://shopify/MediaImage/32180513669142"

 

The docs for the query are here: https://shopify.dev/docs/api/admin-graphql/2023-01/queries/files

Docs for mediaImage fields: https://shopify.dev/docs/api/admin-graphql/2023-01/objects/MediaImage



 

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.
Filiph2
Excursionist
14 1 2

I tried it, and got the reference. Still gave me the same error, so my question was apparently not the question I needed to ask in order to solve my issue here.

 

I guess I'll give you the "accept as solution" since you actually did answer my question.

 

Also, are you aware of someone else trying to do what I'm trying to do? That is, just updating metafields with an image if the title contains "xxxx", using Shopify Flow? Does it even make sense to do it? Beacuse it surely seems like Shopfy themselves haven't thought of this since there is no easy alternatives to simply do it in Flow.

paul_n
Shopify Staff
1010 133 240

It's not a typical use case, but probably 50% of use cases on Flow are custom in some way. That's why Flow exists. 

 

This is still your error? 

 

"Got error updating metafield: "Value must be a file reference string." 

 

I just tested this in my store and was able to update a product metafield with a file reference type using an image from that Content section (with the gid string). Therefore, I suspect that your metafield is not set up to accept images. I see that by default it accepts "GenericFile" or something like that. 

 

Here are my settings

26-11-2msb6-ic199

 

 

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.
Filiph2
Excursionist
14 1 2

The settings on metafield were right, just forgot to remove the citationmarks.

 

We are getting very close.

I'm getting a error that the reference string doesn't exsist, which means it's atleast in the right format now.

 

Exact error message:

Got error updating metafield: "Value references non-existent resource gid://shopify/MediaImage/50422775808326." For value: "gid://shopify/MediaImage/50422775808326"

 

One thing that will make this more clear to me is if I get to understand this...

The file reference string that you sent here (this one "gid://shopify/MediaImage/32180513669142"), is that some kind of universal ID for the image on your shopify?

 

Beacuse if I add the specific image to two products, they will have different ID's. So there must be some universal ID for the image or somewhere I can place it in Shopify, for Shopify flow to know what image to place in the metafield, and also fetch the image.

 

Since based on the error message, it believes that the resource doesn't exsist. Could you also provide a screendump of the Flow you tried, that worked?

paul_n
Shopify Staff
1010 133 240

This is an accepted solution.

That id was specific to my shop. I got it by running the query I showed above, and the file was in the "content" area of the Admin. Once you attach it to a metafield, but it's still referencing the original ID so you can point many products to the same image.

 

Make sure you clear any whitespace around the GID and just doublecheck it's correct. 

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.
Filiph2
Excursionist
14 1 2

This is an accepted solution.

Hi Paul! Thanks for the help, I didn't use exactly what you said but I found a simpler way. I'll give you the accept as solution.

 

To anyone else wondering, to get the specific ID for the image that is universal for the store and not only for the specific product. Simply add the image to any product on the metafield that you want to add, using the bulk editor. Then, in bulk editor, highlight the metafield and press control + C to copy it. That will give you the reference string that is universal for your specific store.

 

You can use this string to automate adding images to metafields with shopify Flow.

Filiph2
Excursionist
14 1 2

You can use this string to automate adding images to metafields with shopify Flow