Page 1 of 1

a little API help?

Posted: November 30th, 2020, 12:06 pm
by the block
I've been wanting to put together an API call that I could throw in a post-processing script and would delete all history for the "movies" category. I came up with the following API call hoping it would do just that, however when I tested it, it deleted ALL history by accident :D

So I guess I was kind of in the right ballpark, just not right enough :P

Would anyone mind taking a peak and tweaking it to how it should be written to ONLY delete history from the "movies" category?

http://localhost:port/sabnzbd/api?mode=history&category=movies&name=delete&value=all&apikey=MYAPIKEY

Thank you! :)

Re: a little API help?

Posted: November 30th, 2020, 12:19 pm
by sander
Two steps:

Get all NZO_IDs in category movies like this:
https://sabnzbd.org/wiki/advanced/api#history says
category optional Only return jobs in this category (Only 1.0.0+)


Then delete those NZO_IDs like this
https://sabnzbd.org/wiki/advanced/api#delete_history tells
api?mode=history&name=delete&value=NZO_ID_1,NZO_ID_2,NZO_ID_3

Re: a little API help?

Posted: November 30th, 2020, 12:53 pm
by the block
I'm having trouble identifying the NZO_ID's.. I tried running "api?mode=queue&start=START&limit=LIMIT&search=SEARCH" as that looks like it resulted in listing NZO_ID's in that big output on the wiki, so I ran it but nothing about NZO_ID's. Lists a bunch of other information instead.

I'm really very much a noob when it comes to API stuff. Are you able to give me a little more specific instructions on what I need to do to identify these NZO_ID's? Thanks

Re: a little API help?

Posted: December 1st, 2020, 3:25 am
by safihre
Before starting you should know that a job can't delete itself from history, or at least it will not be pretty.
Make sure you add &mode=json the output should be more structured.
The nzo_id is listed under queue > slots > 0 > nzo_id

Re: a little API help?

Posted: December 1st, 2020, 7:55 am
by the block
safihre wrote: December 1st, 2020, 3:25 am Before starting you should know that a job can't delete itself from history, or at least it will not be pretty.
Before I go further with this then, is there even a point in trying, or an alternative method I'm not utilizing (if I'm going about this the wrong way)? I would just like certain categories to not be retained in the history. If there's a different or better way to skin that cat, I'm all ears.

Re: a little API help?

Posted: December 3rd, 2020, 7:40 am
by jcfp
If you want to avoid the limitation safihre mentioned you could just as well run your script as a cronjob (or whatever scheduler option your os provides).

Removing a subset of completed jobs from the history through the api isn't a problem, the only "but" being that this specific subset cannot be done in a single call. You'll need your script to do two api calls: the first to get info on all completed jobs in the history; then, after selecting the ids of the ones that match your deletion criteria, a second call for the delete action.

Re: a little API help?

Posted: December 4th, 2020, 1:56 pm
by safihre
You can also use the History Retention setting in Config Switches, although it applies for the whole history and not 1 category.