0
votes

I am going to develop a chat application using ejabberd using ReactJs. I installed ejabberd on our server. I followed the API documentation from the below link.

https://docs.ejabberd.im/developer/ejabberd-api/admin-api/#registered-users

I want to try any api in postman before implementing. But I didn't get the API URL and host name from any of the document.

My ejabberd server admin URL is http://192.168.5.242:5280/admin

Also, I wish to use https://www.npmjs.com/package/ejabberd. But there I can see the usage of host name.

I tried so many ports instead of 5280. But not working for me.

2

2 Answers

0
votes

But I didn't get the API URL and host name from any of the document.

You define the port number in the ejabberd configuration file, in the 'listen' section. For example, in my case I use 5282 for mod_http_api, and path /api:

  -
    port: 5282
    module: ejabberd_http
    request_handlers:
      "/api": mod_http_api
      "/bosh": mod_bosh
      "/oauth": ejabberd_oauth
      "/rest": mod_rest

My ejabberd server admin URL is http://192.168.5.242:5280/admin

Then, if you add the lines that I have, your url for mod_http_api would be http://192.168.5.242:5282/api

0
votes

As an example call, I use this php script:

<?php
$url='localhost:5282/api/registered_users/';
$login="key";
$password='secret';
$request=null;
$info=array(
            "host"=>"localhost"
           );
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($info));
$output=curl_exec($ch);
curl_close($ch);
print_r($output);
?>

This is the result of the query:

$ php test.php 
["user1","user2"]

Sniffing the network traffic, this is the query:

POST /api/registered_users/ HTTP/1.1
Host: localhost:5282
Accept: */*
Content-Length: 20
Content-Type: application/x-www-form-urlencoded

{"host":"localhost"}

and this is the response:

HTTP/1.1 200 OK
Content-Length: 17
Content-Type: application/json
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type, Authorization, X-Admin

["user1","user2"]