none
SPQueryThrottledException while calling REST? RRS feed

  • Question

  • I want to get top 5 highly replied discussion topic item from discussion list. My discussion list contains more than 30000 items and got list threshold issue. Please advise. Thaks in advance.

    "{"error":{"code":"-2147024860, Microsoft.SharePoint.SPQueryThrottledException","message":{"lang":"en-US","value":"The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator."}}}"

    function getHighestReplies(){   
        var url_spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Discussions%20List')/items?$top=5&$select=ID,Title,Body,Author/Title,Created,Folder/ItemCount&$filter=ContentType eq 'Discussion'&$expand=Folder/ItemCount,Author/Id&$orderby=ItemChildCount desc";
        console.log (url);
        $.ajax({
            url:url,
            type: "GET",
            headers: {
                "accept": "application/json;odata=verbose",
                "content-type": "application/json;odata=verbose",
            },
            success: function (data) {
                var items=data.d.results.sort(function(a, b) {
                    return ((a.Folder.ItemCount == b.Folder.ItemCount) ? 0 : ((a.Folder.ItemCount < b.Folder.ItemCount) ? 1 : -1 ));                
                });
                var lis="";
                $.each(items,function(i,item){
                    lis+="<li class='ms-comm-postListItem'><p>Replies:"+item.Folder.ItemCount+"</p><p>Title: "+item.Title+"</p><p>"+item.Created+"</p></li>";
                });
                $('div#divHighlyRepliedDiscussions').html(lis);
            },
            error: function (error) {
                console.log(error);
            }
        });

    }


    • Edited by MC ROY Wednesday, November 27, 2019 12:53 PM
    Wednesday, November 27, 2019 12:52 PM

Answers

  • Hi Roy,

    Try to index the column "ContentType" and columns used in $select and do a paging query as the solution below:

    REST api querying large list

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Thursday, November 28, 2019 5:07 AM

All replies

  • Hi,

    Please check the items count under 'ContentType eq 'Discussion''. I guess it exceeds the threshold. If so, please narrow your filter.

    For example, add a date time range.


    Justin Liu Office Apps & Services MVP, MCSE
    Senior Software Engineer
    Learn Microsoft 365 from Microsoft DOCs now!
    Please Vote and Mark as Answer if it helps you.

    Thursday, November 28, 2019 1:25 AM
  • Hi Roy,

    Try to index the column "ContentType" and columns used in $select and do a paging query as the solution below:

    REST api querying large list

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Thursday, November 28, 2019 5:07 AM