Brett
Brett

Reputation: 321

Error when using $select and $expand with Odata v4.0 on Web API 2.2

I have a web api 2.2 that is configured for OData v4. I want to return a user by ID and include only the user group Id's that the user is a member of. When I do this

http://localhost/User?$filter=id eq 312&$select=*,userGroups/id&$expand=userGroups

I get this error

The query specified in the URI is not valid. Found a path with multiple navigation properties in a select clause. Please reword your query such that each level of select or expand only contains either TypeSegments or Properties.

Found a path with multiple navigation properties in a select clause. Please reword your query such that each level of select or expand only contains either TypeSegments or Properties.

The query will execute if I remove ",userGruops/id"

Upvotes: 7

Views: 8579

Answers (2)

strattonn
strattonn

Reputation: 2002

The Beta version of the API handles

https://graph.microsoft.com/beta/users?$select=id,surname&$expand=manager($select=id)

Upvotes: 0

Yi Ding - MSFT
Yi Ding - MSFT

Reputation: 3014

You should write your query like this:

http://localhost/User?$filter=id eq 312&$select=*&$expand=userGroups($select=id)

By the way, you can also remove the $select=* segment as all non-navigation properties are by default included in the response.

Upvotes: 5

Related Questions