next cloud ocs create share api permission issue - php

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);

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);

Related

CURLOPT_URL how to get two different links?

The below code works with API URL: https://api2.example.com/service/vps/list
but the API provider has changed, they use 2 URLs at the same time, for example: https://api2.example.com/service/vps/list and https://api2.example.com/service/dedicated/list
how to get vps and dedicated information from the above two links?
this is my code working with https://api2.example.com/service/vps/list only:
if (!defined("WHMCS"))
die("This file cannot be accessed directly");
use Illuminate\Database\Capsule\Manager as Capsule;
class FKL
{
public $apikey = '';
public $apiurl = 'https://api2.example.com/';
public function __construct($apikey = '')
{
$this->apikey = $apikey;
}
public function getList()
{
$sendparams = [];
$sendparams['APIKey'] = $this->apikey;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->apiurl . "service/vps/list");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($sendparams, JSON_PRETTY_PRINT));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Content-Type: application/json')
);
$result = curl_exec($ch);
curl_close($ch);
if ($result) {
$list = json_decode($result, true);
return $list['data'];
}
}
public function getOSList()
{
$sendparams = [];
$sendparams['APIKey'] = $this->apikey;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->apiurl . "service/vps/os");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($sendparams, JSON_PRETTY_PRINT));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Content-Type: application/json')
);
$result = curl_exec($ch);
curl_close($ch);
if ($result) {
$list = json_decode($result, true);
return $list['data'];
}
}
......
Thank you!
I have added code:
curl_setopt($ch, CURLOPT_URL, $this->apiurl . "service/dedicated/list");
bellow:
curl_setopt($ch, CURLOPT_URL, $this->apiurl . "service/vps/list");
and now are working!

How to set method of CURL to PUT?

I am trying to set the http method of Curl to PUT but my code is not working
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:
application/json','Content-Length: ' . strlen($post)));
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
The above code is what I have written but it is not setting it to PUT method
Please help
Try changing
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
to
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');

How to do a PUT request with curl and Authorization?

This is what I am trying
$url = "https://aon-test.yui.com/api/".$this->_token."/".$action;
$headers = array(
'Content-Type:application/xml' ,
'Authorization: Basic '. base64_encode("s!YIYIYIYIUYIY:X")
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_TIMEOUT, 30000);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($xml));
$content = curl_exec($ch);
curl_close($ch);
I am getting 500 - Internal server error.
What mistake I am doing here?

Curl Post with multi params

I need to do Post curl in php for this command :
curl -k -X POST https://openshift.redhat.com/broker/rest/domains/did/applications/test/events
--user "[UserName]:[Password]" --data "event=restart""
that what i try but it's not working :
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://openshift.redhat.com/broker/rest/domains/did/applications/test/events");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "--user "[UserName]:[Password]" --data "event=restart" ");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
I should get the -K and the -X also, so any ideas how to do this ?
See curl_setopt for available options.
<?php
$username = 'username';
$password = 'password';
$url = 'https://example.com/';
$cookie = 'cookie.txt';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'event=restart');
curl_setopt($ch, CURLOPT_POST, true);
$response = curl_exec($ch);
curl_close($ch);
?>

login to any site using curl in php

login to a website using curl php
I have tried
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.sitename.com");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($ch, CURLOPT_POSTFIELDS, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
curl_setopt($ch, CURLOPT_USERPWD, "username:password");
curl_exec($ch);
curl_close($ch);
But this does not log in .
curl_setopt($ch, CURLOPT_POSTFIELDS, true); does not make sense.
You may have CURLOPT_POSTFIELDS and CURLOPT_POST mixed up. The correct way is:
curl_setopt($ch, CURLOPT_POST, true);
Check the manual here: http://no.php.net/manual/en/function.curl-setopt.php
Correct Code should be :
NOTE : change the values for userName an password as required by the login form
for the site.
$postField = "userName = abc&password=xyz";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.sitename.com");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
curl_setopt($ch, CURLOPT_USERPWD, "username:password");
curl_exec($ch);
curl_close($ch);`

Categories