Re: How to query a Customer by metafield using GraphQL API

How to query a Customer by metafield using GraphQL API

Lederer
Shopify Partner
9 1 1

Hi,

 

I want to query a Customer filtered by it's metafield key/value. How can I achieve this?

Replies 6 (6)

oscprofessional
Shopify Partner
16373 2440 3188

Hi @Lederer,

You can filter metafield with namespace and key, you cannot filter using value of metafield.

Query:

 

 

query Customer_Data{
  customers(first:10){
    edges{
      node{
        email
        displayName
        metafield(namespace:"custom", key:"xyz"){
        id
        namespace
        key
        value
         }       
      }
    }    
  }
}

 

 Thanks....

Hire us | Pass Core Web Vital | B2B Wholesale Experts | Claim Your Free Website Review |
Connect with Us: WhatsApp | Skype: oscprofessionals-87 | Email: pallavi@oscprofessionals.com |
Custom Shopify SolutionsPrivate Apps, Theme Customization & SEO | Digital Marketing |
OSCP Apps: Discount Suite | Wholesale App | Bundle & Upsell | Shipping Discount | and more...
Lederer
Shopify Partner
9 1 1

-message deleted-

Lederer
Shopify Partner
9 1 1

Hey, thanks for your answer. But this query will not filter the results. It just includes the metafields for all customers.

michaelvips
Shopify Partner
21 0 10

I found a way:

query MyQuery {
customerSegmentMembers(
query: "metafields.custom.dados_fiscais = '03305273127' "
first: 10
) {
edges {
node {
id
}
}
totalCount
}
}

Lederer
Shopify Partner
9 1 1

Does no one know a solution?

michaelvips
Shopify Partner
21 0 10

I do.

michaelvips_0-1711287779043.png

 

 

query MyQuery {
  customerSegmentMembers(
    query: "metafields.custom.dados_fiscais = 'value-metafield-here' "
    first: 10
  ) {
    edges {
      node {
        id
        lastName
        firstName
        note
      }
    }
    totalCount
  }
}