question

NeffDesign-5692 avatar image
0 Votes"
NeffDesign-5692 asked NeffDesign-5692 commented

Microsoft Graph: JSON Batching & References

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-files
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Ok i see that you're using JSON batching here with dependson property. I would suggest you to aware the following when you JSON/dependson property,

  • You need to understand that the individual requests can be executed in a specified order by using the dependsOn property. This property is an array of strings that reference the id of a different individual request. For this reason, the values for id must be unique.

  • If an individual request fails, any request that depends on that request fails with status code 424 (Failed Dependency). Most of the scenario's we see the issue here.

  • There are known issues with JSON batching, which you need to aware of - for example, JSON batch requests are currently limited to 20 individual requests.

  • Thoroughly test the API calls in POSTMAN/Graph explorer before you use it in production.


0 Votes 0 ·

HI @Deva-MSFT,

Thank you for your response.

Yes, I'm fully aware of the dependsOn property and understand how that works. My question is, can I use the response from one of the requests as a variable in a subsequent request?

For example, in a single batch call:

  • Request 0 returns an ID of a drive.

  • Request 1 (dependant on request 0) references the Drive ID returned in Request 0

Since I couldn't figure this out, I built my app to have two calls: one to fetch the Drive ID, the second to fetch the permissions of the drive returned in the first call. It works but was trying to see if it was possible in a single batch call.

Thank you!



0 Votes 0 ·

0 Answers