10

I would like to list all users. For each user, I need to display the roles and groups specific to that user.

I tried:

https://graph.microsoft.com/v1.0/users?$expand=memberOf

But it gives exactly the same result as:

https://graph.microsoft.com/v1.0/users

According to the doc for the user object (http://graph.microsoft.io/en-us/docs/api-reference/v1.0/resources/user), I should be able to list the roles and groups for the user by using the memberOf relationship.

I can get the roles and groups I need for every user by doing one request per user (using https://graph.microsoft.com/v1.0/users/{user_id}/getMemberObjects) but it's a bit slow and overkill.

What am I missing?

Michael
  • 1,557
  • 2
  • 18
  • 38

1 Answers1

9

Expanding navigation properties on user entities is currently not working on the production (v1.0) version of the Microsoft Graph endpoint. The functionality is live on the beta endpoint.

This query works as you desire:

https://graph.microsoft.com/beta/users?$expand=memberOf

There is no timeline on when features move from beta to v1.0 or whether they even will in the current form.

Currently, you have 3 choices using the Microsoft Graph APIs.

Beta endpoint

Use the beta endpoint but understand that it may change in functionality.

Multiple Graph Calls

Fetch the users collection then fetch the memberOf for each user as you need it.

https://graph.microsoft.com/v1.0/users/{id}/memberOf

or

https://graph.microsoft.com/v1.0/users/{user_id}/getMemberObjects

Expand members on Groups

If you want to stick with the v1.0 endpoint and depending on your overall goal, you can attempt to go about finding the information you want the other way. Get the collection of groups and expand the members navigation property instead.

https://graph.microsoft.com/v1.0/groups/?$expand=members
  • beta is not working right either for the following request: https://graph.microsoft.com/beta/users/{id}?$expand=directReports. In v1 it does nothing, in beta it expands every single navigation property on the user and on all the children's navigation properties as well. Combining expand with select in beta has no effect. – Marmoy Aug 02 '17 at 10:56
  • 3
    Assuming you're related to the msgraph project, you should change the documentation here https://developer.microsoft.com/en-us/graph/docs/overview/query_parameters to state that the expand query is not supported, I'm sure it would save developers a lot of headache. – Marmoy Aug 02 '17 at 11:05
  • `https://graph.microsoft.com/beta/users?$expand=memberOf` does not work for me. I get back a `Request_UnsupportedQuery` error message. – Andrei Bazanov Aug 29 '19 at 14:55