Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

How to retrieve metafield from products and productvariants

How to retrieve metafield from products and productvariants

WollyMeister
Tourist
4 0 0

Hi all,

 

I am trying to retrieve metafield from products and productVariants, here I have an example query:

 

 

{
  productVariants(first: 10) { 
    edges { 
      node {
        id
        metafield(namespace: "namespace", key: "key"){
             value
        }
      } 
    }
  }
}

 

 

 

 

But what should key and namespace be? Because, now it just retrieves "null"

 

Can't seem to figure it out. In the data for variants I can see metafields for a specific variant that has for example:
Color group: Blue

Petrol color code: 5812

 

I want to retrieve all these fields, how can I best do that?

Reply 1 (1)

Liam
Community Manager
3108 344 910

Hi WollyMeister,

 

Are you trying to receive all the metafields on products or just specific ones? There's examples of namespaces and keys in our dev docs here

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog