When using the ItemCount function on the / folder, the count is 0.

The result of GET /_api/web/GetFolderByServerRelativeUrl('/')/ItemCount is:

  "d": {
    "ItemCount": 0

But the content is actually not empty as it contains all the system related files as well as the user created libraries.

I can't seem to find anything about this on google or the sharepoint api documentation.

Is there another way to get it? I know it's possible to count items in a library using the list functions, but a folder is not list.

  • 3
    Are you aware of that GetFolderByServerRelativeUrl returns items only and only if they are located at the very level specified inside the ('<level>')? That means that your query would return the ItemCount of items at the /-level of your hierarchy, but not below that level.
    – moe
    Commented May 30, 2017 at 13:33
  • good find, moe!
    – Mike
    Commented May 30, 2017 at 15:28
  • @moe Thanks for the answer! Yes, but there are items at the /-level, this is precisely what I'm trying to access. There are in reality 13 folders and 2 files that are returned at that level when not using the ItemCount function. That's why I'm confused
    – Ganitzsh
    Commented May 31, 2017 at 7:34

1 Answer 1


I think you are facing a similar restriction as in this existing question: Getting an ItemCount with filtering in SP2013 using REST api.

To quote Vadim:

"The ItemCount function could be applied to List resource [...] but not to ListItemCollection resource".

This same restriction would apply to FileCollection resource and FolderCollection resource, which - if I'm correct - the / level would represent either of.

ItemCount's description is the following:

Gets a value that specifies the count of items in the list folder.

This would mean, that a sub-directory (i.e. a type of SP.Folder) would be applicable


Note, that by using GetFolderByServerRelativeUrl can be returned items, so e.g. Folders would be excluded.

  • Thanks for the link. I think / is indeed a Collection, it works with subfolders so I guess you're right. It is confirmed as well when trying to use the ListItemAllFields on GetFolderByServerRelativeUrl('/') which is giving the following error: The object specified does not belong to a list.. So far, using ItemCount on other folders is giving the correct amount of files AND folders.
    – Ganitzsh
    Commented May 31, 2017 at 9:26

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.