Given a group ID, I wish to retrieve the DisplayName (only) for the group. Using the online Microsoft Graph Explorer, I can do this.
I want to do it from an application in C#. The problem is that there seems to be no way of specifying the $select
parameter (highlighted), since the call graphServiceClient.Groups.GetByIds
uses POST, and no arguments to PostAsync
allow the specification of query parameters.
Is this even possible? It seems like it should work since the call succeeds from the Microsoft Graph Explorer.
What I have tried:
var groups = await graphServiceClient.Groups.GetByIds
.PostAsync(new() { Ids = ids, Types = new() { "group" } }, null, cancellationToken)
.ConfigureAwait(false);
return groups?.Value?.Select(d => ((Microsoft.Graph.Models.Group)d).DisplayName);
works in that it gets ALL the properties including DisplayName
. I want to get just DisplayName
.
Looks like an issue in SDK. Could you please report the issue here:
https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues
As a workaround you can modify query parameters of a request before the request is sent.
var requestInformation = graphClient.DirectoryObjects
.GetByIds
.ToPostRequestInformation(new()
{
Ids = ids,
Types = new() { "group" }
});
requestInformation.QueryParameters["%24select"] = new[] { "displayName" };
requestInformation.UrlTemplate += "{?%24select}";
var result = await graphClient
.RequestAdapter
.SendAsync<GetByIdsResponse>(requestInformation, GetByIdsResponse.CreateFromDiscriminatorValue);