3

I've been trying to filters with rest API, but I seem to be struggeling with easy requests. So this one works without any problems

http://myserver/_api/web/lists/getbytitle%28'Tickets'%29/items?$select=AssignedToId

If I try to filter based on this property I receive an error

http://myserver/_api/web/lists/getbytitle%28'Tickets'%29/items?$filter=AssignedToId eq 1

Why is this the case? Isn't it the case that you can filter any property you can find in in the response? Please help me out here.

1 Answer 1

3

This will sound crazy, but change it to filter on "AssignedTo" but keep "AssignedToId" in the select:

http://myserver/_api/web/lists/getbytitle%28'Tickets'%29/items?$select=AssignedToId&$filter=AssignedTo eq 1

The other way to do it would be to use the $expand param:

http://myserver/_api/web/lists/getbytitle%28'Tickets'%29/items?$expand=AssignedTo/Id&$select=AssignedTo/Id,AssignedTo/LastName&$filter=AssignedTo/Id eq 1

EDIT: improved readability

4
  • More info: sympmarc.com/2014/01/21/…
    – Shel
    Feb 19, 2016 at 19:27
  • It really is crazy, but thanks for pointing it out. TaskGroupId behaves in the same way (not sure what it does anyway) so at least it's kind of consitent ;)
    – Andreas
    Feb 22, 2016 at 10:32
  • One more question: If AssignedTo allows multiple values, I can't filter those anymore just like it's the case with view query, right?
    – Andreas
    Feb 22, 2016 at 13:48
  • 1
    I know you can use and/or operators along with (parens) to group parts of the query in $filter. I added a column called "People" that allows the user to select more than one person. I want list items that have both the userID 1 AND 2 in that column, or items that have userId 3: myTestSite.com/_api/web/lists/getbytitle('zShellyTest')/… eq 1 and People/Id eq 2) or People/Id eq 3
    – Shel
    Feb 22, 2016 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.