Get all customers with a specific tag in Admin API

Hi all,

I’m attempting to retrieve all customers that have a specific tag using GraphQL in the Admin API. I’ve tried the following:

query {
  customers(first: 25, query:"tag:b2b") {
    edges {
      node {
        id,
        email,
        tags
      }
    }
  }
}

But I get the following warning:

"warnings": [
    {
        "field": "tag",
        "message": "Invalid search field for this query."
    }
]

In the docs it looks as though I can’t filter on tag or tags - if that is the case, how can I retrieve all customers with a specific tag, without retrieving all customers are filter by tag after the API call?

Thanks

Your syntax looks correct, and I just tested this with my own customer tag and it worked with no issues. Are you running that query from the Shopify GraphiQL App?

Hi @Ricky_Kissoon - yes I’m running it from the Shopify GraphiQL App… That’s where I’m seeing the error message. Will that not return the same results?

Thats where I tested as well. I copied and pasted your query as is and it worked perfectly for me.

Just to be nitpicky, you’re certain that your API schema is set to “Admin”?
Which API version are you using?

That’s strange. You can see the error in the attached screenshot. The query currently returns all customers with any mention of b2b in their profile.

Sorry, I was mistaken. It also fails for me, and it also fails with Shopify’s other customer query examples.
I tried with the following structure and it failed, even tried with state:enabled and that failed.

Hi @Ricky_Kissoon

You can try using customerSegmentMembers

{
  customerSegmentMembers(first: 5,query:"customer_tags CONTAINS 'VIP'") {
    edges{
        node{
            id
            lastName
            firstName
            
        }
    }
  }
}
2 Likes

This works as expected, thank you :smile:!