Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot supply query parameters to GraphServiceClient.DirectoryObjects.GetByIds #2206

Closed
shripathi-kamath opened this issue Nov 9, 2023 · 1 comment

Comments

@shripathi-kamath
Copy link

shripathi-kamath commented Nov 9, 2023

Describe the bug
Given a group ID, I wish to retrieve the DisplayName (only) for the group. Using the online Microsoft Graph Explorer, I can do this successfully.

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.DirectoryObjects.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.DirectoryObjects.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.

To Reproduce
Steps to reproduce the behavior:

  1. Go to Microsoft Graph Explorer online
  2. Log in using some credentials to an AAD
  3. Get a list of groups
  4. Note down one of the group IDs
  5. See the attached image to enter a request, with query parameters
  6. Execute and see that it works, you get the DisplayName.
  7. Next, use the C# code it suggests.
  8. The suggested code does not even compile:
var graphClient = new GraphServiceClient(requestAdapter);

var requestBody = new Microsoft.Graph.Groups.GetByIds.GetByIdsPostRequestBody
{
	Ids = new List<string>
	{
		"00a92ef6-xxx-xxxx-xxxxxxxxe1",
	},
	Types = new List<string>
	{
		"group",
	},
};
var result = await graphClient.Groups.GetByIds.PostAsync(requestBody, (requestConfiguration) =>
{
	requestConfiguration.QueryParameters.Select = new string []{ "displayName" };
});

Expected behavior
Some means to be provided such that the PostAsync API takes in query parameters.

Screenshots
MicrosoftGraphQuestion

Client version
Microsoft.Graph 5.12.0

Desktop (please complete the following information):

  • Browser: Chrome

Additional context
A workaround was made available by a kind soul here: https://stackoverflow.com/a/77451153/4522810
It works with a minor correction to the escaped version of $select.

@andrueastman
Copy link
Member

Thanks for raising this @shripathi-kamath

This is a metadata issue tracked now via microsoftgraph/msgraph-metadata#495. We'll close this issue for now and track this via the duplicate issue at #1975

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants