Webclients chat api

Good Day

I got Chat API [RESTful API with Server Sent Events (SSE) for Openfire Meetings 0.9.5 Release 5 Ignite Realtime] installed.

I need to know why would api login POST give me unauthorized 401?
I use insomnia to do api call.
What do i do wrong?

http://Server_IP:7070/rest/api/restapi/v1/chat/user/login

Hope someone could direct me what i need to do.

Thank You

Albertus Geyser

Make sure you provide correct HTTP authentication header. Try the Swagger UI directly from Openfire that uses the password generated by the plugin. You should see this

Pay attention to the authentication in the CURL example shown

Good Day

Thank You that helped. I managed to get it working with PHP. :slight_smile:
Now i am looking to create a fastpath integration with PHP.

Thank You once again.

Herewith my uncleaned working code to post message to user:

<?php
$usr = "user";
$pwd = "password";
$host = "chat.lintel.co.za";
$message = "Hallo There Tammy!!\nWhat is news?";
$to = "sales@chat.lintel.co.za";

// Just console logging code (Debugging)
function console_log( $data ){
  echo '<script>';
  echo 'console.log('. json_encode( $data ) .')';
  echo '</script>';
}

// Receive stream id from login and send message
function xmpp_send($host, $streamid, $message, $to, $usr, $pwd){

console_log($streamid);

$payload = Array(
    "body" => $message
);

$payload = json_encode($payload);

// Prepare new cURL resource
$ch = curl_init('http://'.$host.':7070/rest/api/restapi/v1/chat/'.$streamid.'/messages/'.$to);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
 
// Set HTTP Header for POST request 
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: text/plain',
    'Content-Length: ' . strlen($payload),
    'Authorization: Basic '. base64_encode($usr.':'.$pwd))
);
 
// Submit the POST request
$result = curl_exec($ch);
 
// Close cURL session handle
curl_close($ch);
}

// Login with username and password to Openfire.
function xmpp_login($host, $usr, $pwd, $message, $to){
// Prepare new cURL resource
$ch = curl_init('http://'.$host.':7070/rest/api/restapi/v1/chat/'.$usr.'/login');

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POST, true);
 
// Set HTTP Header for POST request 
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: text/plain',
    'Content-Length: 0',
    'Authorization: Basic '. base64_encode($usr.':'.$pwd))
);
 
// Submit the POST request
$result = curl_exec($ch);

xmpp_send($host, $result, $message, $to, $usr, $pwd);

}

xmpp_login($host, $usr, $pwd, $message, $to);

?>

Anyone welcome to use or even improve to make a fully fuctional PHP rest api backend.

Thank You

Albertus Geyser

Thank you for the contribution :slight_smile:

Good Day @Dele_Olajide

Could you maybe help me to send message to group?

Thank You

Albertus Geyser

I have stopped developing the chat api plugin. I am too busy with other projects and I don’t use REST with chat anymore. It is now deprecated. My suggestion is for you to use Strophe or Converse Headless