How to get media src by using metafield file type in Graphql or API's ?

Solved
DSLR
Tourist
24 0 1

Hello , 

I am trying to get the image source by using metafields value but it will be given me "gid://shopify/MediaImage/24161764376760" that type media Image id, 

With the help of this in which query I have to use to get media src .

 

metafields_img.png

 

Thanks in advance !

 

0 Likes
Dave_Pelletier
Shopify Staff
Shopify Staff
26 3 1

Hi!

Starting next Friday (Oct 1) with the release of the 2021-10 API version you'll be able to query a new reference field on the Metafield object. You can see it in the dev docs for the 2021-10 version here:

https://shopify.dev/api/admin-graphql/2021-10/objects/Metafield

https://shopify.dev/api/admin-graphql/2021-10/unions/MetafieldReference

You can also try it out by using the 2021-10 release candidate version before it launches on Oct 1.

0 Likes
DSLR
Tourist
24 0 1

Thank you @Dave_Pelletier for your response, 

I have checked dev docs but i am not found any query about the media image to get source . I know with the help of liquid object we will achieve image src. But i want to get the image src by using any Api's or Graphql for metafields.

 

0 Likes
Dave_Pelletier
Shopify Staff
Shopify Staff
26 3 1

This is an accepted solution.

This query works for me on the 2021-10 version of the GraphQL Admin API. Is this what you're looking for?

 

{
  product(id: "gid://shopify/Product/YOUR_PRODUCT_ID") {
    metafield(namespace: "my_fields", key: "image") {
      reference {
        ... on MediaImage {
          image {
            originalSrc
          }
        }
      }
    }
  }
}

 

Response:

{
  "data": {
    "product": {
      "metafield": {
        "reference": {
          "image": {
            "originalSrc": "https://cdn.shopify.com/s/files/1/1026/6195/files/mobile-receipt-shopify.png?v=1613088523"
          }
        }
      }
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 4,
      "actualQueryCost": 4
    }
  }
}

 

DSLR
Tourist
24 0 1

Thanks , that's great !!

That's query help me a lot , 

Can you please share me metafields docs url with the help of I will be use other metafields type data ?

0 Likes
Dave_Pelletier
Shopify Staff
Shopify Staff
26 3 1

Here's the best starting point for Metafields docs: https://shopify.dev/apps/metafields

Here is the list of types: https://shopify.dev/apps/metafields/definitions/types

 

0 Likes
valschr
New Member
1 0 0

Thanks for the very helpful info. 

Will this also be available for the storefront API? I'm currently looking for a way to get this to work with a headless Gastby setup. 

thanks, 

0 Likes
DonaldW
New Member
1 0 0

Hi!

I have the same issue on the storefront api.

Is it possible to get the reference using the storefront api?

Thanks

0 Likes