[JSON API] Help with callbacks

Suggestions and discussion of future versions
Post Reply
Hiram
Member
Member
Posts: 16
Joined: Thu Jan 20, 2011 7:34 am

[JSON API] Help with callbacks

Post 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?
Cas
Top Bloke
Top Bloke
Posts: 3679
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: JSON API callbacks

Post 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:
Hiram
Member
Member
Posts: 16
Joined: Thu Jan 20, 2011 7:34 am

Re: JSON API callbacks

Post 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.
Cas
Top Bloke
Top Bloke
Posts: 3679
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: JSON API callbacks

Post 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.
Post Reply