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
15938 2383 3092

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....

Get pass your Store Core Web Vital Free Speed Optimization Audit, Chat on WhatsApp | Skype : oscprofessionals-87 | Email: pallavi@oscprofessionals.com | Hire us | Guaranteed Site Speed Optimization | Website Free Audit | Shopify Theme Customization | Build Shopify Private App | Shopify SEO | Digital Marketing | Oscp Upsell & Cross sell App : Free | Oscp Sales & Volume Discount App : Free | Custom Pricing Wholesale App : Free
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 6

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 6

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
  }
}