igniterealtime / REST-API-Client

Java REST API Client for the Openfire to manage Openfire instances by sending an REST/HTTP request to the server
Apache License 2.0
102 stars 62 forks source link

Adding a user to roster only partially works #2

Closed anonimal closed 9 years ago

anonimal commented 9 years ago

Greetings, Redor, Thank you for creating a very useful, much-needed API! I hope that Ignite pulls this into their base someday.

Scenario: Openfire 3.10 REST API 1.1.0 1) Create username "newuser" 2) Add a previously registered user "testuser" to "newuser"'s roster (by "previously", I mean I did not use this API to register "testuser"). 3) Add "newuser" to "testuser"'s roster

Outcome: 1) Works very well 2) Works somewhat: it returns 201 but presents problems 3) Works somewhat: it returns 201 but presents problems

Process: Not that it matters, but all requests are sent with cURL/PHP. I'm seeing everything on the wire with a tcpdump so I know exactly what's being sent. Also, I am using JSON for all requests.

Problems: The problems for 2) and 3) are as follows:

Data: 1) POST /plugins/restapi/v1/users/ HTTP/1.1 Host: 127.0.0.1:9090 Accept: application/json Authorization: Content-type: application/json User-Agent: curl/PHP Content-Length: 117

{"username":"newuser","password":"password123","name":"newuser","email":"newuser@server.domain","groups":[]}

2) POST /plugins/restapi/v1/users/newuser/roster HTTP/1.1 Host: 127.0.0.1:9090 Accept: application/json Authorization: Content-type: application/json User-Agent: curl/PHP Content-Length: 72

{"jid":"testuser@server.domain","name":"testuser","subscription":"3"}

3) POST /plugins/restapi/v1/users/testuser/roster HTTP/1.1 Host: 127.0.0.1:9090 Accept: application/json Authorization: Content-type: application/json User-Agent: curl/PHP Content-Length: 74

{"jid":"newuser@server.domain","name":"newuser","subscription":"3"}

Solutions: I know that subscriptionType is an integer and I have tried every iteration possible that I could think of for the "subscription" value, such as: 0, 1, 2, 3, true, false (and all of these in quotations). None of these have worked.

Am I missing a step or is this a bug? Could you provide a working JSON example for the above process?

Thank you for your help!

Redor commented 9 years ago

Hey,

The subscription parameter should be named "subscriptionType" and not "subscription". And the "name" paramter should be "nickname". That should work:

{
  "rosterItem": {
    "jid": "test@localhost.de",
    "nickname": "redeyes",
    "subscriptionType": "1"
  }
}
anonimal commented 9 years ago

Excellent! This works great. Thank you!