Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add New User Failed #35

Open
Keram-Yasin opened this issue Mar 12, 2023 · 0 comments
Open

Add New User Failed #35

Keram-Yasin opened this issue Mar 12, 2023 · 0 comments

Comments

@Keram-Yasin
Copy link

Keram-Yasin commented Mar 12, 2023

I have installed the php-openfire-restapi successfully. I have also enabled the REST API on the server. I am able to get user using the $api->getUser($userName) command. But I am not able to add new user to the Openfire server with the command.
The command i used:

`<?php
include './vendor/autoload.php';

// Create the Openfire Rest api object
$api = new Gidkom\OpenFireRestApi\OpenFireRestApi;

// Set the required config parameters
$api->secret = "*********";
$api->host = "localhost";
$api->port = "9090"; # default 9090

// Optional parameters (showing default values)

$api->useSSL = false;
$api->plugin = "/plugins/restapi/v1"; // plugin

// Retrieve users
$result = $api->addUser('mamut', '123456', 'Mamut', '[email protected]');
//$Username = 'ahmat'; // optional
//$result = $api->getUser($userName);

// Check result if command is succesful
if($result['status']) {
// Display result
print_r($result['message']);
} else {
// Something went wrong
echo 'Error: ';
echo $result['message'];
}
?>
`
I got the following error when i execute above code:

PHP Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: POST http://localhost:9090/plugins/restapi/v1/users` resulted in a 400 Bad Request response:
Unrecognized field "groups" (class org.jivesoftware.openfire.plugin.rest.entity.UserEntity), not marked as ignorable (5 (truncated...)
in /home/knook/scripts/RESTAPI/php-openfire-restapi/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
Stack trace:
#0 /home/knook/scripts/RESTAPI/php-openfire-restapi/vendor/guzzlehttp/guzzle/src/Middleware.php(65): GuzzleHttp\Exception\RequestException::create()
#1 /home/knook/scripts/RESTAPI/php-openfire-restapi/vendor/guzzlehttp/promises/src/Promise.php(204): GuzzleHttp\Middleware::GuzzleHttp{closure}()
#2 /home/knook/scripts/RESTAPI/php-openfire-restapi/vendor/guzzlehttp/promises/src/Promise.php(153): GuzzleHttp\Promise\Promise::callHandler()
#3 /home/knook/scripts/RESTAPI/php-openfire-restapi/vendor/guzzlehttp/promises/src/TaskQueue.php(48): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise{closure}()
#4 /home/knook/scripts/RESTAPI/php-openfire-restapi/vendor/guzzlehttp/promises/src/Promise.php(248): GuzzleHttp\Promise\TaskQueue->run()
#5 /home/knook/scripts/RESTAPI/php-openfire-restapi/vendor/guzzlehttp/promises/src/Promise.php(224): GuzzleHttp\Promise\Promise->invokeWaitFn()
#6 /home/knook/scripts/RESTAPI/php-openfire-restapi/vendor/guzzlehttp/promises/src/Promise.php(269): GuzzleHttp\Promise\Promise->waitIfPending()
#7 /home/knook/scripts/RESTAPI/php-openfire-restapi/vendor/guzzlehttp/promises/src/Promise.php(226): GuzzleHttp\Promise\Promise->invokeWaitList()
#8 /home/knook/scripts/RESTAPI/php-openfire-restapi/vendor/guzzlehttp/promises/src/Promise.php(62): GuzzleHttp\Promise\Promise->waitIfPending()
#9 /home/knook/scripts/RESTAPI/php-openfire-restapi/vendor/guzzlehttp/guzzle/src/Client.php(182): GuzzleHttp\Promise\Promise->wait()
#10 /home/knook/scripts/RESTAPI/php-openfire-restapi/vendor/guzzlehttp/guzzle/src/Client.php(95): GuzzleHttp\Client->request()
#11 /home/knook/scripts/RESTAPI/php-openfire-restapi/vendor/gidkom/php-openfire-restapi/src/Gidkom/OpenFireRestApi/OpenFireRestApi.php(58): GuzzleHttp\Client->__call()
#12 /home/knook/scripts/RESTAPI/php-openfire-restapi/vendor/gidkom/php-openfire-restapi/src/Gidkom/OpenFireRestApi/OpenFireRestApi.php(118): Gidkom\OpenFireRestApi\OpenFireRestApi->doRequest()
#13 /home/knook/scripts/RESTAPI/php-openfire-restapi/test.php(18): Gidkom\OpenFireRestApi\OpenFireRestApi->addUser()
#14 {main}
thrown in /home/knook/scripts/RESTAPI/php-openfire-restapi/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 113
`
I skipped the last parameter from $api->addUser function: array('Group 1'); Because i wanted to only add a user without adding to any group. I have also added a group to Openfire server name "Group 1", and i called the following function:
$result = $api->addUser('mamut', '123456', 'Mamut', '[email protected]', array('Group 1'));
But i sill got above error message.

Did i made any mistake in my code or there is something wrong with the php-openfire-restapi?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant