Upload a nzb using the api?

Get help with all aspects of SABnzbd
Forum rules
Help us help you:
  • Are you using the latest stable version of SABnzbd? Downloads page.
  • Tell us what system you run SABnzbd on.
  • Adhere to the forum rules.
  • Do you experience problems during downloading?
    Check your connection in Status and Interface settings window.
    Use Test Server in Config > Servers.
    We will probably ask you to do a test using only basic settings.
  • Do you experience problems during repair or unpacking?
    Enable +Debug logging in the Status and Interface settings window and share the relevant parts of the log here using [ code ] sections.
Post Reply
User avatar
Hmail
Release Testers
Release Testers
Posts: 65
Joined: August 12th, 2008, 1:13 pm

Upload a nzb using the api?

Post by Hmail »

I am trying to upload a nzb by using the api, so far I have this (perl):

Code: Select all

my $req = POST $url."api?mode=addfile&ma_username=".$username."&ma_password=".$password."&name=".$filename, Content_Type => 'form-data', Content => [$filename=>[$location."/".$filename]];
But this doesn't work. I get the following error message:

Code: Select all

        <h2>500 Internal error</h2>
        <p>The server encountered an unexpected condition which prevented it from fulfilling the request.</p>
        <pre id="traceback">Traceback (most recent call last):
  File "/usr/src/tar.gz/SABnzbd-0.4.2/cherrypy/_cphttptools.py", line 126, in _run
    applyFilters('before_finalize')
  File "/usr/src/tar.gz/SABnzbd-0.4.2/cherrypy/filters/__init__.py", line 151, in applyFilters
    method()
  File "/usr/src/tar.gz/SABnzbd-0.4.2/sabnzbd/utils/multiauth/filter.py", line 61, in beforeFinalize
    **rsrc.callable_kwargs)
TypeError: api() got an unexpected keyword argument 'file.nzb'
</pre>
    <div id="powered_by">
    <span>Powered by <a href="http://www.cherrypy.org">CherryPy 2.3.0</a></span>
    </div>
I know I am doing something wrong, but I have no idea what. Can anyone help me out?
(Oh, and for the non-perl people, or the people who are to lazy to figure out what URL I am using ;)), The above code would do an URL like:
http://server:7777/sabnzbd/api?mode=add ... e=file.nzb.
And together with this, it'll post a file with the name file.nzb. If I run php with a print_r over the $_FILES array, I get this:

Code: Select all

    [file_nzb] => Array                                           
        (                                                                 
            [name] => file.nzb                                    
            [type] => text/plain                                          
            [tmp_name] => /tmp/phpzLa6F1                                  
            [error] => 0                                                  
            [size] => 217853                                              
        )
But, how about the error message, can anyone help me out? Thanks in advance!
User avatar
switch
Moderator
Moderator
Posts: 1380
Joined: January 17th, 2008, 3:55 pm
Location: UK

Re: Upload a nzb using the api?

Post by switch »

The contents of the nzb need to be sent, here is an example request:
http://sabnzbd.org/switch/example1.txt
User avatar
Hmail
Release Testers
Release Testers
Posts: 65
Joined: August 12th, 2008, 1:13 pm

Re: Upload a nzb using the api?

Post by Hmail »

OK, didn't know that, but I still can't get it working. The log of my request: http://pastebin.com/m55c32171

The code I am using:

Code: Select all

my $req = POST $url."api?mode=addfile&ma_username=".$username."&ma_password=".$password."&name=".$filename, Content_Type => 'multipart/form-data', Content => [$file_content];
And, of course, in $file_content is the nzb.

Thanks for the really fast answer, and I hope you can help me with this. If you need the whole script I am using, I'll be happy to assist you helping me ;)

edit: Hmm, while looking at the log, I think the answer is around here:

Code: Select all

Content-Disposition: form-data; name="<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>
Just a minute, I'll try to figure out what is going wrong.

