Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get SharePoint online site usage report using pnp/sp? #2684

Closed
bhoomesh-spe opened this issue May 18, 2023 · 5 comments
Closed

How to get SharePoint online site usage report using pnp/sp? #2684

bhoomesh-spe opened this issue May 18, 2023 · 5 comments

Comments

@bhoomesh-spe
Copy link

bhoomesh-spe commented May 18, 2023

I have created SharePoint Framework Solution for custom development in the SharePoint Online.

I need to display SharePoint site usage report in my SPFx web part.

I have tried with @pnp/graph and @pnp/sp but I can not find any solution.

Can anyone help me with the same?

Thanks

@bhoomesh-spe bhoomesh-spe changed the title How to get SharePoint online site usage report using sp/pnp? How to get SharePoint online site usage report using pnp/sp? May 18, 2023
@bcameron1231
Copy link
Collaborator

You can extend some of the internal methods we have in the library to make your own calls against Graph.

For Example

import { GraphQueryable, graphGet, SPFxToken,SPFx } from '@pnp/graph';

const reports = await graphGet(GraphQueryable("https://graph.microsoft.com/v1.0/reports/getSharePointSiteUsageDetail(period='D7')").using(SPFx(this.context),SPFxToken(this.context)));

You can pass any URL into a GraphQuery object to create a new instance at the endpoint of your choosing.

Just be aware there are lots of nuances with this endpoint in regard to permissions. Make sure you follow through that, as we are just a pass through to the Graph APIs, authentication issues will likely be caused by misconfigurations.

https://learn.microsoft.com/en-us/graph/reportroot-authorization

@bhoomesh-spe
Copy link
Author

bhoomesh-spe commented May 23, 2023

HI @bcameron1231

Thanks for the quick response.

Please refer to the below screenshot of package.json file.

MicrosoftTeams-image (8)

Please refer to the below screenshots of main pnpconfig.ts file .

MicrosoftTeams-image (11)

Please refer to the below screenshots of main webpart.ts file .

MicrosoftTeams-image (9)

MicrosoftTeams-image (10)

I have tried as you have suggested. Below is my code snippet,

import { SPFI } from "@pnp/sp";
import { getSP, getGraph } from "./pnpConfig";
import { GraphFI, graphfi, GraphQueryable, graphGet, SPFxToken, SPFx } from "@pnp/graph";
import "@pnp/graph/insights";
import "@pnp/graph/users";
import "@pnp/graph/groups";
import "@pnp/graph/calendars";
import { context } from "../webparts/zebra/components/Zebra";
import "@pnp/graph/sites";

 

export const currentDashboard = async () => {

    const graph: GraphFI = getGraph();
    const reportData = await graphGet(GraphQueryable("https://graph.microsoft.com/v1.0/reports/getSharePointSiteUsageDetail(period='D7')").using(SPFx(context),SPFxToken(context)));
    console.log("reportData...", reportData);

    return reportData;
}

I have faced some error. Please check below screenshots for the same.

MicrosoftTeams-image (3)

MicrosoftTeams-image (5)

MicrosoftTeams-image (6)

Also, I have posted the issue in the Microsoft Graph Support.

Thanks

@bcameron1231
Copy link
Collaborator

Thanks. It looks like this may be a known issue.

It looks like the token may not include the wids claim because of length concerns. Which actually means it can't resolve the Azure AD Role for the user (which is required for this endpoint).

https://learn.microsoft.com/en-us/sharepoint/dev/spfx/use-msgraph#azure-ad-roles-with-delegated-authentication

You may be able to add this Wids claim manually, but i'm not 100% sure.
https://learn.microsoft.com/en-us/security/zero-trust/develop/configure-tokens-group-claims-app-roles

Unfortunately, this means we likely aren't able to help you and that you'll have to raise this up with Microsoft directly.

@bcameron1231
Copy link
Collaborator

Closing this issue as answered, and unfortunately not something we can solve within the library. If you have additional questions or we did not answer your question, please open a new issue, ref this issue, and provide any additional details available. Thank you!

@github-actions
Copy link

This issue is locked for inactivity or age. If you have a related issue please open a new issue and reference this one. Closed issues are not tracked.

@github-actions github-actions bot locked and limited conversation to collaborators May 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants