Dogu Arslan
Dogu Arslan

Reputation: 3384

How to get All Users in the organization with their member Groups using MS Graph in a single request

Is there a way to retrieve Users in an organization including Groups that each User is a member of, in a single call to Microsoft Graph?

Something like https://graph.microsoft.com/v1.0/users?$expand=MemberOf

This call does not return the Member groups. If I call the beta endpoint with same URL though I get the member groups in the response. the problem with the beta end point is that it returns a big response and I could not find a way to combine $expand with $select to only return the MemberOf property for each User and User's id field.

Upvotes: 0

Views: 1862

Answers (3)

JTvermose
JTvermose

Reputation: 342

As other has mentioned, it's not possible with a single request.

For retrieving all users of our organization, and the groups they are members of, I resolved to this

This produced a list of groups, each with a list of all users that are directly or indirectly (user could be a member of a group that the original group has as a member). Should be relatively easy to convert it to a list of users each with a list of groups they are members of, if that is what you need.

Upvotes: 0

Keen Jin
Keen Jin

Reputation: 1138

According to the introduction of this document, "with Azure AD resources that derive from directory Object, like user and group, $expand is only supported for beta and typically returns a maximum of 20 items for the expanded relationship".

Base on my test, you can use this API below to list out all the memberof.

'GET /users/{id | userPrincipalName}/memberOf

So there is no way to retrieve Users in an organization including Groups that each User is a memberof by using a single call to Microsoft Graph.

Upvotes: 1

SunnySun
SunnySun

Reputation: 1935

This call does not return the Member groups. If I call the beta endpoint with same URL though I get the member groups in the response. the problem with the beta end point is that it returns a big response and I could not find a way to combine $expand with $select to only return the MemberOf property for each User and User's id field.

Not all relationships and resources support the $expand query parameter, $expand is only supported for beta and typically returns a maximum of 20 items for the expanded relationship. And not all resources or relationships support using $select on expanded items, I also tried https://graph.microsoft.com/beta/users?$expand=memberOf($select=id,name) in beta, the error prompts valid for this. For the details, please read here.

Upvotes: 2

Related Questions