Querying productvariants by metafields in GraphQL

Topic summary

Querying product variants by a metafield value in Shopify’s GraphQL Admin API is not supported. Attempts to use metafields(query: …) or metafields(key: …) on variants or products return errors, as the metafields connection does not accept query or key arguments.

What is supported: retrieving a specific metafield via the singular metafield(namespace: “…”, key: “…”) field on a node (e.g., product or variant). The metafields connection supports namespace filtering but not key or value filtering.

What is not supported: filtering products or variants based on metafield key/value in GraphQL. This blocks use cases like fetching variants by a custom identifier stored in metafields (e.g., wholesaler_product_id) or pulling all items marked “needs review.”

Workaround suggested: filter products (not variants) using tags via products(query: “tag:needs-review”, …), then fetch related data. There is no equivalent tag-based filtering for variants.

Status: No official solution provided for metafield-based filtering; discussion remains open with a practical workaround limited to product-level tagging. Code snippets demonstrate current API limitations.

Summarized with AI on December 17. AI used: gpt-5.

Hello,
I am trying to query productvariants based on a certain metafield value using GraphQL.
I have tried the following but it returns a “Field ‘metafields’ doesn’t accept argument ‘query’” error.

query {
  shop {
    name
    products(first: 100, query:"") {
      edges {
        cursor
        node {
          id
          title
          handle
          variants(first:100) {
            edges {
              node {
                id
                title
                 metafields(query: "key: ean") {
                  edges {
                     cursor
                      node {
                        id
                        namespace
                        key
                        value
                      }
                  }
              }
              }
             
            }
          }
        }
      }
    }
  }
}

Is there any way to accomplish this?

Thanks.

1 Like

Hi, @WouterBouwman ,

This is Evita from On The Map.

Meta fields don’t have query argument.

You can try to use metafield(namespace: “example”, key: “ean”) .

Read the Docs here: https://help.shopify.com/en/api/guides/metafields/admin-api-metafields#retrieving-metafields

Best,
Evita

2 Likes

Hi @OTM (Evita),

Thank you for your response.
Are you saying that there is no way to filter the results based on a metafield value?

Using 'metafield(namespace: “example”, key: “ean”) ’ only returns a specific metafield.

Thanks.

2 Likes

Hi - I’m also interested in this. I want to add custom values to products (e.g. mark a product as “needing review”), and am not sure where I can add that information other than in the metafields. However if I add the information to the metafields, I can’t make queries to pull all products that need review.

Hi people, did you happen to find a solution or a workaround to this problem?? I also want to be able to fetch product variants by metafield value.

Why? I want to store my wholesalers internal product id as “wholesaler_product_id” in a metafield for each product. Then, I can use that number for forwarding dropshipping orders and syncing stock levels.

Seems like shopify has tried to hobble any attempt to actually make use of metafields from graphql.

A perfectly reasonable query would be to get some product info and metafields of those products with a key value of “monkey”

e.g.

query { 
      products(first:40) {
          edges {
             node {
                 title
                 metafields(first:20 key: "monkey") {
                     edges {
                         node {
                              namespace
                              key
                              value
                          }
                     }
                 }
             }
          }
      }
}

BUT NO! graphql errors:

Field ‘metafields’ doesn’t accept argument ‘key’

This works using namespace.

query { 
      products(first:40) {
          edges {
             node {
                 title
                 metafields(first:20 namespace:"football" ) {
                     edges {
                         node {
                             namespace
                              key
                              value
                          }
                     }
                 }
             }
          }
      }
}

Let me guess, I need the 2k a month plan…

Metafields are totally broken in shopify. All these posts are so old.

Is anyone still developing at shopify?

Wont work.

Cant use ‘key’

‘namespace’ is usable.

While this won’t help with filtering variants, you can filter products using a product tag. For example:

query MyQuery {
  products(query: "tag:needs-review", first: 5) {
    nodes {
      id
      title
      images(first: 1) {
        nodes {
          url
        }
      }
      variants(first: 1) {
        nodes {
          id
          price
        }
      }
    }
  }
}