Get list of all users with the id of group in which user is member using azure graph api

Viewed 639

I want the list of groups in which the user is a member of the Azure AD B2C group using the azure graph API in a single request.

I am able to get the list of users but however the MemberOf property of the Microsoft.Graph.User class is null.

 // Get all users (one page)
var result = await _graphClient.Users
    .Request(queryOptions)
    .Filter("userType eq 'member'")
    .Select($"id,displayName,identities,memberOf")
    .GetAsync();

Here I am getting all users, but the groups are not returned in which the user is a member.

Is it possible to get the group's name in the above single request?

Yes, I know I can call another API separately for each and every user, but I want in a single call.

1 Answers

Please try by including memberOf as Expand parameter. Something like:

var result = await _graphClient.Users
    .Request(queryOptions)
    .Filter("userType eq 'member'")
    .Select($"id,displayName,identities")
    .Expand("memberOf")
    .GetAsync();
Related