3

I am using the Sharepoint Online REST API.

I can successfully make the following request:

GET /_api/web/GetFileByServerRelativeUrl('/Shared%20Documents/Hello.docx') HTTP/1.1
Host: SITE.sharepoint.com
Authorization: Bearer TOKEN
Accept: application/atom+xml
Cache-Control: no-cache

However, when I try to make the below request

POST /_api/web/GetFolderByServerRelativeUrl('/Shared Documents')/files/add(overwrite=true,url='test.txt') HTTP/1.1
Host: SITE.sharepoint.com
Authorization: Bearer TOKEN
Accept: application/atom+xml
Cache-Control: no-cache

"hello, world"

I get the response

<?xml version="1.0" encoding="utf-8"?>
<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
    <m:code>-2147024891, System.UnauthorizedAccessException</m:code>
    <m:message xml:lang="en-US">Access denied. You do not have permission to perform this action or access this resource.</m:message>
</m:error>

I am requesting the following scopes:

Web.FullControl Site.FullControl AllSites.FullControl List.FullControl

Am I missing a scope for this request, or is there some other permissions I need to set elsewhere?

2
  • Can you please post the code you're using?
    – Akhoy
    Commented Nov 26, 2015 at 10:55
  • @Akhoy Hey, there is no code, this is using Postman to send the requests.
    – dav_i
    Commented Nov 26, 2015 at 11:04

2 Answers 2

4

Figured it out!

According to Authentication Code OAuth flow for SharePoint Add-ins:

the FullControl right is not available ... because an add-in that request permission to access SharePoint resources on the fly can't request full control right

So setting the requested scope to be Web.Manage allowed me to upload the file as needed.

1

Are you including the the form digest? This is necessary when doing a POST.

To get the form digest in postman first do a POST request with this URL:

http://yoursite/_api/contextinfo

You'll get a long string back which you then need to add to the POST request you're trying to make as a Header in the X-RequestDigest parameter.

Full details here.

8
  • Or just go to a SP site and view source to get the request digest. :)
    – Akhoy
    Commented Nov 26, 2015 at 11:17
  • Yes there are a number of ways to grab the digest value. Since the OP is using Postman, I've described a way for OP to get the digest value from Postman itself.
    – Submits
    Commented Nov 26, 2015 at 11:20
  • Paste document.getElementById("__REQUESTDIGEST").value in the console of your SP site Commented Nov 26, 2015 at 11:21
  • @Submits I wasn't including that actually - useful information, thanks. Unfortunately though I have now done this and it still responds with the same error!
    – dav_i
    Commented Nov 26, 2015 at 11:37
  • Just try again. The digest value is temporary so you shouldn't wait too long between getting the value and then running your POST query. Failing that, are you sure you don't have read only permissions to the document library?
    – Submits
    Commented Nov 26, 2015 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.