Querying productvariants by metafields in GraphQL

New Member
4 0 0

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.

0 Likes
Trailblazer
299 68 60

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

On The Map Marketing | Developing custom Shopify Sites & Apps is our thing

- Install our latest app Accessibly - Makes your store accessible for everyone, helps to avoid fines
- Inc 5000 | Shopify Parners | 20+ stores launched | 300+ active clients
- Need help with your Shopify store? Reach out to us!
1 Like
Highlighted
New Member
4 0 0

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.

0 Likes