How to create a folder by using API?


#1

Hi.

I have created a little php application which upload a file by using curl to make a webdav call using PUT method. That's working great.
However, I can't manage to use API to create a folder (the idea is to create a folder from php and then upload the file on this new folder).
I have read that I should use OCP instead of OCS or webdav. Also I think I have found the documentation of the function that I have to all: https://doc.owncloud.org/api/classes/OCP.Files.Folder.html#method_newFolder but I haven't found any example on how can I make this call from php.

Could anyone show me an example?

Thank you.


Create Folder via API?
#2

You just need to do a WebDAV call doing a MKCOL, similar how you do the PUT.


#3

Thank you for your answer. I tried but it doesn't seem to work.

I have done this by linux command-line:

curl -X MKCOL "https://myserver/remote.php/webdav/existing_folder/new_folder" -k -u my_user:mypassword

After this call I'm getting this answer:


301 Moved Permanently

Moved Permanently


The document has moved here.




Apache/2.4.10 (Debian) Server at myserver Port 80

But when I login on owncloud with my credentials (myuser / mypassword, according to the example) I can't see the folder.

What I'm doing wrong?


#4

This is really strange, but moving the -X MKCOL option to the end seems to make it work.

So, it's working now. Thank you!!


#5

I am trying to create a folder using owncloud API in java. I get "pkix path building failed sun.security.provider.certpath.suncertpathbuilderexception" because I guess org.apache.commons httpClient cannot trust this server. I tried to solve this by registering self signed certificate to CloseableHttpClient. But I guess CloseableHttpClient does not support jackrabbit MKCOL. Any suggestions on how I can solve this?