Hello Mangesh Shinde,
I understand you're trying to fetch permissions for multiple OneDrive items using batch requests in the Microsoft Graph Java SDK and facing issues with RequestInformation
and how the response is handled.
The approach you're following uses patterns from earlier SDK versions, which don’t align well with the latest Kiota-based SDK (v6.x+). This newer version changes how requests are built and managed.
In my case, I used Microsoft Graph Java SDK version 5.5.0 with azure-identity for authentication. This combination worked without needing microsoft-graph-core
or microsoft-graph-auth
. Using BatchRequestContent
and BatchResponseContent
, I was able to fetch permissions for multiple items in one call.
Initially, I registered an app in Entra ID and granted it the Files.Read.All
permission (Application type) with admin consent:
Here’s the setup that worked for me:
pom.xml:
<dependencies>
<dependency>
<groupId>com.microsoft.graph</groupId>
<artifactId>microsoft-graph</artifactId>
<version>5.5.0</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.11.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>
<!-- SLF4J with Logback for logs -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.4.14</version>
</dependency>
</dependencies>
Main.java:
package com.example.graphbatch;
import com.azure.identity.ClientSecretCredential;
import com.azure.identity.ClientSecretCredentialBuilder;
import com.google.gson.*;
import com.microsoft.graph.authentication.TokenCredentialAuthProvider;
import com.microsoft.graph.content.BatchRequestContent;
import com.microsoft.graph.content.BatchResponseContent;
import com.microsoft.graph.content.BatchResponseStep;
import com.microsoft.graph.requests.GraphServiceClient;
import java.util.*;
public class Main {
public static void main(String[] args) {
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "off");
long startPermissionsBatch = System.currentTimeMillis();
ClientSecretCredential credential = new ClientSecretCredentialBuilder()
.clientId("yourappId")
.clientSecret("yoursecret")
.tenantId("yourtenantId")
.build();
TokenCredentialAuthProvider authProvider = new TokenCredentialAuthProvider(
List.of("https://graph.microsoft.com/.default"), credential
);
GraphServiceClient<?> graphClient = GraphServiceClient.builder()
.authenticationProvider(authProvider)
.buildClient();
Map<String, String> items = Map.of(
"ItemId1", "DriveId1",
"ItemId2", "DriveId2",
"ItemId3", "DriveId3",
"ItemId4", "DriveId4",
"ItemId5", "DriveId5"
);
Map<String, List<String>> permissionsBatch = new HashMap<>();
try {
BatchRequestContent batchRequest = new BatchRequestContent();
Map<String, String> requestIdToItemId = new HashMap<>();
for (Map.Entry<String, String> entry : items.entrySet()) {
String stepId = batchRequest.addBatchRequestStep(
graphClient.drives(entry.getValue())
.items(entry.getKey())
.permissions()
.buildRequest()
);
requestIdToItemId.put(stepId, entry.getKey());
}
BatchResponseContent response = graphClient.batch()
.buildRequest()
.post(batchRequest);
Gson gson = new Gson();
for (Map.Entry<String, String> entry : requestIdToItemId.entrySet()) {
BatchResponseStep<JsonElement> step = response.getResponseById(entry.getKey());
JsonElement body = step.getDeserializedBody(JsonElement.class);
if (body != null && body.isJsonObject() && body.getAsJsonObject().has("value")) {
JsonArray permissions = body.getAsJsonObject().getAsJsonArray("value");
List<String> summaries = new ArrayList<>();
for (JsonElement permElem : permissions) {
JsonObject perm = permElem.getAsJsonObject();
String userDisplayName = "Unknown";
if (perm.has("grantedToV2") && perm.getAsJsonObject("grantedToV2").has("user")) {
JsonObject user = perm.getAsJsonObject("grantedToV2").getAsJsonObject("user");
userDisplayName = user.has("displayName") ? user.get("displayName").getAsString() : "Unknown";
}
List<String> roles = new ArrayList<>();
if (perm.has("roles")) {
for (JsonElement role : perm.getAsJsonArray("roles")) {
roles.add(role.getAsString());
}
} else {
roles.add("None");
}
summaries.add("Role: " + String.join(", ", roles) + ", User: " + userDisplayName);
}
permissionsBatch.put(entry.getValue(), summaries);
}
}
} catch (Exception e) {
System.err.println("Batch request failed: " + e.getMessage());
}
long endPermissionsBatch = System.currentTimeMillis();
System.out.println("Time required for PermissionsBatch: " + (endPermissionsBatch - startPermissionsBatch) + " ms");
if (!permissionsBatch.isEmpty()) {
System.out.println("Found permissions for " + permissionsBatch.size() + " items.");
permissionsBatch.forEach((itemId, summaries) -> {
System.out.println("Permissions for item: " + itemId);
summaries.forEach(summary -> System.out.println(" - " + summary));
});
}
}
}
Response:
Let me know if you have any other questions or need any further assistance.
Hope this helps!
If this answers your query, do click Accept Answer
and Yes
for was this answer helpful, which may help members with similar questions.
If you have any other questions or are still experiencing issues, feel free to ask in the "comments" section, and I'd be happy to help.