Facing issue in accessing method GetGroupMembers

Pardeep Kumar 0 Reputation points
2024-04-04T09:38:54.4933333+00:00

Hi,

Previously, I was using Microsoft.Graph (version 3.35.0) and Microsoft.Graph.Core (version 1.25.1). Recently, I upgraded Microsoft.Graph to version 5.46.0 and Microsoft.Graph.Core to version 3.1.10. As per the documentation, I changed the way to create GraphServiceClient. But, as shown in screenshot, I am facing in accessing method GetMemberGroups.

User's image

Might be this have been changed in the new/latest version.

Can anyone please help me to resolve this?

Any help, will be much appreciated.

Thanks

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,042 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yakun Huang 85 Reputation points
    2024-04-08T08:26:34.6033333+00:00

    Hi @Pardeep Kumar,

    After Microsoft.Graph version 5.0, calling the GetGroupMembers method has been deprecated, because you updated the version, so you can no longer get Group memberships like this, I have tested for your needs and successfully returned the result, my code is as follows, please try the following.

    using Microsoft.Graph.Users.Item.GetMemberGroups;
    
    var requestBody = new GetMemberGroupsPostRequestBody
    {
        SecurityEnabledOnly = false,
    };
    var userId = "{user-id}";
    var groupsUser = Task.Run(async() => await graphClient.Users[userId].GetMemberGroups.PostAsGetMemberGroupsPostResponseAsync(requestBody)).Result;
    

    For more usage, please refer to the link below.

    https://learn.microsoft.com/en-us/graph/api/directoryobject-getmembergroups?view=graph-rest-1.0&tabs=http

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.