2

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'))
2
  • Did you try adding /$count to the end of your url? Commented Feb 17, 2015 at 18:57
  • Gives the same result for me (returns the items).
    – matt
    Commented Feb 17, 2015 at 19:10

1 Answer 1

5

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'))
5
  • Thanks, if anyone is wondering the documentation is here: msdn.microsoft.com/en-us/library/office/…
    – matt
    Commented Feb 17, 2015 at 19:31
  • The SP 2010 solution proposed by @Rob is returning errors : "Unsupported media type requested"
    – Aamir
    Commented Jun 24, 2016 at 18:27
  • 1
    I just tried it on my 2013 on-premises farm and my SharePoint Online tenant. It worked in both cases. Commented Jun 24, 2016 at 19:30
  • 2
    The response is just a number in plain text. Maybe that's the issue you're having. Commented Jun 24, 2016 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
    Commented Jul 19, 2016 at 5:55

Your Answer

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

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