edit2: Okay, fixed that, but it still doesn't work: http://pastebin.com/f6d4928b7
And the code I am using right now, somewhat de-scrambled:

Code: Select all

my $call_url = $url."api?mode=addfile&ma_username=".$username."&ma_password=".$password."&name=".$filename;
my $req = POST $call_url,
   Content_Type => 'multipart/form-data',
   Content => [nzbfile=> [$location."/".$filename],
   ];
Last edited by Hmail on August 12th, 2008, 2:41 pm, edited 1 time in total.
User avatar
switch
Moderator
Moderator
Posts: 1380
Joined: January 17th, 2008, 3:55 pm
Location: UK

Re: Upload a nzb using the api?

Post by switch »

Just realised my headers were from the non-api request, so things may be a little different. Instead of:

Code: Select all

name="nzbfile"; filename="file.nzb"
try:

Code: Select all

name="name"; filename="file.nzb"
Not sure if there is anything else wrong, it's late and I'm tired; can help again tomorrow.

Some more info if you need it can maybe be found in this conversation: http://forums.sabnzbd.org/index.php?topic=605.30
User avatar
Hmail
Release Testers
Release Testers
Posts: 65
Joined: August 12th, 2008, 1:13 pm

Re: Upload a nzb using the api?

Post by Hmail »

That works! Thanks!

Should be documented though.. the documentation only says:
Upload an NZB file, the is the pathless name of the filename

http://host:port/sabnzbd/api?mode=addfile&name=&cat=&pp=&script=

Omitted parameters (cat, pp or script) will get default values.
If you want to force an empty parameter, use an empty string, e.g. script="".
Oh, and for future reference, my script:

Code: Select all

my $call_url = $url."api?mode=addfile&ma_username=".$username."&ma_password=".$password."&name=".$filename;
my $req = POST $call_url,
   Content_Type => 'multipart/form-data',
   Content => [name=> [$location."/".$filename],
   ];
User avatar
Hmail
Release Testers
Release Testers
Posts: 65
Joined: August 12th, 2008, 1:13 pm

Re: Upload a nzb using the api?

Post by Hmail »

crap.. I am trying to improve my script with a windows application, but I don't remember how to get the request headers. Can anyone help me out? How can I see what my client posts to cherrypy? (C# provides no way to get a detailed log).
Thanks in advance!
User avatar
inpheaux
Administrator
Administrator
Posts: 562
Joined: January 16th, 2008, 9:14 pm

Re: Upload a nzb using the api?

Post by inpheaux »

Look through the cherrypy log, or alternatively, run the console version of sabnzbd to see it live.
User avatar
Hmail
Release Testers
Release Testers
Posts: 65
Joined: August 12th, 2008, 1:13 pm

Re: Upload a nzb using the api?

Post by Hmail »

Well, that doesn't quite do as I expect.. If I run it directly, or use the weblogging, I get messages like:

Code: Select all

28/Dec/2008:00:06:26 HTTP INFO Traceback (most recent call last):
  File "/usr/src/tar.gz/SABnzbd-0.4.5/cherrypy/_cphttptools.py", line 126, in _run
    applyFilters('before_finalize')
  File "/usr/src/tar.gz/SABnzbd-0.4.5/cherrypy/filters/__init__.py", line 151, in applyFilters
    method()
  File "/usr/src/tar.gz/SABnzbd-0.4.5/sabnzbd/interface.py", line 234, in beforeFinalize
    **rsrc.callable_kwargs)
TypeError: api() got an unexpected keyword argument 'filename'

192.168.178.20 - - [28/Dec/2008:00:06:26] "POST /sabnzbd/api?mode=addfile&filename=E:%5Cdownloads%5Cfile.nzb HTTP/1.1" 500 - "" ""
I expected the whole request, like the pastebin's and the example from Switch, but don't know how to get it anymore..
Post Reply