Can you programmatically create a share in an OCC command?

I’m trying to create an OCC command for the Deck app that will attach a file to a task. Currently, the app does this in the frontend by making a POST request to /ocs/v2.php/apps/files_sharing/api/v1/shares. I would like to have that same functionality in an OCC command.

I have not been able to find an easy way of creating a share object in the backend without making that API call. The code for that API route is in apps/files_sharing/lib/Controller/ShareAPIController.php, in the createShare function, and it’s very long. It’s not something that we should be recreating everywhere we need it.

I thought about making a call to that API endpoint from the OCC command. Although it feels weird to make an API call from the backend to localhost, it would at least remove the duplication of work. However, I’m making an OCC command, so there is no logged-in user or API token available.

Is there already a way of making API calls to the server from an OCC command? I couldn’t find one.

To answer your question literally: no there is no occ command to make API calls to the rest interface as you already found out.

However, one could easily wrap any controller method into a command in the backend without network interaction. This should be done on the corresponding app, I guess to prevent collision and tight coupling of apps.

Thanks! I’ll look into moving that controller method to another file so it can be reused elsewhere.

Be careful that you do not build too tight of a coupling in your app. Also, make sure that your code is compatible with an update of the other app/server.