Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access ejabberd admin api via HTTP?

I read about the doc https://docs.ejabberd.im/admin/api/

And I wonder how can I access those API via HTTP. I tried to access but it always 404.

like image 213
Sirui Zhuang Avatar asked May 06 '16 04:05

Sirui Zhuang


People also ask

How do I connect to Ejabberd server?

Open the Web Admin page in your favourite browser. The exact address depends on your ejabberd configuration, and may be http://localhost:5280/admin/, https://localhost:5443/admin/, https://localhost:5280/admin/ ... Make sure to enter the full JID, in this example [email protected] . See Web Admin for details.

How do I add a user to Ejabberd?

Create chat users in ejabberd real time IM serverIn the web admin console, using the side menu, go to Virtual Hosts and click on your domain. Then from the side menu select Users. You can add each user by typing in the username and password. All users appear on the list below.


1 Answers

In your ejabberd.yml you can find a configuration like this

- 
port: 5280
module: ejabberd_http
request_handlers:
  "/websocket": ejabberd_http_ws

Enable api and oauth,

- 
port: 5280
module: ejabberd_http
request_handlers:
  "/websocket": ejabberd_http_ws
  "/api": mod_http_api
  "/oauth": ejabberd_oauth

We are enabling api to have access from other programming languages(JSON request and response)

We are enabling oauth to raise an api request and get response(Without which if we access /api we will get only 401-unauthorized error)

Once this configuration in done, give a http request in your browser. URL must be

http://localhost:5280/oauth/authorization_token?response_type=token&client_id=Client1&scope=get_roster+connected_users

get_roster and connected_users are API end points Clinet1 is some name that you can give response_type must be always token

Once you hit it it will render a screen as this,

enter image description here

Enter your admin details and click on accept

Then in the url you will find a change something like this

http://localhost:5280/oauth/authorization_token?access_token=Ra9W9aRgeoUgIpN0P68SIGDaatDIVcgB&token_type=bearer&expires_in=3600&scope=get_roster%20connected_users&state=

You can see a access token there copyit and do a curl to get the connected users. (Type this command in your terminal)

curl -v POST -H "X-Admin: true" -H "Authorization: Bearer Ra9W9aRgeoUgIpN0P68SIGDaatDIVcgB" http://localhost:5280/api/connected_users -d '[]'

You will get a Json response with all connected users.

This is how you should make API calls in ejabberd. Hope this helps :)

like image 152
Niranj Rajasekaran Avatar answered Sep 18 '22 02:09

Niranj Rajasekaran