The main issue could be related to using $top
and $orderby
with $count=true
. When you apply pagination ($top
and $skip
), SharePoint REST API might not always provide the total count as expected.
Here is a slightly adjusted version of your query that might help:
https://example.sharepoint.com/_api/web/lists/getbytitle('DocLibrary1')/items?$select=FileLeafRef&$filter=FSObjType eq 0 and substringof('File1', FileLeafRef)&$count=true
In this case, we’re simplifying the query by removing $top
, $orderby
, and $expand
. The result will give you the total count of all the items that match the filter, and then you can use pagination with another query for the actual item data:
https://example.sharepoint.com/_api/web/lists/getbytitle('DocLibrary1')/items?$select=*,FileLeafRef,FileRef,Author/Title,Editor/Title,File/Length&$expand=Author,Editor,File&$top=50&$filter=FSObjType eq 0 and substringof('File1', FileLeafRef)&$orderby=Modified desc