0
votes

I want to fetch all users together with their group names from MS Graph API. It works as long as I don't want to do some advanced filtering (endsWith()).

Here's the select query I'm running:

https://graph.microsoft.com/v1.0/users?$select=displayName,userPrincipalName,mail,id,givenName,surname,memberOf&$expand=memberOf($select=displayName)

It produces a nice set of users together with the display name's of groups they are in. I wanted to restrict the result to a specific mail domain (i have added ConsistencyLevel: eventual), however I am unable to do it unless I remove the memberOf expand. This works:

https://graph.microsoft.com/v1.0/users?$select=displayName,userPrincipalName,mail,id,givenName,surname,memberOf&$count=true&$filter=endsWith(mail,'@somedomain.com')

But as expected, there are no groups. In fact, there are no groups at all despite selecting memberOf! I thought I'll just fetch groups first and then pair them in my code, but to get them I must expand, and with expand the filter doesn't work!

This produces an Request_UnsupportedQuery error:

https://graph.microsoft.com/v1.0/users?$select=displayName,userPrincipalName,mail,id,givenName,surname,memberOf&$expand=memberOf($select=displayName)&$count=true&$filter=endsWith(mail,'@somedomain.com')

Is there any way to achieve what I want without filtering manually or issuing multiple requests and mapping stuff on my own? We're talking about directories containing tens of thousands of users.. Graph seemed to be nice at the beginning but as I wanted to do anything more complex it turns out to be a limited POS where one query totally excludes another. I was also unable to filter by the expanded memberOf in any way

1

1 Answers

0
votes

Based on Microsoft Docs

$expand is not currently supported with advanced queries.