Tag Archives: Microsoft Graph Explorer

GET Onedrive activity reports using microsoft graph sdk


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.

Investigate Microsoft Graph API call getOffice365ActiveUserDetail(period=’D7′) error HTTP 403 with Microsoft Graph explorer


One of my developer customer updated me that he tried calling reports from his custom application, using the Microsoft Graph API call “getOffice365ActiveUserDetail(period=’D7′)”, but receive HTTP 403. In order to isolate the issue, i tried repro the issue using Microsoft Graph Explorer and i can repro so. HTTP 403 – Forbidden!!
image

Being said that, Graph explorer updated me that i need to consent to the permissions on the “Modify Permissions” tab; in another words in order to run the reports i need the permissions. 
How cool is this new feature introduced in new MS Graph explorer?

Ok, I followed the steps in Graph explorer:

image

Just hover over the description. It provides a info clearly (see the below snapshot):

image

In order to make the permissions (admin consent required) to effect with my app (in this scenario, it will be MS Graph explorer), it thrown the dialog box to confirm:

image

On successful of the above, i made the same API call with Microsoft Graph explorer and it worked as i expected…!!

Happy Microsoft Graphing Winking smile