Register new user in ejabberd with REST API

2.3k views Asked by At

I am using ejabberd-18.01 on Windows 10 (localhost). I am trying to connect to ejabberd via Postman using the web method:

POST: localhost:5280/api/specific_api_method

As per the official API documentation (https://docs.ejabberd.im/developer/ejabberd-api/admin-api/), I am trying to add a roster item using the POST method with the body that follows:

POST: localhost:5280/api/add_rosteritem

{ "localuser": "user1", "localserver": "mydomain", "user": "admin", "server": "mydomain", "nick": "u1", "group": "Friends", "subs": "both" }

I am getting an error:

{ "status": "error", "code": 32, "message": "AccessRules: Account does not have the right to perform the operation." }

I will be grateful if somebody can guide me how to authenticate myself and add a new user or roster item to ejabberd using the web API. Thanks.

1

There are 1 answers

0
dilwaria On

make these changes in your yml file config file

change loopback in acl to this:

loopback:
    ip:
      - "127.0.0.0/8"
      - "::1/128"
      - "::FFFF:127.0.0.1/128"

and use this api_permissions:

api_permissions:
  "console commands":
    from:
      - ejabberd_ctl
    who: all
    what: "*"
  "admin access":
    who:
      - access:
          - allow:
            - ip: "127.0.0.1/8"
            - acl: admin
      - oauth:
        - scope: "ejabberd:admin"
        - access:
          - allow:
              - ip: "127.0.0.1/8"
              - acl: admin
    what:
      - "*"
      - "!stop"
      - "!start"
  "public commands":
    who:
      - acl: loopback
    what:
      - "status"
      - "register"
      - "connected_users_number"

this issue have been closed at : Access denied issue on ejabberd