My requirement is to get details about OneDrive activity by user using Microsoft Graph SDK.
I set the Graph permission “Reports.Read.All” as per the documentation. Being said that in case if you’re using delegated permissions then it needs to allow apps to read service usage reports on behalf of a user, the tenant administrator must have assigned the user the appropriate Azure AD limited administrator role. More info is given at the documentation.
Here’s the code sample that i used:
// create a get request for the period D7
var request = graphServiceClient.Reports
.GetOneDriveActivityUserDetail("D7")
.Request()
.GetHttpRequestMessage();
// send the request to get the response
var response = await graphServiceClient.HttpProvider.SendAsync(request);
string csvReport = "";
if (response.IsSuccessStatusCode)
{
// read the report
csvReport = await response.Content.ReadAsStringAsync();
}
else
{
// read the error status code and error message
var code = response.StatusCode.ToString();
var message = await response.Content.ReadAsStringAsync();
}
If the above API call is successful, then you will see this method returns HTTP 302 Found
response that redirects to a preauthenticated download URL for the report. That URL can be found in the Location
header in the response.
Alternately you can test the same with Microsoft Graph explorer or POSTMAN as well using the following API call:
GET https://graph.microsoft.com/v1.0/reports/getOneDriveActivityUserDetail(period='D7')
Hope this helps.