403 Forbidden Response using AAD App and SharePoint Graph API

%3CLINGO-SUB%20id%3D%22lingo-sub-2796383%22%20slang%3D%22en-US%22%3E403%20Forbidden%20Response%20using%20AAD%20App%20and%20SharePoint%20Graph%20API%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2796383%22%20slang%3D%22en-US%22%3E%3CP%3EAs%20the%20subject%20says%2C%20I%20am%20trying%20to%20upload%20a%20file%20to%20SharePoint%20Online%20Documnet%20library.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20created%20AAD%20App%20and%20given%20Site.FullControl.All%20on%20my%20test%20lab%20tenant.%20I%20am%20able%20to%20generate%20oAuth%20Token%20but%20whenever%20I%20try%20to%20trigger%20the%20Invoke-RESTMethod%20it%20throws%20403%20error.%3C%2FP%3E%3CP%3E%24Uri%20%3D%26nbsp%3B%23%24Uri%20%3D%20%22%3CA%20href%3D%22https%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2Fdrives%2F%24driveId%2Fitems%2Froot%3A%2Ftest45.docx%3A%2Fcontent%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2Fdrives%2F%24driveId%2Fitems%2Froot%3A%2Ftest45.docx%3A%2Fcontent%3C%2FA%3E%22%3C%2FP%3E%3CP%3EInvoke-RestMethod%20-Uri%20%24Uri%20-Headers%20%24headers%20-Method%20Put%20-Body%20%24path.OpenRead()%20-ContentType%20%22application%2Fdocx%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20tested%20the%20end%20point%20using%20the%20token%20available%20in%20Graph%20Explorer%20and%20it%20works%20fine.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20help.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3CP%3EAniruddha%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2796383%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional Contributor

As the subject says, I am trying to upload a file to SharePoint Online Documnet library. 

 

I created AAD App and given Site.FullControl.All on my test lab tenant. I am able to generate oAuth Token but whenever I try to trigger the Invoke-RESTMethod it throws 403 error.

$Uri = #$Uri = "https://graph.microsoft.com/v1.0/drives/$driveId/items/root:/test45.docx:/content"

Invoke-RestMethod -Uri $Uri -Headers $headers -Method Put -Body $path.OpenRead() -ContentType "application/docx"

 

I tested the end point using the token available in Graph Explorer and it works fine. 

 

Any help.

 

Thanks

Aniruddha

 

 

 

 

1 Reply
Invoke-RestMethod : The remote server returned an error: (403) Forbidden.