Reputation: 2723
I have an OData end point using OData V4. When I do a GET
https://localhost:323/Staff?$Filter=Company+eq+Microsoft
then I would get the multiple people back each with this basic JSON data:
"Company": "Microsoft",
"LastName": "Bob",
"FirstName: "Saget",
"Details": [
{
"Age": "63",
"Sex": "Male"
}]
How would I write a URL to query using OData convention if I want to find all staff who work for Microsoft and has age bigger than 30?
My attempt failed with couple of the version of URL below:
https://localhost:323/Staff?$Filter=Company+eq+Microsoft+and+Details/Age+gt+30
https://localhost:323/Staff?$Filter=Company+eq+Microsoft+and+$expand=Details($Filter=Age+gt+30)
Upvotes: 1
Views: 7366
Reputation: 1370
I tried your examples and had trouble with using $Filter as opposed to $filter. When I used that on OData's own official website endpoints, it did not like $Filter
but would work with $filter
.
Your example might work if you set $Filter
to $filter
? Have you tried it?
https://localhost:323/Staff?$filter=Company+eq+Micrsofoft+and+Details/Age+gt+30
My answer above is based off of trying it on OData's website (copy and paste this and try it yourself, this works and uses nested property in the filter):
https://services.odata.org/V4/OData/OData.svc/PersonDetails?$filter=(Address/City eq 'Boise' and PersonID gt 0)
So I think this will work:
https://localhost:323/Staff?$filter=(Company eq 'Microsoft' and Details/Age gt 30)
Btw, "Microsoft" was misspelled in your example query. That too can effect your results and expected output, since your JSON example has it spelled correctly.
Upvotes: 1