I’m currently working on with Graph SDK v5 (.NET).
I’m trying to get all the drive ID using the sites list.
I other reference show the way to call API for each time using each requestID, but I want to get all the batch response at a onetime. Bellow is a code I’m working, having error with GetResponseAsync()
private List<(string SiteId, string DriveId)> GetSharepointDriveIds(GraphServiceClient gsc, List<Site> siteList)
{
var siteDriveIds = new List<(string SiteId, string DriveId)>();
int batchSize = 20;
for (int i = 0; i < siteList.Count; i += batchSize)
{
var batchRequestContent = new BatchRequestContentCollection(gsc);
var batchSites = siteList.Skip(i).Take(batchSize).ToList();
foreach (var site in batchSites)
{
var requestInformation = gsc.Sites[site.Id].Drives.ToGetRequestInformation();
var requestId = batchRequestContent.AddBatchRequestStepAsync(requestInformation).GetAwaiter().GetResult();
}
// I'm having error here
var batchResponseContent = gsc.Batch.PostAsync(batchRequestContent).GetAwaiter().GetResult();
var responses = batchResponseContent.GetResponsesAsync().GetAwaiter().GetResult();
}
return siteDriveIds;
}
please suggest!!