403(Forbidden) Invalid permission error in my SPFx web part when trying to access SharePointSiteUsageDetail with MSGraph

Hiren Changela 15 Reputation points

I can GET data in Graph Explorer, but when I try in my SPFx solution it gives me an 403(Forbidden) error:


In the package-solution.json file,I set these permissions:

"webApiPermissionRequests": [                                
      {"resource": "Microsoft Graph","scope":"User.ReadBasic.All"},
      {"resource": "Microsoft Graph","scope": "sites.Read.All"},
      {"resource": "Microsoft Graph","scope": "Reports.Read.All"}]

I have this to init the graph API connection:

 public GetUsageData = (): void => {
      .then((msGraphClient: MSGraphClient) => {
        const period = 7;
            "reports/getSharePointSiteUsagePages(period='D" +
              period +
          .get((err, report: any, res: any) => {
            if (err) {
              console.log("Error occured from usage", err);
            console.log("Error occured usage data", err);
            console.log("Response usage data", res);
            res.value.map((result) => {
                storageUsedInBytes: result.storageUsedInBytes,
                storageAllocatedInBytes: result.storageAllocatedInBytes,
            this.setState({ usageDataState: this.allUsage });

I have set the required Report.Read.All permission to "SharePoint Online Client Extensibility Web Application Principal"

User's image

API access:

User's image


User's image

User's image

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,415 questions
0 comments No comments
{count} votes