An API that connects multiple Microsoft services, enabling data access and automation across platforms
Filtering on the name property in this scenario is not supported the way the request expects.
For OneDrive for Business and SharePoint Online, the optimized and supported filterable properties for items are limited. For drive items, filtering is optimized for properties such as:
- createdDateTime (with gt, ge, lt, le)
- lastModifiedDateTime (with gt, ge, lt, le)
- file
- folder
- image
- video
- deleted
In OneDrive for Business, SharePoint Online, and SharePoint Server 2016, filtering is only supported on the name and url properties in the context of search results, not for arbitrary item listing endpoints. The example where filter on name is used is specifically on a search request:
GET /drive/root/search(q='vacation')?filter=image ne null and file ne null
This means:
-
$filteronnameis not guaranteed to work or be efficient on/itemscollections. - Using
contains(name,'test'),startswith(name, ...), oreqonnamein/itemscan lead to unexpected behavior, including apparently random results or ignoring the filter.
Because of these limitations, the behavior observed (only $top=1 being honored and the filter not affecting results) is expected for that endpoint.
To filter by name reliably, use the search API over drive items (for example, search on a drive or drive root) and then apply supported filters (such as file ne null and image ne null) on the search results, rather than on /items directly. Note that access to the Microsoft Search API and its scopes/roles is required; if only Sites role is granted and the Search API cannot be used, there is no supported way in this context to do server-side contains/startswith filters on item names under /items.
References: