Unable to fetch product metafields via. API

Highlighted
Shopify Partner
5 0 0

I'm trying to fetch product meta fields via. Storefront API for one collection.

API doesn't return any error, but edges property has an empty error.

I tested if the product has meta fields via. Admin API and I'm sure that yes.

 

My query: 

 

  query {
    shop {
      collectionByHandle(handle: "xxx") {
        id
        products(first: 250) {
          edges {
            node {
              id
              handle
              title
              description
              metafields(first: 100) {
                edges {
		 node {
		  key
                  value
		 }
		}
              }
            }
          }
        }
      }
    }
  }
0 Likes
Shopify Staff (Retired)
Shopify Staff (Retired)
624 102 125

Hi @airShopify ,

 

In order to fetch Product Metafields via the Storefront API, you need to first use the Admin API to expose the metafield and make it visible. Once the metafield is visible to the Storefront API, you're able to query for it with the query you posted above.  

 

Read this document for more details: https://shopify.dev/tutorials/retrieve-metafields-with-storefront-api

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes