Page 1 of 2

Problems using API (Switch)

Posted: April 14th, 2012, 8:26 am
by dogzipp
With 7.0b2 I am getting this when I try a switch command like:

api?mode=switch&value=SABnzbd_nzo_RjARgX&value2=1&apikey=[apikey]

Code: Select all

500 Internal Server Error

The server encountered an unexpected condition which prevented it from fulfilling the request.

Traceback (most recent call last):
  File "/mnt/DroboFS/Shares/DroboApps/sabnzbd/cherrypy/_cprequest.py", line 618, in respond
    cherrypy.response.body = self.handler()
  File "/mnt/DroboFS/Shares/DroboApps/sabnzbd/cherrypy/_cpdispatch.py", line 25, in __call__
    return self.callable(*self.args, **self.kwargs)
  File "/mnt/DroboFS/Shares/DroboApps/sabnzbd/sabnzbd/interface.py", line 403, in api
    return api_handler(kwargs)
  File "/mnt/DroboFS/Shares/DroboApps/sabnzbd/sabnzbd/api.py", line 99, in api_handler
    response = _api_table.get(mode, _api_undefined)(name, output, kwargs)
  File "/mnt/DroboFS/Shares/DroboApps/sabnzbd/sabnzbd/api.py", line 356, in _api_switch
    return report(output, data=(pos, prio))
  File "/mnt/DroboFS/Shares/DroboApps/sabnzbd/sabnzbd/api.py", line 854, in report
    data = ' '.join(data)
TypeError: sequence item 0: expected string, int found
BTW, the switch command is processed sucesfully. It's just that there's no XML success response, just the cherrypy error.
Thanks

Re: Problems using API (Switch)

Posted: April 15th, 2012, 2:52 am
by shypike
It crashes when trying to return the new positions,
by expecting a text where an integer number is delivered.
I'll fix that in the next 0.7.0Beta.
Thanks for reporting.

BTW: a work-around is to add "output=json" to the command.
We recommend the use of the json and XML forms instead of plain text.

Re: Problems using API (Switch)

Posted: April 15th, 2012, 1:09 pm
by dogzipp
I am trying out the XML output. Altough it returns XML output, how do I know if the operation was succesful or not? (I don't see any success/error message). Should I assume position -1 is an error?
i get:

<result>
<priority>0</priority>
<position>-1</position>
</result>

I can even use a Non Existant NZBID, and I still get the same XML results. I don't even get an Invalid NZB error or anything.

Re: Problems using API (Switch)

Posted: April 15th, 2012, 3:46 pm
by shypike
A non-existing id will return position -1.

Re: Problems using API (Switch)

Posted: April 15th, 2012, 3:51 pm
by dogzipp
Also, another thing I noticed using the API.

I am sending files using the Addurl option. I am also sending the category. But for some reasons, if you're using wildcards on Config->Categories, they are ignored when using the API. Only an exact match will do.

For example, if I send two files, one with category Movies > HD, and another TV > HD, if I have categories "Movies*" and "TV*" they will be ignored, and the files are put on "default".

If I have an exact match (Movies > HD and TV > HD) it works perfectly.

Can you double check that wildcards should work through API addurl?

Thanks a lot for all the patience with my reports ;-)

Re: Problems using API (Switch)

Posted: April 15th, 2012, 3:57 pm
by shypike
I think you misunderstand the purpose of category in the API.
You're supposed to send an actual category as defined in SABnzbd.
The matching column in Config->Categories is used to match to categories
coming from (some) indexers.

Re: Problems using API (Switch)

Posted: April 15th, 2012, 4:06 pm
by dogzipp
I think perhps you misundertood my problem. I am the indexer. I am sending the Category to my users.

For example one of my users downloads files from TV > Sports, TV > HD, and TV > SD.

He doesn't want to create 3 different categories in SABnzbd. He creates one that says "TV*"

After all, Config->Categories says: "Wildcards are supported."

Right now if I am sending a file through the API, the Wildcard is being ignored. Unless user has TV > Sports, TV > HD and TV > SD define as three separate categories, the pushed file will be put in "default".

I mean, that's the purpose of using wilcards on Config->Categories, right? So you could group all your "TV" and "MOVIES" no matter what the subcategory is?

Re: Problems using API (Switch)

Posted: April 16th, 2012, 6:19 am
by shypike
The API supports user defined categories.
User-defined categories can be mapped to categories as defined by indexers.
I understand that you are trying to send your own indexer categories to SABnzbd,
but that's not what the API calls were designed for.
They were created to create an alternative user interface (like the many iPhone and Android apps do).
They query the user category list and create a pick list based on that.
I'm not saying your request is not useful, but it's currently not implemented.
So this is not a problem report but you're asking for additional functionality.
I'll see if that can be accommodated somehow.

Re: Problems using API (Switch)

Posted: April 16th, 2012, 1:54 pm
by shypike
I can add an "xcat" parameter to the calls "addlocalfile" and "addfile".
The xcat parameter will be mapped to a category using the method used for indexer mapping.

Re: Problems using API (Switch)

Posted: April 16th, 2012, 9:23 pm
by dogzipp
Great I cant wait to test the new funtionality. Because several users are asking (complaining) that their downloads are not being correctly categorized, even tough they are using wildcards. The xcat would result in much less headaches for both my users and me. I can just tell them if they want it to work with wildcards, they should upgrade to 7.0

Thank you.

Re: Problems using API (Switch)

Posted: April 17th, 2012, 5:41 am
by shypike
As Beta3 is about to be released, it will be in Beta4.

Re: Problems using API (Switch)

Posted: April 17th, 2012, 2:15 pm
by dogzipp
Shypike, please make it so that xcat can also be repeated for uploading multiple NZBs with different categories.

Re: Problems using API (Switch)

Posted: April 17th, 2012, 2:22 pm
by shypike
The calls (addfile, addlocalfile) which support xcat don't allow multiple files to be uploaded.
For the other calls (addid and addurl) which do allow multiple NZBs, xcat makes no sense.

Re: Problems using API (Switch)

Posted: April 17th, 2012, 4:30 pm
by dogzipp
I actually believe multiple xcats makes perfect sense... A user might have 3 files. One Movies, one TV HD and one TV SD. If I am adding all three on the same HTTP request, what's the point of them all ending up in the same category). The User might have two categories: TV*, and Movies.

Re: Problems using API (Switch)

Posted: April 17th, 2012, 11:58 pm
by shypike
Have you tried uploading multiple files?