Hi,
I am using the Microsoft Graph API to fetch the OneDrive SharedWithMe items. I'm using Client Secret Flow for authentication. Below is the relevant part of my code. However, when I execute the SharedWithMe API, I receive a 500 generalException error. All other API's are working fine. And below code was also working till last week. Suddenly something happened and I start receiving the 500 General Exception. Could anyone help me understand what is the issue or do I missing something?
Code for Get Shared With Me Items:
public async Task<List<Tuple<string, SharedWithMeResponse?>>> GetSharedDriveItemsAsync(GraphServiceClient microsoftGraphClientContext, List<string?> driveIds)
{
try
{
List<Tuple<string, SharedWithMeResponse?>> driveItemCollection = new List<Tuple<string, SharedWithMeResponse?>>();
var batchRequestContent = new BatchRequestContent(microsoftGraphClientContext);
List<string> requestIds = new List<string>();
foreach (var driveId in driveIds)
{
var request = microsoftGraphClientContext
.Drives[driveId]
.SharedWithMe;
var driveItemsRequestInformation = new RequestInformation
{
HttpMethod = Method.GET,
UrlTemplate = request.ToGetRequestInformation().URI.ToString()
};
driveItemsRequestInformation.AddRequestOptions(new List<IRequestOption> { retryHandlerOption });
var driveItemsPageRequestMessage = await microsoftGraphClientContext.RequestAdapter.ConvertToNativeRequestAsync<HttpRequestMessage>(driveItemsRequestInformation);
//HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, driveItemsRequestInformation.URI.ToString());
BatchRequestStep batchRequestStep = new BatchRequestStep(driveId, driveItemsPageRequestMessage);
batchRequestContent.AddBatchRequestStep(batchRequestStep);
}
var returnedResponse = await microsoftGraphClientContext.Batch.PostAsync(batchRequestContent);
if (returnedResponse != null)
{
foreach (var driveId in driveIds)
{
SharedWithMeResponse? sharedDriveItemCollectionResponse = await returnedResponse
.GetResponseByIdAsync<SharedWithMeResponse>(driveId);
if (sharedDriveItemCollectionResponse != null)
{
driveItemCollection.Add(new Tuple<string, SharedWithMeResponse?>(driveId, sharedDriveItemCollectionResponse));
}
}
}
return driveItemCollection;
}
catch (Exception exception)
{
throw;
}
}
Code for Microsoft Graph Service Client:
public class ServiceClient
{
public GraphServiceClient microsoftGraphServiceClient;
public ServiceClient(string clientId, string clientSecret, string tenantId)
{
var scopes = new string[] { "https://graph.microsoft.com/.default" };
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
var clientSecretCredential = new ClientSecretCredential(tenantId, clientId, clientSecret, options);
microsoftGraphServiceClient = new GraphServiceClient(clientSecretCredential, scopes);
}
}
Error:
"CorrelationId": "XXX",
"IsSuccessful": false,
"StatusCode": 500,
"Messages": [
"Exception occured API processing for CorrelationId = XXX",
"generalException"
],
"Data": " at Microsoft.Graph.ResponseHandler`1.ValidateSuccessfulResponse(HttpResponseMessage httpResponseMessage, Dictionary`2 errorMapping)\r\n at Microsoft.Graph.ResponseHandler`1.HandleResponseAsync[NativeResponseType,ModelType](NativeResponseType response, Dictionary`2 errorMappings)\r\n at Microsoft.Graph.BatchResponseContent.GetResponseByIdAsync[T](String requestId, IResponseHandler responseHandler)