394
Views
21
Comments
Solved
Has anyone successfully created a REST API to create a folder on SharePoint?
Question

I have been successfully using REST APIs to interact with SharePoint, however I am unable to get the Create Folder functionality working.

Does anyone know what the Method URL should be please?

This what I have so far...


UserImage.jpg
Sienna
Solution

Actually, cancel that - I fixed it!

The problem was that there was some residual code that had been auto generated in the Body Content when playing around and that was affecting it.

UserImage.jpg
Sienna
Solution

Stumbled on this again, and thought I'd just clarify regarding the solution - Outsystems populates the Body Content with some auto generated text. Once populated it appears that the text remains the same even after amending your code. Anyway the solution was as simple as deleting the auto generated text (which had been generated before I'd got my code finalised) and then running it again.

UserImage.jpg
Sienna
Solution

Hi Luiz, the following should work (obviously removing all the curly brackets and entering your own data):

{BaseURL}/sites/{SiteName}/_api/web/GetFolderByServerRelativeUrl('Shared%20Documents/{Filepath}')/folders/add('{NewFolder}')

Hope you get it working soon!

UserImage.jpg
Louis Cuypers

I'm getting this exception when posting to that endpoint: 

Any clues why? My token includes scope "https://graph.microsoft.com/.default" and I'm able to post files to sharepoint with it. 

UserImage.jpg
Sienna

I already saw that thanks but it doesn't help.  The method URL "http://site url/_api/web/folders" doesn't work.

UserImage.jpg
Prasad Rao

Hi,

I no longer in that project but I can try to recreate it after sometime when I become little free. Can you post what exactly is the error you are getting when you use folders method?

Regards.

UserImage.jpg
Prasad Rao

Hi,

In this forge component there is an action to create folder https://www.outsystems.com/forge/component-overview/4114/sharepoint-connector, it has URL like /_api/web/folders/add('Shared Documents/FolderA'). Try this and let me know.

Regards,

Prasad Rao


UserImage.jpg
Sienna

Thank you, I tried the following 3 method URLs and I've copied the relevant error message under each....


/_api/web/GetFolderByServerRelativeUrl('Shared Documents')/add('Shared Documents/FolderA')
Cannot find resource for the request add

/_api/web/GetFolderByServerRelativeUrl('Shared Documents')/folders/add('Shared Documents/FolderA')
Cannot handle the data at position 0

/_api/web/folders/add('Shared Documents/FolderA')
Cannot handle the data at position 0

UserImage.jpg
Sienna

...interestingly, the one other REST call I had trouble with was creating a file. In the end I did it in the C# extension I was writing instead.  But both of the (most) troublesome ones I've had involve creating a file/folder.

UserImage.jpg
Prasad Rao

Hi,

I was able to create a folder using below in our internal sharepoint site.

/_api/web/GetFolderByServerRelativeUrl('Shared%20Documents')/Folders/add('newfolder')

Regards.

UserImage.jpg
Sienna

Ah that's interesting.  I still get the error 'Cannot handle the data at position 0' when I try that.....hmmm.....

UserImage.jpg
Sienna

...I'm using SharePoint online.

UserImage.jpg
Prasad Rao

Hi,

I also tried in sharepoint online. Did you try going to https://<domain>.sharepoint.com/sites/<SiteName>/Shared%20Documents, did it open in browser?

Regards.

UserImage.jpg
Sienna

Yes, that URL opens on my SharePoint site.

UserImage.jpg
Sienna

FYI, when using Chris' code....(which seems odd as no permissions issues with other RESTs)....

UserImage.jpg
Prasad Rao

Hi,

Its really strange that you are getting the error 'Cannot handle the data at position 0',this means it cannot find the resource.

In the above screenshot you are missing the some part of URL after the domain like /sites/<sitename>/

Regards.

UserImage.jpg
Sienna

Sorry yes, I made so many changes I omitted it from there when writing that to take a screenshot, but I did include the site details when testing.

I have tried the following and they all generate the same error:  'Cannot handle the data at position 0'.

  1. .../sites/{SiteName}/_api/web/folders/add('Shared Documents/{FolderName}')
  2. .../sites/{SiteName}/_api/web/GetFolderByServerRelativeUrl('Shared Documents')/folders/add('{FolderName}')
  3. .../sites/{SiteName}/_api/web/GetFolderByServerRelativeUrl('Shared%20Documents/{FilePath}')/folders/add('{NewFolder}')
  4. .../sites/{SiteName}/_api/web/GetFolderByServerRelativeUrl('{FilePath}')/folders/add('{NewFolder}')

Note that the first one works for another internal SharePoint site but doesn't on the one I need it to.

UserImage.jpg
Sienna

I think I'll start another post with that error message as the title in case anyone can offer further advice.

Thanks so much for your time and help and help though Prasad, really appreciate it!!

UserImage.jpg
Sienna
Solution

Actually, cancel that - I fixed it!

The problem was that there was some residual code that had been auto generated in the Body Content when playing around and that was affecting it.

UserImage.jpg
Sienna
Solution

Stumbled on this again, and thought I'd just clarify regarding the solution - Outsystems populates the Body Content with some auto generated text. Once populated it appears that the text remains the same even after amending your code. Anyway the solution was as simple as deleting the auto generated text (which had been generated before I'd got my code finalised) and then running it again.

UserImage.jpg
Luiz Furlan

Hello, Sienna!

Which one of these did you use to solve your problem:


.../sites/{SiteName}/_api/web/folders/add('Shared Documents/{FolderName}')

.../sites/{SiteName}/_api/web/GetFolderByServerRelativeUrl('Shared Documents')/folders/add('{FolderName}')

.../sites/{SiteName}/_api/web/GetFolderByServerRelativeUrl('Shared%20Documents/{FilePath}')/folders/add('{NewFolder}')

.../sites/{SiteName}/_api/web/GetFolderByServerRelativeUrl('{FilePath}')/folders/add('{NewFolder}')


I'm trying to create a new folder on my Sharepoint site, but I can't find a way. I'm only beeing able to upload a file on the Shared Folder...

UserImage.jpg
Sienna
Solution

Hi Luiz, the following should work (obviously removing all the curly brackets and entering your own data):

{BaseURL}/sites/{SiteName}/_api/web/GetFolderByServerRelativeUrl('Shared%20Documents/{Filepath}')/folders/add('{NewFolder}')

Hope you get it working soon!

UserImage.jpg
Louis Cuypers

I'm getting this exception when posting to that endpoint: 

Any clues why? My token includes scope "https://graph.microsoft.com/.default" and I'm able to post files to sharepoint with it. 

UserImage.jpg
Sienna

Btw in case you're not aware and it's helpful, some parts of a REST call are case sensitive.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.