⚠️ PROBLEM
SharePoint Online REST API to get List items returns only 100 results.A standard REST call to get all Projects, but it returns only 100 projects.
https://c2c.sharepoint.com/sites/SP/_api/web/lists/getbytitle('Code2Care Projects')/items
⚡️ REASON
The REST API has a limit set to return only 100 results by default to protect against developers inadvertently making a request that returns large result sets. The limitation is due to server side paging.⛏️ HOW TO RETRIEVE MORE THAN 100 ITEMS USING REST ?
There are 2 ways,✔️ Use $top parameter to override the limitation and specify how many items to return.
Below REST call example will return 500 results.
https://c2c.sharepoint.com/sites/SP/_api/web/lists/getbytitle('Code2Care%20Projects')/items?$top=500
NOTE - The SharePoint List threshold of 5000 applies to this and you cannot retrieve more than 5000 items. Specifying a value over 5000 will give error, Microsoft.SharePoint.SPQueryThrottledException - The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator.TIP - Use $skiptoken=Paged=TRUE with SharePoint Server 2013.
https://c2c.sharepoint.com/sites/SP/_api/web/lists/getbytitle('Code2Care%20Projects')/items?$top=500&$skiptoken=Paged=TRUE
⛔️ $limit does not work with SharePoint 2013.
✔️ Get 100 results at a time and keep appending. Check if next page exists by using __next.
if (response.d.__next)
{
urlNext = response.d.__next;
//Do something
}
If __next returns a value --> use the url which will return next set of items.If __next is null --> it's the end of the result set and no further values.
⭐ Code with REST query to read more than 5000 items from SharePoint list or document library
var listUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Code2Care Projects')
/items?$select=ProjectID&$top=1000";
var response = response || []; //create variable to store fetched list items
function GetProjectListItems(){
return $.ajax({
url: listUrl,
method: "GET",
headers: {
"Accept": "application/json; odata=verbose"
},
success: function(data){
response = response.concat(data.d.results); //append results to response variable
//Use __next to check if next set of items exist in the result or its null
if (data.d.__next) { //logic to check if further results exist
url = data.d.__next; //returns url to get the next set of items
GetProjectListItems(); //call recursively to fetch results in bunch of 1000 items
}
$.each(response, function(index, listItem) {
//store ProjectID and other column values and perform further actions like displaying
arrayProjectID[index] = listItem.ProjectID;
});
},
error: function(error){
// code to handle error and perform any action
}
});
}
✌️ CONCLUSION
Use __next to check if next set of items exist in the result set and keep appending until you get __next as null. This will ensure you do not encounter the SharePoint List View Threshold limit of 5000 and get all items.
Using $top is a quick and easy solution, but will work only if the list has upto 5000 items and you are sure list/library will never reach the threshold limit.
Comments:
- Why cant' we just increase the threshold for SharePoint 2013? The way we do it for list view threshold?
11 Dec 2020 22:09:13 GMT
- Does Graph API also has this limitation or I can query all list items using Graph query? I want to avoid the loop as I'm having about 100k+ files and folders in my SP 2013 document library.
03 Dec 2020 13:00:30 GMT
- Still getting only 100 results, tried using $top in the rest query but not working. I am using SharePoint Online. Any suggestions?
29 Nov 2020 07:11:28 GMT
- I have SP list with 9000 records, which will increase only by a few items every month, can I use $top=9000 in the REST call and get all together?
23 Nov 2020 11:23:36 GMT
- Further comments disabled!
- SharePoint An unexpected error has occurred - Correlation ID and Merge-SPlogfile
- SharePoint list excel import error - Title is a required filed and can't be empty
- Send Email with attachment using SharePoint PowerShell, SMTP server
- Sharepoint errors were found when compiling the workflow
- How to update SharePoint List Item programmatically
- Merge-SPlogfile PowerShell - SharePoint Correlation ID error
- Get-ADUser PowerShell - Get AD user details using email address
- Restore deleted Office 365 SharePoint group site
- [Solved] SharePoint Access Denied error editing Document Name
- How to migrate SharePoint Designer 2010 workflow to Power Automate FLOW (Microsoft Office 365)
- [Solved] Notepad++ Menu Bar Missing - NotepadPlusPlus
- Copy all .vcf Mobile Contacts files into one .vcf - HowTos
- Add blank lines after each lines using Notepad++ text editor - NotepadPlusPlus
- How to set background color for android layout pragmatically using java and through xml - Android
- Share or Send SMS via Android Intent - Android
- Android Emulator window was out of view and was recentered - Android-Studio
- Multiline EditText in Android Example - Android
- Right Align Text in Bootstrap framework - Bootstrap
- SharePoint 2016 error - Could not find file ManageUserProfileServiceApplicationTenantSimplified.xml - SharePoint
- Division between two numbers - C-Program
- How to send email from JavaScript HTML using mailto - JavaScript
- Android Emulator 5.1.1 not loading on Mac OS X Android Studio - Android-Studio
- How to remove disable google search blue triangle - Google
- How to update Android Studio - Android-Studio
- Add Buttons at the bottom of Android Layout xml file - Android