Querying Shopify collections with specific metafield using GraphQL

Querying Shopify collections with specific metafield using GraphQL

AdrienDV19
Shopify Partner
1 0 0

I'm currently working on querying Shopify collections using the GraphQL Storefront API. I'm trying to retrieve collections where a specific metafield (filtering_category) has a value of 'Theme'.

Here's the GraphQL query I'm using:

  

{
  collections(
    first: 250
    query: "metafield: { key: 'filtering_category', value: 'Theme' }"
  ) {
    pageInfo {
      startCursor
      hasNextPage
    }
    edges {
      node {
        id
        title
      }
    }
  }
}

However, despite having collections with filtering_category set to 'Theme', the query is not returning any results. Could you please advise if there's anything specific I should check or adjust in my query to ensure it correctly filters based on metafields?

Thank you for your assistance.

Replies 3 (3)

Liam
Shopify Staff
2873 312 821

On the query line can you try:

 

query: "metafields.namespace_key:'namespace.filtering_category' AND metafields.value:'Theme'"

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

ShopifyDevSup
Shopify Staff
1453 238 501

Hi folks 👋 - just following up here. You are correct @Eric-HAN - at the moment, we don't support query filtering for metafields on the Storefront API's collection object. My understanding is that at the moment, the only way to query those values directly on collections themselves is through Liquid: https://community.shopify.com/c/shopify-scripts/get-collections-by-meta-fields-i-want-to-filter-vend...

Definitely understand that this isn't the most ideal though, so I'm going to put through a note up to our developers to consider adding metafield query filtering on collections as a possible feature in a future release. 

I can't guarantee anything on my end, but did just want to confirm that I'll send that feature request up to our developers right away here. 

Thanks for the clarification there - really appreciated!

- Al 
Shopify Developer Support

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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

Eric-HAN
Shopify Partner
106 15 9

Hi, there

Based on the doc  . Storefront api only supports 3 fields in query param  not covering metafield.

EricHAN_0-1719977208051.png

 

- Helpful? Please hit Like and mark it as a solution
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me    Buy Me A Coffee