Rajan
Rajan

Reputation: 2425

Openfire RestAPI for PHP Configuration

I am trying to connect to my Openfire Server using RestAPI from Github

Now I have installed RestAPI plugin in Openfire folder. I am on Centos 7.

    <?php

include "vendor/autoload.php";

$api = new \Gnello\OpenFireRestAPI\API();

//Set the required config parameters
$api->Settings()->setSecret("YWRtaW46YWRtaW4");
$api->Settings()->setHost("localhost");
$api->Settings()->setServerName("localhost");

//Default values
$api->Settings()->setPort("9090");
$api->Settings()->setSSL(false);
$api->Settings()->setPlugin("/plugins/restapi/v1");

Now WhenI try to connect it shows error:

if($result['response']) {
    echo $result['output'];
} else {
    echo 'Error!';
}

In httpd logs it says undefined $result which is obvious.

But I followed the steps as it were mentioned on its repository.

Can Any One please guide me how to use this ?

#Udated

    include "vendor/autoload.php";

$api = new \Gnello\OpenFireRestAPI\API();

//Enable debug mode
$api->Settings()->setDebug(true);
$requests = \Gnello\OpenFireRestAPI\Debug\Request::getRequests();

//var_dump($api);

//var_dump($requests);

$result = $api->users();
//var_dump($api);

$username ="test2";
$results = $api->getuser($username); 


 if($result['response']) 
    { 
        echo $result['output']; 
    } 
else 
    { 
        echo 'Error!'; 
    }

Upvotes: 0

Views: 1121

Answers (1)

Shubham Shukla
Shubham Shukla

Reputation: 104

https://github.com/gnello/php-openfire-restapi

Easy Php REST API Client for the Openfire REST API Plugin which provides the ability to manage Openfire instance by sending an REST/HTTP request to the server

Please read documentation for further information on using this application.

Installation

composer require gnello/php-openfire-restapi

Authentication There are two ways to authenticate:

Basic HTTP Authentication

$authenticationToken = new \Gnello\OpenFireRestAPI\AuthenticationToken('your_user', 'your_password');

Shared secret key

$authenticationToken = new \Gnello\OpenFireRestAPI\AuthenticationToken('your_secret_key');

Start

$api = new \Gnello\OpenFireRestAPI\API('your_host', 9090, $authenticationToken);

Users

//Add a new user
$properties = array('key1' => 'value1', 'key2' => 'value2');
$result = $api->Users()->createUser('Username', 'Password', 'Full Name', '[email protected]', $properties);

//Delete a user
$result = $api->Users()->deleteUser('Username');

//Ban a user
$result = $api->Users()->lockoutUser('Username');

//Unban a user
$result = $api->Users()->unlockUser('Username');

Then print Result.

Open Link Fore more. https://github.com/gnello/php-openfire-restapi

Upvotes: 2

Related Questions