[JSON API] add_torrent_magnet with json rpc

General support for problems installing or using Deluge
Post Reply
gprime
New User
New User
Posts: 7
Joined: Thu Apr 19, 2012 7:28 pm

[JSON API] add_torrent_magnet with json rpc

Post by gprime »

I am trying to add a magnet uri but its not working. I am doing the following:

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/jsonHTTP/1.1 200 OK
Transfer-Encoding: chunked
Date: Thu, 19 Apr 2012 19:36:53 GMT
Content-Encoding: gzip
Content-Type: application/x-json
Server: TwistedWeb/11.0.0
Set-Cookie: _session_id=cf90eafbdc0691d7eed8bff8756c7f872511; Expires=Thu, 19 Apr 2012 20:36:53 GMT; Path=/json

{"id": 1, "result": true, "error": null} 
Then i am trying to add a magnet:

Code: Select all

$curl -b cookies.txt --compressed -i -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"method": "core.add_torrent_magnet", "params": ["magnet:?xt=urn:btih:67257d9765f7fbe40fc00290e47827d6d3edbf5d&dn=Game+of+Thrones+S02E03+HDTV+x264-ASAP+%5Beztv%5D&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80&tr=udp%3A%2F%2Ftracker.ccc.de%3A80"], "id": 1}' http://localhost:8112/json
That call just hangs and does nothing. These commands are being entered on my terminal on my mac. Is there something I am doing wrong?
Cas
Top Bloke
Top Bloke
Posts: 3681
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: add_torrent_magnet with json rpc

Post by Cas »

It takes two parameters, uri string and an options dict:

Code: Select all

curl -b cookies.txt --compressed -i -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"method": "core.add_torrent_magnet", "params": ["uri", {}], "id": 1}' http://localhost:8112/json
gprime
New User
New User
Posts: 7
Joined: Thu Apr 19, 2012 7:28 pm

Re: add_torrent_magnet with json rpc

Post by gprime »

I am not sure what I am doing wrong. I did the following:

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/jsonHTTP/1.1 200 OK
Transfer-Encoding: chunked
Date: Mon, 23 Apr 2012 18:37:22 GMT
Content-Encoding: gzip
Content-Type: application/x-json
Server: TwistedWeb/11.0.0
Set-Cookie: _session_id=57c9165bbf2ff310b6ec659e276d78462213; Expires=Mon, 23 Apr 2012 19:37:22 GMT; Path=/json

{"id": 1, "result": true, "error": null}
And then tried to add a magnet uri using the following:

Code: Select all

$ curl -b cookies.txt --compressed -i -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"method": "core.add_torrent_magnet", "params": ["uri", {"THE_MAGNET_URI"}], "id": 1}' http://localhost:8112/json
HTTP/1.1 500 Internal Server Error
Date: Mon, 23 Apr 2012 18:37:31 GMT
Content-Length: 0
Content-Type: text/html
Server: TwistedWeb/11.0.0
Does deluge log the errors? I have deluge installed on my mac but it is only running from the .app file I downloaded. I could nto get it installed using macports (it errored out). I have the deamon running and enabled the WebUi.
Cas
Top Bloke
Top Bloke
Posts: 3681
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: add_torrent_magnet with json rpc

Post by Cas »

params should be ["THE_MAGNET_URI", {}] not ["uri", {"THE_MAGNET_URI"}]
gprime
New User
New User
Posts: 7
Joined: Thu Apr 19, 2012 7:28 pm

Re: add_torrent_magnet with json rpc

Post by gprime »

Ah ok, now I am getting:

Code: Select all

$ curl -b cookies.txt --compressed -i -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"method": "core.add_torrent_magnet", "params": ["MAGNET_URI", {}], "id": 1}' http://localhost:8112/json
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Date: Tue, 24 Apr 2012 21:16:13 GMT
Content-Encoding: gzip
Content-Type: application/x-json
Server: TwistedWeb/11.0.0

{"id": 1, "result": null, "error": {"message": "Unknown method", "code": 2}}
Does this mean the "core.add_torrent_magnet" method is not correct?
Cas
Top Bloke
Top Bloke
Posts: 3681
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: add_torrent_magnet with json rpc

Post by Cas »

You cannot be connected to the daemon. Either use the connection manager in webui or use these methods (from the json api docs) to find the daemon hostid and connect:

Code: Select all

web.get_hosts()
web.get_host_status(host_id)
web.connect(host_id)
Does deluge log the errors? I have deluge installed on my mac but it is only running from the .app file I downloaded.
You can enable logging with different levels from info to debug for both deluged and deluge-web but you would need to ask carbnl to clarify how this is done for .app.
Post Reply