I need to query items in a given folder and all of its children in a document library with as few APIs as possible.
The ideal solution seemed to be getItems
with Scope='RecursiveAll'
and a FolderServerRelativePath
. However the API below returns an SPQueryThrottledException
for a specific document library on Sharepoint Online, and I can't figure out the reason.
POST <web-url>/_api/Web/Lists(<list-id>)/getItems?$select=*,FileRef
POST BODY:
{
"query": {
"odata.type": "SP.CamlQuery",
"ViewXml": "<View Scope='RecursiveAll'><RowLimit>1</RowLimit></View>",
"DatesInUtc": true,
"FolderServerRelativePath": {
"DecodedUrl": "<subfolder's-server-relative-path>"
}
}
}
Some observations:
- The subfolder has 4 files and no folders in it.
- Getting items under any folder in the document library fails with the same error
- The document library has around 6.5k items (folders+files) in it
Scope='Recursive'
also fails, but'Default'
and'FilesOnly'
work fine- The same query worked for another document library with 100k files
What's the problem with the query? How can I fix it? If it's impossible to fix, are there any other APIs that can recursively query items in a folder?