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

[Client bug]: BadRequest when using nested select inside expand #1881

Closed
MartinM85 opened this issue May 6, 2023 · 1 comment
Closed

[Client bug]: BadRequest when using nested select inside expand #1881

MartinM85 opened this issue May 6, 2023 · 1 comment

Comments

@MartinM85
Copy link
Contributor

Describe the bug
When using expand with nested select for reading items in SharePoint site's list the SDK generates wrong query.

Let's say I have a request

GET https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items?expand=fields(select=createdDateTime)

It works fines for example from Graph Explorer. Based on the documentation here and here the query is correct and developers are familiar with this syntax and they are used to use this syntax.

The code for the query above is

var result = await graphClient.Sites["{site-id}"].Lists["{list-id}"].Items.GetAsync((requestConfiguration) =>
{
	requestConfiguration.QueryParameters.Expand = new string []{ "fields(select=createdDateTime)" };
});

which looks fine but when executed it fails with the error

Parsing OData Select and Expand failed: Term '(select=createdDateTime)' is not valid in a $select or $expand expression.

The root cause is that SDK generates wrong URL with $expand instead of expand

https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items?$expand=fields(select=createdDateTime)

Workaround
The workaround is to use $select instead of select in Expand.

var result = await graphClient.Sites["{site-id}"].Lists["{list-id}"].Items.GetAsync((requestConfiguration) =>
{
	requestConfiguration.QueryParameters.Expand = new string []{ "fields($select=createdDateTime)" };
});

Additional context
I'm not sure if the issue requires a fix in SDK or in the documentation but if https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items?expand=fields(select=name) is correct syntax then SDK should be able to handle it.

It would be nice if SDK team can discuss the issue with Graph API team.

What I remember the $ prefix is optional only for beta version but v1.0/sites/{site-id}/lists/{list-id}/items endpoint supports both.

@andrueastman
Copy link
Member

Closing this one for now. Documentation updates via microsoftgraph/microsoft-graph-docs-contrib#9127 and upgrade guide includes information via #2275

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