0

I am new to Sharepoint and REST APIs and am currently having an issue uploading a file using REST API. I am getting error System.UnauthorizedAccessException","message":{"lang":"en-US","value":"Access denied."}}}|403 when uploading a file.

I am using OAuth and have the tenant ID, client id, and client secret. I have no issue getting the client credentials. But when calling: https://[tenant].sharepoint.com/sites/[site]/_api/web/GetFolderByServerRelativeUrl('[folder dir]')/Files/add(url='test_file.txt',overwrite=true) then I get the 403 error as response.

Here are my HTTP Headers:

"Authorization": "Bearer" + access token
"Accept": "application/json;odata=verbose"
"Content-Length": *length of file*

Is this an add-in permission issue or am I missing a header? Thanks in advance for your help.

ecc07
  • 1
  • 1
  • How are you submitting the request to SharePoint? For example, are you using jQuery or the Fetch API in JavaScript or are you using the SPHttpClient in SharePoint Framework? – Rob Windsor Dec 12 '22 at 11:20

1 Answers1

0

You need a Form Digest - an X-RequestDigest header - to POST to SharePoint APIs.

How to get 'form digest value' to use in REST call?

Derek Gusoff
  • 8,011
  • 1
  • 17
  • 15