REST Api Create user and modify roster example needed please

I found the following code online which works great but it is only retrieving information on the user. RedEyes, or anyone else, can you show me what the code would look like by doing the following 2 things: 1) Create a user. 2) Add or change a roster item for this user such as adding a friend, etc.


$secret = ``'xxxxxxxxxxxxxxx'``;

$url = ``""``;

$headers = ``array``(

``'http' => ``array``(

``'method' => ``"GET"``,

``'header' => ``"Authorization: " . ``$secret . ``"\r\n"



$context = stream_context_create(``$headers``);

$response = ``file_get_contents``(``$url``, false, ``$context``);

echo $response``;


I would recommend you to use the follow project: gidkom/php-openfire-restapi · GitHub
It is able to create new users and add roster entries.

Will do, thanks!

Hello Guys,

I have to add roster programmatically and i am using this code

$result = $api->addToRoster(‘Username’, ‘Password’, ‘Real Name’, ‘’, array(‘Group 1’));

Here Roster is adding successfully but group is not adding, it always show none.

Please navigate me what i have to change.


I guess you mix something up.

If I read the readme of

There is no:

$result = $api->addToRoster('Username', 'Password', 'Real Name', '', array('Group 1'));


You can only create new user by opefire (not roster) with:

$result = $api->addUser('Username', 'Password', 'Real Name', '', array('Group 1'));

To add a roster entry you need to use follow:

$api->addToRoster($username, $jid);

Hello Redeyes,

Thanks for reply.

Please can you let me know that what is code to add roster with Subscription key and Group also.


Such I see it is not possible to add roster entry to a group with the script of:

Hello Guys,

Can you please help me for update roster entry using rest api gidkom/php-openfire-restapi · GitHub code.

Thanks in advance…