Search code examples
searchsharepointmicrosoft-graph-api

Finding if a user ever created an item in a SharePoint List with more than 5000 items for most users


I need to program a simple answer if a user ever added an item to a very big list (over 6000 items). If use SharePoint REST, for most users, the result will be error:"The attempted operation is prohibited because it exceeds the list view threshold." Using graph items query also returns "The request is unprocessable because it uses too many resources"

I wonder if the graph "/search/query" will do the trick but I do not know how to phrase the queryString to include the site,list and user ID. The number of hits will be enough. Anyone knows how to build the query String? Thank you


Solution

  • I don't have a list with more than 5000 items, but search API can help

    POST https://graph.microsoft.com/v1.0/search/query
    
    {
        "requests": [
            {
                "entityTypes": [
                    "listItem"
                ],
                "query": {
                    "queryString": "authorOWSUSER:\"[email protected]\" AND path:\"https://contoso.sharepoint.com/sites/{site_name}/Lists/{list_name}\""
                },
                "fields": [
                    "id",
                    "title",
                    "author",
                    "authorOWSUSER"
                ],
                "size": 1
            }
        ]
    }
    

    Apply filter to managed property authorOWSUSER which shows who created the item. You can specify either email or name of the user.

    To reduce the scope to a particular SharePoint list, use path property.

    The size property is set to 1 to return one result if you need only to check if any item was created by the user.