A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
The customer segmentation dashboard has rolled out and merchants are starting to create new, interesting segments with the more powerful query builder. Which is great.
I would like to use these segments in a customer tagging automation, but I don't see how to get the customer ID from the CustomerSegmentMember object.
I realize that I can use the email in the defaultEmailAddress to do a lookup using a filtered customers query... but that seems so inefficient. So for a list of say 1000 customers, I would then need to make 1000 separate queries to get their customer IDs to then pass to my tagging automation.
Heck, even a segment_id filter in the customers query would work.
Are there plans to implement either of those?
Solved! Go to the solution
This is an accepted solution.
Hello @tekhaus ,
The actual id at the end of the object being returned is the same between Customer and CustomerSegmentMember. So if you have a customer with ID "8675309", it would return as "gid://shopify/Customer/8675309" when queried via Customers, or "gid://shopify/CustomerSegmentMember/8675309" when queried via Customer Segment. The object name changes (Customer vs CustomerSegmentMember) but the id itself is always static and global.
You generally won't be able to receive a customer id under the format of "gid://shopify/Customer" when querying CustomerSegmentMember, but you may be able to use some logic in your app so that any CustomerSegmentMember ids you query have their id values re-applied to the appropriate object name.
To learn more visit the Shopify Help Center or the Community Blog.
Did you get any update for this ?
Hello @tekhaus ,
Customer ID is available on CustomerSegmentMember as customerSegmentMember.id.
You could run a query such as:
query {
customerSegmentMembers(segmentId: "gid://shopify/Segment/123456789" first:10) {
edges {
node {
id
firstName
lastName
}
}
}
}
This would return ids for each customer in the form of:
"id": "gid://shopify/CustomerSegmentMember/123456789"
Hopefully this helps!
Best,
To learn more visit the Shopify Help Center or the Community Blog.
Hi Graham, I appreciate the response.
The customer segment ID doesn't seem to be usable anywhere outside of segments. I tried it in a tagsAdd mutation (in GraphiQL app, 2022-04 Release candidate), and received back an invalid ID error.
I need to be able to get the customer gid (e.g. gid://shopify/Customer/1234567890), so that I can use it as needed with existing GraphQL API queries and mutations.
Is there a way to get that customer ID from the Segmentation API?
This is an accepted solution.
Hello @tekhaus ,
The actual id at the end of the object being returned is the same between Customer and CustomerSegmentMember. So if you have a customer with ID "8675309", it would return as "gid://shopify/Customer/8675309" when queried via Customers, or "gid://shopify/CustomerSegmentMember/8675309" when queried via Customer Segment. The object name changes (Customer vs CustomerSegmentMember) but the id itself is always static and global.
You generally won't be able to receive a customer id under the format of "gid://shopify/Customer" when querying CustomerSegmentMember, but you may be able to use some logic in your app so that any CustomerSegmentMember ids you query have their id values re-applied to the appropriate object name.
To learn more visit the Shopify Help Center or the Community Blog.
Ah ha! That did indeed work. Thank you!
...but the id itself is always static and global.
And it sounds like I can confidently build lasting solutions around this switcheroo method.