Microsoft Graph: JSON Batching & References

Neff Design 6 Reputation points
2021-04-20T22:12:28.743+00:00

I need to make a request to fetch the folder ID's in OneDrive and then subsequently fetch the permissions of those folders. I think I've determined there is not a single request to return all of this, but I was attempting to use batching in a single request.

The issue I can't solve is the ability to take the folder(s)' ID from the first GET and use it in the dependant/subsequent GETs.

Starting to believe it's not possible.
Request:

POST https://graph.microsoft.com/v1.0/$batch  
Accept: application/json  
Content-Type: application/json  

Body:

{  
    "requests": [  
        {  
            "id": "1",  
            "method": "GET",  
            "url": "/me/drive/items/{item-id}/children?$select=name,id"  
        },          
        {  
            "id": "2",  
             "dependsOn": [ "2" ],  
            "method": "GET",  
            "url": "/me/drive/items/{item-id: returned from ID-1}/permissions?$select=link"  
        }  
    ]  
}  

The first request in the batch returns an array of folder objects, each with the unique ID of the folder {item-id}.
I need to extract the IDs (1 to many) from the first response and reference them in the subsequent request to return the permissions of that folder/item.

Or if there is a way to return the permissions along with the folder/item details, but I have found this to not be possible.

If I can't do this as a "batch", my alternative is to make two calls: (1) get the folder(s) ID, (2) Process the data and make a separate call to return the permissions.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,002 questions
{count} vote

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.