Home > Net >  Get CompanyName for group user using Azure GraphAPI
Get CompanyName for group user using Azure GraphAPI

Time:11-03

I am using GraphAPI from Azure and want to GET data from the API using the graphClient SDK. I want to list all members of a specific group and display some more details about them. The problem is that I miss the property CompanyName in the response from the API (null).

I build the request like this (searchParam is the group id):

await graphClient.Groups[searchParam.ToString()]
                                        .Members
                                        .Request()
                                        .GetAsync(cancellationToken);

Anyone know if I can get the CompanyName in the same request? (I dont want to make another request just to fetch the companyname).

I tried filter and extend methods, but not sure if that is the way to go?

Thanks for your time and help!

CodePudding user response:

try this code pls and it worked for me.

var members = await graphClient.Groups["{group_id}"].Members.Request().Select("id,displayName,companyName").GetAsync();

enter image description here

This is because, when we call list member graph api, it will return a list of directoryObject objects, and user is also a kind of directoryObject. And when enter image description here

  • Related