Linux shell JSON troubles

Get help, report and discuss bugs.
Post Reply
Nedle
Posts: 49
Joined: 06 Aug 2014, 10:24

Linux shell JSON troubles

Post by Nedle » 21 Aug 2014, 12:45

I'm trying to port the FailureLink script for DogNZB which was build in python to a linux shell script. Got quite far, but stuck with adding the new nzb to que.
Keep getting this error:
{ "version" : "1.1", "error" : { "name" : "JSONRPCError", "code" : 2, "message" : "Invalid parameter (Category)" } }

Not quite sure how to format the JSON to get it correctly though, I already correctly extract the filename/category/new link from the headers. But the JSON request is giving me troubles..
Tried multiple variations, this is what it is now but also tried without quotes/less quotes/whatever:

Code: Select all

curl -X POST -d '{"method": "appendurl", "params":{'"$filename"','"$dnzb_category"', 0, false, '"$new_link"', 0}}' -H 'content-type: application/json;' http://$username:$password@$host:$port/jsonrpc
Whole script can be found here:
https://www.dropbox.com/s/5sfu8ld91d3ot ... reShell.sh

Any help is much appreciated
Last edited by Nedle on 21 Aug 2014, 13:09, edited 1 time in total.

hugbug
Developer & Admin
Posts: 7645
Joined: 09 Sep 2008, 11:58
Location: Germany

Re: Linux shell JSON troubles

Post by hugbug » 21 Aug 2014, 12:58

The easiest is to send an URL via web-interface and use browser's developer pane "network" to see what was sent.
Connect to your device from a desktop browser (instead of installing NZBGet on PC, this is to be sure you use the same NZBGet version).

mannibis
Posts: 60
Joined: 29 Jul 2014, 15:10

Re: Linux shell JSON troubles

Post by mannibis » 21 Aug 2014, 13:15

Try using "method" : "append" ?

This is the Documentation for the append method
http://nzbget.net/RPC_API_reference#Method_.22append.22

Nedle
Posts: 49
Joined: 06 Aug 2014, 10:24

Re: Linux shell JSON troubles

Post by Nedle » 21 Aug 2014, 13:53

Running NZBGet 12 so can't use urls with append. Need to use appendurl. I can pass the filename/category correctly now, they show up in nzbget with the correct filename. However the url is invalid.
The links are of this format (tried http and https)

Code: Select all

http://dognzb.cr/fetch/ca4c5de2a2b596628323f185d06c6c1b/XXXXXXXapikeyXXXXXXXX/?CFID=225013539&CFTOKEN=f95c2b80cc69c7dd-B83C1C6B-AFDC-7E37-ECDE63E5AF9BCE67
Need to use '"$filename"' to get it to use the contents of filename instead of just the string.. However when I do that for the url I get an error, invalid parameter URL. I can get them to add without using the single quotes ' around it but then the url is just the string $new_link so it obviously can't dl anything..

Code: Select all

curl -s -X POST -d '{"method": "appendurl", "params":{'"$filename"',"", 0, false, '"$new_link"', 0}}' -H 'content-type: application/json;' http://$username:$password@$host:$port/jsonrpc 
Got it, had to put double quotes around it again..
Thus:

Code: Select all

"'"$new_link"'"

Can add stuff now, just need to add some error handling and think it's done..

hugbug
Developer & Admin
Posts: 7645
Joined: 09 Sep 2008, 11:58
Location: Germany

Re: Linux shell JSON troubles

Post by hugbug » 21 Aug 2014, 14:45

Nedle wrote:Got it, had to put double quotes around it again..
Thus:

Code: Select all

"'"$new_link"'"
That's bash stuff, not related to NZBGet actually.
Use "echo" to control what the hell is passed as parameter to curl.

Nedle
Posts: 49
Joined: 06 Aug 2014, 10:24

Re: Linux shell JSON troubles

Post by Nedle » 21 Aug 2014, 19:20

Well was getting json errors, appearantly because the quotes were lost again so I had to enclose them again. Anyway, script is done:

https://www.dropbox.com/s/oi66w6c1cxas6 ... k_shell.sh

Should be usable by anyone on linux. If you are not on android you will want to remove the line where I set the PATH variable as it is not needed (line 34).
Also uses the old appendurl method was I'm still on NZBGet 12.0.

Post Reply

Who is online

Users browsing this forum: No registered users and 51 guests