a little API help?

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
the block
Newbie
Newbie
Posts: 25
Joined: April 5th, 2012, 7:59 am

a little API help?

Post 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! :)

User avatar
sander
Release Testers
Release Testers
Posts: 7416
Joined: January 22nd, 2008, 2:22 pm

Re: a little API help?

Post 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

the block
Newbie
Newbie
Posts: 25
Joined: April 5th, 2012, 7:59 am

Re: a little API help?

Post 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

User avatar
safihre
Administrator
Administrator
Posts: 4228
Joined: April 30th, 2015, 7:35 am
Location: Switzerland
Contact:

Re: a little API help?

Post 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
If you like our support, check our special newsserver deal or donate at: https://sabnzbd.org/donate

the block
Newbie
Newbie
Posts: 25
Joined: April 5th, 2012, 7:59 am

Re: a little API help?

Post 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.

User avatar
jcfp
Release Testers
Release Testers
Posts: 895
Joined: February 7th, 2008, 12:45 pm

Re: a little API help?

Post 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.

User avatar
safihre
Administrator
Administrator
Posts: 4228
Joined: April 30th, 2015, 7:35 am
Location: Switzerland
Contact:

Re: a little API help?

Post by safihre »

You can also use the History Retention setting in Config Switches, although it applies for the whole history and not 1 category.
If you like our support, check our special newsserver deal or donate at: https://sabnzbd.org/donate

Post Reply