Given a customer ID, I’m trying to fetch all segments that customer is in via the Admin API. Is there any way to accomplish this? Things I’ve tried with no success:
Finding a field on the customer object that has this data - nothing seems relevant.
Starting from segments and filtering by customer using query - this doesn’t work because the only supported filter name on this resource is name.
My ideal output is a cursor of Segment objects, but any response would be helpful.
To answer my own question in case anyone stumbles upon this in the future, this might not be the most elegant solution, but it’s the best thing I’ve come up with so far:
First fetch the global IDs of all segments in the shop.
{
segments(first: 10, after: "abc") {
edges {
node {
name
id
}
}
}
}
Then use customerSegmentMembership to fetch whether or not a user is in each segment. The entire response has a query cost of 2 regardless of how many segments you check: