Search code examples
sharepointmicrosoft-graph-api

Microsoft Graph returns 422 error on querying Sharepoint subsites


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.

enter image description here

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 then 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.

EDIT: full response body

{
    "error": {
        "code":"notSupported", 
        "message": "The request is unprocessable because it uses too many resources",
        "innerError": {
            "date": "2021-07-13T08:21:45", 
            "request-id":"48de58fe-90b5-4a49-8236-e8b2c981e837",
            "client-request-id":"48de58fe-90b5-4a49-8236-e8b2c981e837"
        }
    }
}

Solution

  • After suffering from this issue for a long time, I finally solved this by adding Prefer: apiversion=2.1 as a header to this specific request.


    EDIT:

    This does not seem to be needed anymore and can possibly cause issues. It has been removed from the predefined Postman collection, so I would suggest trying out your request using that configuration.