API error creating user " failure 998 Invalid query"

Im trying to use the API on nextcloud 16 ( lastest as of today)
On trying to create a user on my install via command line, using

curl -X POST http://admin:mypass@myinstall.com/ocs/v1.php/cloud/users -H "OCS-APIRequest: true" -d userid="newuser" -d password="newpassword

This works fine and a new user is created.

The problem is when i use curl -

$url = 'http://admin:mypass@myinstall.com/ocs/v1.php/cloud/users -H "OCS-APIRequest: true";

$data = [
'userid' => $username, 
'password' => $userpassword, 

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
echo "Response from curl :" . $response;

i get Response from curl : failure 998 Invalid query, please check the syntax. API specifications are here: http://www.freedesktop.org/wiki/Specifications/open-collaboration-services.

Any one how any ideas or advise that might help. be much appreciated.


space problem for me.
should be “OCS-APIRequest:true”

$url = 'http://admin:mypass@myinstall.com/ocs/v1.php/cloud/users -H "OCS-APIRequest:true";
Ive tried that and still the error 998.

Sorry it did not do the trick.

This seem good anyway.

998 means notfound.

docsnextcloud is down actually …

Do you have any info where you found the 998 means not found, ive looked for ages and cant find a thing.
Its weird how it works via SSH but not curl.


  • 100 - successful
  • 996 - server error
  • 997 - not authorized
  • 998 - not found
  • 999 - unknown error

Thanks for that.
Not sure what it’s not finding, as the command line actually works.
Anyone else have any ideas?
I can’t see that the API won’t work with curl or maybe I’m wrong. :thinking:

Surely someone has got this working ???

below code worked for me:

	$params = array(
		'userid'   => 'test03',
		'displayName' => 'test03',
		'password' => 'test03@1234',
		'email' => 'test03@example.com',
		'groups[]' => 'admin'
	$headers = array(
	    'Accept: application/json',

	$ch = curl_init("http://example.com/ocs/v1.php/cloud/users");
	curl_setopt($ch, CURLOPT_USERPWD, "user:password");

	curl_setopt($ch,CURLOPT_POST, true);
	curl_setopt($ch,CURLOPT_POSTFIELDS, $params);
	curl_setopt($ch,CURLOPT_CUSTOMREQUEST, 'POST');
	curl_setopt($ch,CURLOPT_HTTPHEADER, $headers);
	curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch,CURLOPT_FOLLOWLOCATION, false);
	$response = curl_exec($ch);

below is github repository having utils functions to create group and user :