When I go to a specific folder in Sharepoint, I hit an error that I have exceeded the view threshold of 5000 items. I created a new view to only show items when the ID < 5000, I am able to see the folder contents now.

However, how do I apply a specific view/filter when using Python?

Using Python's request module, I have:

requestUrl = sharePointUrl + "/{0}/_api/web/GetFolderByServerRelativeUrl('/{0}/{1}')/Files".format(site, folder)
headers={'Content-Type': 'application/json; odata=verbose', 'accept': 'application/json;odata=verbose'}
requests.get(requestUrl , headers=headers).json()

which returns {'d': {'results': []}}

If I modify the requestUrl to include ?$top=1000 or ?$filter=Id lt 1000, I still have an empty result (no throttled error, just empty result)

How do I apply the filters correctly or use a specific view when running the request query?

(I used a different folder name and I get an error 'Field or property "Id" does not exist.' so clearly something is wrong with my query too but I am not sure why the other folder returns empty result and not an error)

  • Having more than 5000 items in a single library and single folder is not a best practice and must be avoided. If you cannot rearrange items in multiple library or folders then you have to tune your query in a way you always retrieve less than 5000 items per call. sharepoint.stackexchange.com/a/136002/55933 this solution is not intended for Python but probably can lead to a solution. Using CAML query in viewXml variable you can adjust calls to many other current and future needs. viewXml can define, among others, <RowLimit> tag. Feb 18 at 21:00


Your Answer

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