How to create and share folder in a custom app?

Hi there,

I am quite new to owncloud. And I am struggling a little bit with the develoment of cutom apps.
My Owncloud-version is 10.8.
What I want to do from inside my app is creating a folder owned by a specific user. After that I want to share this Folder with a specific Group.

I have searched for some hours now, but I can’t find much specifics on hot to accomplish this. It seems an easy task that an app should be able to do with oncloud mechanics.

Everything I find so far is using webdav, provisining and share apis but very few specifics on how to do this. I cannot find any example code on how to access webdav api from inside my app.

Is it really the way to go to setup curl and fire curl requests from inside my app to access webdav api? Furthermore how to creat folders with it?
Any links, any step by step guides or any other tips will be appreceated!

Best Regards,
FirestromHell

No one forces you to use curl to submit your requests. You can use whatever you want or what is available in your app environment. (jQuery, fetch…)

1 Like

Thanks for your answer.

I get where you coming from, but the question for me is more like, is there no owncloud internal way to create (and share) a folder? Do I have to do this via webdav api?

I don’t know of an official statement or advice on that topic. If we are talking about an ownCloud app, I think it’s ok to create a folder directly with PHP. For the sharing you have to use the API anyway.

2 Likes

That’s what the ownCloud desktop client does. A little trick can be to look at the ownCloud client’s traffic using wireguard (or similar) while doing in the client what you want to achieve in your app.

Creating a user, a group and assign group membership would for example also be possible to do using occ commands. You can create a folder with the correct permissions on the filesystem if you have system level access. Finally you would have to do an occ files:scan and you would have the first 90% covered by a bash script. However for sharing you still need a curl request against the API.

I recently created a whole bunch of shares like so:

curl -s --user '<user>:<password>' -X POST -H "Content-Type: application/json" --data '{"shareType":0,"shareWith":"test","permissions":31,"path":"/test/path"}' https://owncloud.fqdn.tld/ocs/v1.php/apps/files_sharing/api/v1/shares
1 Like

Thank you for the answer.
I am fairly new to owncloud so I guess I will try to do this in php with curl from inside my app.
The ocs/v1.php/apps/files_sharing/api/v1/shares part is clearly the api. So far so good, what about the base URL, how can I get the onwncloud base url? Of course i don’t want it to be hardcoded.
I am really puzzled how few exmaples are to be found how to actually use these owncloud internal apis from inside n app, like real code examples.
You would think there should be loads of apps using the apis, incl. installed standard apps. But I can’t seem to find any app that calls one of the apis via curl, e.g. provisioning api, files_sharing api, files api etc.

After some research and code browsing I am coming to my initial conclusion.
The Share API seems to be for calls from outside of owncloud.

The more suitable solution for me seems to be, to orient my code on the internals the share api is using.

Means getting a shareManager and use OC\Share20 Classes and Methos to create the share with all the parameters and configs you can do (e.g. setting who is sharing, setting permissions etc.).

Would you guys agree, that I am on the right path here?

Thanks for the answers anyway :+1:

Wouldnt do that. Internals might change any time, but the API is/should be constant/versioned.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.