customer groups or tags

Highlighted
Shopify Partner
22 1 3

Hi

I hope everyone is doing great.
My question is about customer groups or tags.

 

Is there any API call to get all existing customer groups or customer tags of a store?

or any suggestion?

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1129 82 179

Hello @Muhammad_Asfar , 

 

By customer groups I'm assuming that you mean batches of customers that have been saved in the Shopify admin, to retrieve those you can use the CustomerSavedSearch endpoint

 

However, to get all tags attached to customers, there isn't a REST endpoint available to fetch all tags that I'm aware of - you have to paginate through all customers on a shop and record the tags manually. Unless you have access to a shop's admin area, in which case you can use the web browser to go to `/admin/customers/tags.json` and that will list all the tags in the browser for you. 

 

Alternatively, GraphQL is able to retrieve customers tags as well. Here's an example GraphQL query that can get tags for you : 

 

{
  customers(first: 250) {
    edges {
      node {
        id
        tags
      }
    }
  }
}
1 Like
Highlighted
Shopify Partner
22 1 3

hi @Josh

Thank so much for detailed suggestions.

Sorry for late reply.

I did not see any Customer Saved Search assigned to customer by getting a customer using Customer API.
Secondly, I cannot access to a shop's admin area in the web browser to go to `/admin/customers/tags.json` using Public App.

Alternatively, GraphQL is able to retrieve customers tags. That is a feasible solution in my case but did not know about GraphQL API rate limit.

Thanks again!

0 Likes
Highlighted
Shopify Partner
22 1 3

@Josh One thing more in using this GraphQL API

 

{
  customers(first: 250) {
    edges {
      node {
        id
        tags
      }
    }
  }
}

Response:

stdClass Object
(
    [edges] => Array
        (
            [0] => stdClass Object
                (
                    [node] => stdClass Object
                        (
                            [id] => gid://shopify/Customer/2099424444154
                            [tags] => Array
                                (
                                    [0] => Wholesaler
                                )
                        )
                )
            [1] => stdClass Object
                (
                    [node] => stdClass Object
                        (
                            [id] => gid://shopify/Customer/2099000042090
                            [tags] => Array
                                (
                                    [0] => shopkeeper
                                )
                        )
                )
            [2] => stdClass Object
                (
                    [node] => stdClass Object
                        (
                            [id] => gid://shopify/Customer/2102430456722
                            [tags] => Array
                                (
                                    [0] => Wholesaler
                                )
                        )
                )
        )
)

 
Issue in response:
it is duplicating tags records (Wholesaler) and if there is no tag for customer it will show empty array. so basically it is showing number of tags records equal to number of existing customers.
How to avoid duplication and empty arrays?
BTW response of this call `/admin/customers/tags.json` in the browser is fine and show tags without duplication and empty results.

Note: I am new in using GraphQL

 

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1129 82 179

Hey again @Muhammad_Asfar , 

 

This is normal - what you are doing with that call is searching through 250 customers and returning their tags, you are not searching for tags specifically. So that call will find the first 250 customers on a shop and list their tags for you - regardless of whether or not more than one customer has the same tag. 

 

The same would happen if you were to use REST and send a GET request to /admin/customers.json?limit=250 - it will list 250 customers and their associated information (including tags) - but it won't just list unique tags, it will list every customer and whatever tags happen to be attached to them. You would have to look at the tags and remove any duplicates yourself if you only wanted to have ones that were unique. 

0 Likes