Get Content stops working intermittently and throws com.microsoft.graph.core.ClientException: Error executing the request
Hi Team,
We have an application which reads the Sharepoint path and downloads the contents of the files present in the path using Graph API Java SDK.
The application has SharePointSites.selected Graph API permissions enabled on Azure. The application also has ReadWrite access to the SPO site.
List Children : GET /drives/{drive-id}/root:/{path-relative-to-root}:/children. Reference: List the contents of a folder - Microsoft Graph v1.0 | Microsoft Learn
Get content : GET /drives/{drive-id}/items/{item-id}/content
Both the APIs return expected response when its accessed via Postman. But when accessing from code, the Get Content API intermittently stops working and returns below exception. (During the same time when application is getting exception, if I try to get content through Postman it returns the data.)
com.microsoft.graph.core.ClientException: Error executing the request
As this exception message is very generic, we want to know the reason why it stops working suddenly and the causes for this exception.
Thanks, Mohanavalli A
Hi @Mohanavalli-A, thanks for reaching out.
Could you please share what version of the SDK you're using and sample code you're using to make the two requests?
(Just the graphClient.... lines)
Hi,
The microsoft graph sdk version is 5.75.0.
Below is the sample code for downloading file content.
public byte[] downloadFile(DriveItem driveItem) throws ClientException, Exception {
String getItemUrl = String.format("/drives/%s/items/%s/content",
sharepointProperties.getDriveId(), driveItem.id);
try (InputStream is =
graphClient().customRequest(getItemUrl, InputStream.class).buildRequest().get()) {
return Objects.isNull(is) ? new byte[0] : is.readAllBytes();
}
Hi @Mohanavalli-A Unfortunately, we're only providing active support for version 6.x of this SDK and security fixes only for 5.x. I would recommend upgrading if you can. Here's an upgrade guide