Sharing of group folder via API and basic auth leads to 404 error

Support intro

Sorry to hear you’re facing problems :slightly_frowning_face:

help.nextcloud.com is for home/non-enterprise users. If you’re running a business, paid support can be accessed via portal.nextcloud.com where we can ensure your business keeps running smoothly.

In order to help you as quickly as possible, before clicking Create Topic please provide as much of the below as you can. Feel free to use a pastebin service for logs, otherwise either indent short log examples with four spaces:

example

Or for longer, use three backticks above and below the code snippet:

longer
example
here

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can :heart:

Nextcloud version (eg, 12.0.2): 17.0.2
Operating system and version (eg, Ubuntu 17.04): Docker image
Apache or nginx version (eg, Apache 2.4.25): it’s in the docker container
PHP version (eg, 7.1): it’s in the docker container

The issue you are facing:

When I try to add a share link to a group folder via the API with basic auth, the request fails with error 404. A GET request works as well as sharing other normal folders of the user via the API. If I send a cookie of a browser session instead of the basic auth string along with the request, the stuff works.
Documentation: https://docs.nextcloud.com/server/17/developer_manual/client_apis/OCS/ocs-share-api.html

Is this the first time you’ve seen this error? (Y/N): Y
(when you mean compared to other versions; but had not tested it there)

Steps to replicate it:

Get the current shares:

curl -X GET -i -u "admin:mycoolpassword" https://mydomain.de/ocs/v2.php/apps/files_sharing/api/v1/shares -H "OCS-APIREQUEST:true"

-> Works like a charm and gives me a 200 OK with the currently active shares.

Add a share link for a group folder with basic auth:

curl -X POST -i -u "admin:mycoolpassword" https://mydomain.de/ocs/v2.php/apps/files_sharing/api/v1/shares -H "OCS-APIREQUEST:true" -d "shareType=3" -d "path=/testgroupfolder" -d "permissions=1"

–>

<?xml version="1.0"?>
<ocs>
 <meta>
  <status>failure</status>
  <statuscode>404</statuscode>
  <message>Can’t increase permissions of /admin/files/testgroupfolder</message>
 </meta>
 <data/>
</ocs>

Add a share link for a group folder with cookie:

curl -X POST -i https://mydomain.de/ocs/v2.php/apps/files_sharing/api/v1/shares -H "OCS-APIREQUEST:true" -H "Cookie: oc2ft4imfqls=3d068f3185055de71408a709cxxxxxxx; oc_sessionPassphrase=reDMqoWPswjr7uYPYOlyv2VILO05JRafzrFqTXJ%2BlOqFbZ4H%2BjBpllD9hTRfKR6KNSN4wEq%2FifxUV0wWAGG%2BqzwA5aqytJJ%2BYlsGwkwhjvg5o3oQO09PKbXXXXXXXXXX; nc_sameSiteCookielax=true; nc_sameSiteCookiestrict=true; nc_username=admin; nc_token=t4NqmrAoOHlQz%2BsrbKLtEsXXXXXXXXXX; nc_session_id=3d068f3185055de71408a7xxxxxxxxxx; __Host-nc_sameSiteCookielax=true; __Host-nc_sameSiteCookiestrict=true" -d "shareType=3" -d "path=/testgroupfolder" -d "permissions=1"

–>

<?xml version="1.0"?>
<ocs>
 <meta>
  <status>ok</status>
  <statuscode>200</statuscode>
  <message>OK</message>
 </meta>
 <data>
  <id>3</id>
  <share_type>3</share_type>
  <uid_owner>admin</uid_owner>
  <displayname_owner>admin</displayname_owner>
  <permissions>1</permissions>
  <stime>1577983705</stime>
  <parent/>
  <expiration/>
  <token>jop4zy2iqmxxxxx</token>
  <uid_file_owner>admin</uid_file_owner>
  <note></note>
  <label></label>
  <displayname_file_owner>admin</displayname_file_owner>
  <path>/testgroupfolder</path>
  <item_type>folder</item_type>
  <mimetype>httpd/unix-directory</mimetype>
  <storage_id>local::/var/www/html/data/</storage_id>
  <storage>1</storage>
  <item_source>312</item_source>
  <file_source>312</file_source>
  <file_parent>6</file_parent>
  <file_target>/testgroupfolder</file_target>
  <share_with/>
  <share_with_displayname/>
  <password/>
  <send_password_by_talk></send_password_by_talk>
  <url>https://mydomain.de/s/jop4zy2iqmxxxxx</url>
  <mail_send>1</mail_send>
  <hide_download>0</hide_download>
 </data>
</ocs>

The output of your Nextcloud log in Admin > Logging:

nothing related

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'htaccess.RewriteBase' => '/',
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'apps_paths' => 
  array (
    0 => 
    array (
      'path' => '/var/www/html/apps',
      'url' => '/apps',
      'writable' => false,
    ),
    1 => 
    array (
      'path' => '/var/www/html/custom_apps',
      'url' => '/custom_apps',
      'writable' => true,
    ),
  ),
  'instanceid' => 'myid',
  'passwordsalt' => 'supersalt',
  'secret' => 'supersecret',
  'trusted_domains' => 
  array (
    0 => '10.0.1.22',
    1 => 'mydomain.de',
  ),
  'trusted_proxies' => 
  array (
    0 => '10.0.1.22',
  ),
  'datadirectory' => '/var/www/html/data',
  'dbtype' => 'mysql',
  'version' => '17.0.2.1',
  'overwrite.cli.url' => 'http://10.0.1.22',
  'overwriteprotocol' => 'https',
  'dbname' => 'nextcloud',
  'dbhost' => '10.0.1.10',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => 'cooldbpass',
  'installed' => true,
  'mail_from_address' => 'noreply',
  'mail_smtpmode' => 'smtp',
  'mail_sendmailmode' => 'smtp',
  'mail_domain' => 'myinternal.intranet',
  'mail_smtphost' => '10.0.1.13',
  'mail_smtpport' => '25',
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
  'skeletondirectory' => '',
);

-> But also tested on another instance with the same version.

The output of your Apache/nginx/system log in /var/log/____:
Nothing in the error logs. Access log:

"POST /ocs/v2.php/apps/files_sharing/api/v1/shares HTTP/1.0" 404 1553 "-" "curl/7.58.0"