Skip to content

Add New User Failed #35

@keramjan

Description

@keramjan

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', 'mamut@gmail.com');
//$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', 'mamut@gmail.com', 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions