Microsoft Graph returns 422 error on querying Sharepoint subsites

Tratsaert Stijn 11 Reputation points
2021-07-19T08:13:46.767+00:00

Hi,

My API tries to query the subsites of a site in a huge Microsoft Sharepoint, but the Graph API returns a 422 "The request is unprocessable because it uses too many resources" error.

115826-screenshot-from-2021-07-16-16-33-55.png

The URL I called to achieve this was https://graph.microsoft.com/v1.0/sites/site_id/sites . When using the Graph Explorer, this does return about 8-10 subsites, which are recursively queryable (using their site id in that same URL). This can go about 5 levels deep and each site has a document library with files. In another Sharepoint, my API is able to do this succesfully, because it is way smaller, I assume.

I've also tried using $top and thus limiting the results per response to 1, but that still gave the same error.

Does anyone have an idea how this could be and if there's a workaround for this? Thanks in advance.

Microsoft Security Microsoft Graph
{count} vote

4 answers

Sort by: Most helpful
  1. Ram Vir Singh 0 Reputation points
    2023-02-09T14:09:20.77+00:00

    I have also experiencing same issue. Let me know any workaround for this issue

    0 comments No comments

  2. RahulB 0 Reputation points
    2023-08-08T07:01:13.68+00:00

    I am also facing same issue from very long time. Please help on this. I believe so many people are struggling on this issue.

    Please help. Thank you.

    0 comments No comments

  3. Matthew Watts 25 Reputation points
    2023-08-08T07:06:16.2466667+00:00

    We had this issue when we attempted to retrieve the site pages for a given site. We fixed it by deleting the pages which were no longer in use and bringing the overall count down, preventing this error from appearing.


  4. Ryan Epperson 1 Reputation point
    2023-08-08T16:32:55.15+00:00

    The way I've addressed this is by taking my query and breaking it up into smaller groups so that I don't get back more than 500 results in a query. Sharing the code that I use below as an example.

    $listitems = @()
    $querythreshold = 500
    $listqueries = @()
    
    if(($ticketids[-1]-$ticketids[0]) -ge $querythreshold){
        if($VerboseLog){
            $message = "Query range "+($ticketids[-1]-$ticketids[0])+" is above threshold, breaking query up to gather all results."
            LogIt -level "WARNING" -message $message -LogFile $LogFile
        }
        $startingId = $ticketids[0]
        $endingId = $ticketids[-1]
        do{
            $lowrange = $startingId;
            $highrange = $startingId+($querythreshold-1)
            $listqueries += @('https://graph.microsoft.com/v1.0/sites/'+$siteid+'/lists/'+$listid+'/items?expand=fields(select=TicketID)&$filter=fields/TicketID ge '+"'"+$lowrange+"' AND fields/TicketID le '"+$highrange+"'")
            $startingId = $startingId+$querythreshold
        } while ($highrange -lt $endingId)
        if($VerboseLog){
            LogIt -level "VERBOSE" -message "SharePoint will be queried in $($listqueries.count) queries." -LogFile $LogFile
        }
    } else {
        $listqueries = @('https://graph.microsoft.com/v1.0/sites/'+$siteid+'/lists/'+$listid+'/items?expand=fields(select=TicketID)&$filter=fields/TicketID ge '+"'"+$ticketids[0]+"' AND fields/TicketID le '"+$ticketids[-1]+"'")
    }
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.