SOLVED

On-premise sharepoint API upload pdf error

New Contributor

Hello, I'm trying to upload a PDF on the on-premise sharepoint 2016 through the API with Postman. Here is my setup.

 

URL: https://test.com/_api/Web/GetFolderByServerRelativeUrl('/somefolder/Shared%20Documents')/Files/Add(u...', overwrite=true)

Authentication: NTLM domain username and password.

Headers: 

ptremblay1515_0-1654533844459.png

Body:

ptremblay1515_1-1654533963297.png

Error:

ptremblay1515_2-1654534052411.png

Here's a couple of question

1. Can I use NTLM to upload a file or do I have to setup sharepoint to use bearer token authentication?

2.  Why I'm I getting this error? Is it because it can't find the folder? I was able to make a GET API call to that folder to get the detailed information and it worked.

 

I used to get "Access Denied" but we fixed that issue by giving the user the correct permissions.

 

I would appreciate any help!

Patrick

 

 

 

1 Reply
best response confirmed by ptremblay1515 (New Contributor)
Solution

I was able to fix this issue by supplying the site name in the url and not in the GetFolderByServerRelativeUrl.

So instead of 

https://test.com/_api/Web/GetFolderByServerRelativeUrl('/sitename/Shared%20Documents')/Files/Add(url...', overwrite=true)

use

https://test.com/sitename/_api/Web/GetFolderByServerRelativeUrl('/Shared%20Documents')/Files/Add(url...', overwrite=true)