Site feedback

yasi-9251 avatar image
0 Votes"
yasi-9251 suggested

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

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

https://graph.microsoft.com/beta/reports/getSharePointSiteUsageDetail(period='D30')?$format=application/json

173575-error.png


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"}]


the code fetching data with MS Graph:

public GetUsageData = (): void => {
this.props.context.msGraphClientFactory
.getClient()
.then((msGraphClient: MSGraphClient) => {
const period = 7;
msGraphClient
.api(
"reports/getSharePointSiteUsagePages(period='D" +
period +
"')?$format=application/json"
)
.version("v1.0")
.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) => {
this.allUsage.push({
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":
173548-reportreadall.png


I approved the permissions in my sharePoint admin center:

173576-nwe.png


azure-active-directorymicrosoft-graph-permissionsoffice-sharepoint-online
error.png (11.2 KiB)
reportreadall.png (92.4 KiB)
nwe.png (17.7 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

No Solutions

Your Opinion Counts

Share your feedback, or help out by voting for other people's feedback.