1
votes

I am trying to make some rest requests (without OAuth) but ejabberd response is always "HTTP/1.1 400 Bad Request"

Here is the detail:

ejabberd version: 16.02

ejabberd configuration

port: 5280
    ip: "::"
    module: ejabberd_http
    request_handlers:
      ##"/websocket": ejabberd_http_ws
      ##"/oauth": ejabberd_oauth
      "/api": mod_http_api
    ##  "/pub/archive": mod_http_fileserver
    web_admin: true
    http_bind: true
    http_poll: true
    ## register: true
    captcha: false
    commands_admin_access: configure
    commands:
      - add_commands: user
    oauth_expire: 3600
    oauth_access: all

Request

curl -v -X POST -H "X-Admin: true" -H "Authorization: Basic YWRtaW5AcHJqLmlvOmFkbWlu"  -H "Content-Type:application/json" http://prj.io:5280/api/status -d '{}'

Logs

2016-03-26 04:38:04.711 [debug] <0.490.0>@ejabberd_http:process_header:281 (#Port<0.16265>) http query: 'POST' <<"/api/status">>
2016-03-26 04:38:04.711 [debug] <0.490.0>@ejabberd_http:extract_path_query:395 client data: <<"{}">>
2016-03-26 04:38:04.711 [debug] <0.490.0>@ejabberd_http:process:353 [<<"api">>,<<"status">>] matches [<<"api">>]
2016-03-26 04:38:04.711 [info] <0.490.0>@mod_http_api:log:388 Admin call status [] from ::FFFF:192.168.117.1:53583

Please help me out to understand ejabberd's behaviour and the way to post some requests to mod_http_api.

2
I am unable to generate the token, struggling in this for nearly 3 days and I am new to ejabbberd, this is the configuration that I use. port: 5280 module: ejabberd_http request_handlers: "/websocket": ejabberd_http_ws # OAuth Support "/oauth": ejabberd_oauth # ReST API: "/api": mod_http_api ## "/pub/archive": mod_http_fileserver web_admin: true http_bind: true register: true captcha: false commands_admin_access: configure commands: - add_commands: user oauth_expire: 3600 oauth_access: allJ P
Try to implement this answer.Niranj Rajasekaran

2 Answers

0
votes

try the below ...

commands_admin_access: configure
commands:
   - add_commands:
     - status
0
votes

In Request you have given,

curl -v -X POST -H "X-Admin: true" -H "Authorization: Basic YWRtaW5AcHJqLmlvOmFkbWlu" -H "Content-Type:application/json" http://prj.io:5280/api/status -d '{}'.

There is no such end point status

Try one of the following as you endpoint,

  1. num_active_users - Number of users active in the last days
  2. status_num_host - Number of logged users with given status in host
  3. status_num - Number of logged users with given status
  4. stats - Get statistical value: registered users, online users, online users node, uptime seconds stats_host - Get statistical value per host: registered users, online users, online users node, uptime seconds