next cloud ocs create share api permission issue

594 views Asked by At

while creating share link with the help of ocs share api i am able to create the link but it is not setting the permission that i am trying to give it.

        $ch = curl_init("https://servername/ocs/v2.php/apps/files_sharing/api/v1/shares");
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data', "OCS-APIRequest:true"));
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_USERPWD, getenv('NEXTCLOUDUSERNAME') . ":" . getenv('NEXTCLOUDPASSWORD'));
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        $return = curl_exec($ch);
1

There are 1 answers

0
Somchai P. On
function curlPost($url, $headers, $username, $password, $data) {
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($ch, CURLINFO_HEADER_OUT, true);
     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
     curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
     curl_setopt($ch, CURLOPT_TIMEOUT, 30);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
     return curl_exec($ch);
     curl_close($ch);
}

$url = 'https://SERVERNAME/ocs/v2.php/apps/files_sharing/api/v1/shares';
$headers = Array('OCS-APIRequest: true');
$username = 'NEXTCLOUDUSERNAME';
$password = 'NEXTCLOUDPASSWORD';
$data = 'path=PATH/FILE.xxx&shareType=3&permissions=1&format=json';
echo curlPost($url, $headers, $username, $password, $data);