Page 1 of 1

[JSON API] Help with callbacks

Posted: Tue Nov 29, 2011 10:37 am
by Hiram
I'm trying to use the JSON API, however I'm a bit puzzled by the use of the callbacks. If I'm on a remote machine, sending these JSON requests, how can I specify a callback?

Re: JSON API callbacks

Posted: Tue Nov 29, 2011 7:35 pm
by Cas
I asked damoxc about your question and hes not entirely sure what you are trying to do and would need some more clarification however he supplied these links:

Re: JSON API callbacks

Posted: Tue Nov 29, 2011 10:07 pm
by Hiram
Essentially, at this point, I'm just trying to get anything out of Deluge, using curl. Once I do that I'll move onto something else. I haven't used JSON-RPC before so I'm unsure if I'm doing something wrong. Here's what I'm trying at the moment.

Code: Select all

$ curl -X POST --data '{"id": 1, "method": "login", "params": ["password"]}' http://localhost:8112/json
�V�LQ�R0�QP*J-.�)r�Jsr��Ԣ��" �Z)7��81=�V
����/�S�M-��OQ*K�O���v�~SL
The binary is the output of the command, which I find strange. If I change the URL to /json/rpc I get a HTML 404 page.

Re: JSON API callbacks

Posted: Mon Mar 05, 2012 11:07 pm
by Cas
The first problem is that you need to use the method auth.login and secondly the response is gzipped so by adding the compressed option, it will uncompress the data. Finally in order to connect you need to store the session id in a cookie. Here is an example using curl:

Code: Select all

curl -c cookies.txt --compressed -i -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"method": "auth.login", "params": ["deluge"], "id": 1}' http://localhost:8112/json

Code: Select all

curl -b cookies.txt --compressed -i -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"method": "web.connected", "params": [], "id": 1}' http://localhost:8112/json

Code: Select all

curl -b cookies.txt --compressed -i -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"method": "web.get_torrent_files", "params": ["<torrentid>"], "id": 1}' http://localhost:8112/json
Hope this helps.