How do I get the total number of items in a list based on a filter. For example:

How many fruits in the SharePoint list, "Fruits", are red?

I can get the items themselves like below, but I just want the number.

_api/web/lists/getbytitle('Fruits')/items?$filter=((color eq 'red'))
  • Did you try adding /$count to the end of your url? Feb 17 '15 at 18:57
  • Gives the same result for me (returns the items).
    – matt
    Feb 17 '15 at 19:10

According the OData spec there are supposed to be operations like count and inlinecount but, as far as I've seen, they don't work with the SharePoint 2013 REST API.

Your best bet is to run the query you have above and then check the length property of the array that's returned.

Update: I just though of another option, using the SharePoint 2010 REST API. Your query would look like

_vti_bin/ListData.svc/Fruits/$count?$filter=((color eq 'red'))
  • Thanks, if anyone is wondering the documentation is here: msdn.microsoft.com/en-us/library/office/…
    – matt
    Feb 17 '15 at 19:31
  • The SP 2010 solution proposed by @Rob is returning errors : "Unsupported media type requested"
    – Aamir
    Jun 24 '16 at 18:27
  • 1
    I just tried it on my 2013 on-premises farm and my SharePoint Online tenant. It worked in both cases. Jun 24 '16 at 19:30
  • 2
    The response is just a number in plain text. Maybe that's the issue you're having. Jun 24 '16 at 19:33
  • @Rob, you are right! That was the problem indeed. Now I am trying to figure out how to retrieve that number in SP designer WF. What path should I be specifying. d/results and value won't work.
    – Aamir
    Jul 19 '16 at 5:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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