0
votes

I want to make script to create new user in OwnCloud. I trying this:

$url = "http://admin:[email protected]/ocs/v1.php/cloud/users/";

$owncloud_postdata = array(
                'userid' => "testname",
            'password' => "testpassword,
    );
$owncloud_postdataurl = http_build_query($owncloud_postdata);
$init = curl_init();
curl_setopt( $init, CURLOPT_URL, $url );
curl_setopt( $init, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt( $init, CURLOPT_POST, TRUE );
curl_setopt( $init, CURLOPT_POSTFIELDS, $owncloud_postdataurl );
$owncloud_odpoved = curl_exec( $init );
curl_close($init);

I getting this:

<?xml version="1.0"?>
<ocs>
 <meta>
  <status>failure</status>
  <statuscode>999</statuscode>
  <message>Invalid query, please check the syntax. API specifications are here: http://www.freedesktop.org/wiki/Specifications/open-collaboration-services. DEBUG OUTPUT:
</message>
 </meta>
 <data/>
</ocs>

What is wrong with this? I use PHP 5.5, and I need to use only PHP, not JS or other... I cant see anything wrong... Thanks

1
1. Do you really pass user and password as part of the url? everybody listening to your conversation may read user and password information directly... 2. Did you follow the link in the response? - Stephen Reindl
1. How I can pass user/password other way? 2. I dont understand the question - Vojtěch Pšenák
Passing user/password as part of the Url is usually a very insecure way. Please consult your API documentation if there are any other way (especially as you are passing username and passwort as part of the POST data as well). The link I refer to is freedesktop.org/wiki/Specifications/open-collaboration-services. Another point, passing POST data remains unsecure as well as long as http is used instead of https - Stephen Reindl
There is a doc to API: doc.owncloud.org/server/8.0/admin_manual/configuration_user/… Yes, I follow it and I dont get any help on the link - Vojtěch Pšenák

1 Answers

0
votes
$owncloud_postdata = array(
            'userid' => "testname",
        'password' => "testpassword,
);

should be

$owncloud_postdata = array(
            'userid' => "testname",
        'password' => "testpassword
);