API upload file (via direct POST/multi part form) returns invalid JSON on version 3.7.1

Report & discuss bugs found in 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
OldRustyKnight
Newbie
Newbie
Posts: 5
Joined: September 4th, 2020, 9:34 pm

API upload file (via direct POST/multi part form) returns invalid JSON on version 3.7.1

Post by OldRustyKnight »

When posting a file through the API (using multi part form), the JSON been returned is invalid (the upload works just fine)

The docs (wiki/configuration/3.7/api#addur) state it should return

Code: Select all

{
    "status": true,
    "nzo_ids": ["SABnzbd_nzo_kyt1f0"]
}
But it's returning

Code: Select all

{'status': True, 'nzo_ids': ['SABnzbd_nzo_vfglszd6']}
Pasting this into jsonformatter.curiousconcept, it reports two "fixes"

* Info: Replaced incorrect quotes.
* Info: Converted true to lowercase.

While "some" parses may fix this, I'm using Swift, which won't auto correct this - based on my limited testing, this seems to be the only response which uses single quotes (and true is incorrectly formatted)

(Apologies, I did a quick search, but could not find any other response which seemed to match this issue)
User avatar
safihre
Administrator
Administrator
Posts: 5523
Joined: April 30th, 2015, 7:35 am
Contact:

Re: API upload file (via direct POST/multi part form) returns invalid JSON on version 3.7.1

Post by safihre »

You need to add mode=json to your request, right you are using text mode.
If you like our support, check our special newsserver deal or donate at: https://sabnzbd.org/donate
OldRustyKnight
Newbie
Newbie
Posts: 5
Joined: September 4th, 2020, 9:34 pm

Re: API upload file (via direct POST/multi part form) returns invalid JSON on version 3.7.1

Post by OldRustyKnight »

safihre wrote: January 10th, 2023, 9:35 pm You need to add mode=json to your request, right you are using text mode.
It already is

Code: Select all

POST http://.../api?output=json
I updated from 2.3.9 where the API request was working to 3.7.1 which broke my unit tests

Also, shouldn't it be "output" not "mode", as "mode" would need to be "addfile" (but that's part of the form data in this case)

----------

Okay, after digging my way back through my code, I found that I did have "output" in my form data, just it was "json=output" instead of "output=json" - now I'm completely weird out over how it's worked for so long (since before 2.3.9) :-\
Last edited by OldRustyKnight on January 11th, 2023, 10:34 pm, edited 1 time in total.
OldRustyKnight
Newbie
Newbie
Posts: 5
Joined: September 4th, 2020, 9:34 pm

Re: API upload file (via direct POST/multi part form) returns invalid JSON on version 3.7.1

Post by OldRustyKnight »

I think I'd be happy to say that this is mostly a case of "idiot on the outside" with a side of "luck"

I've corrected my form data to include "output=json" correctly and it now seems to be working fine

Thanks
User avatar
safihre
Administrator
Administrator
Posts: 5523
Joined: April 30th, 2015, 7:35 am
Contact:

Re: API upload file (via direct POST/multi part form) returns invalid JSON on version 3.7.1

Post by safihre »

Great 👍
If you like our support, check our special newsserver deal or donate at: https://sabnzbd.org/donate
Post Reply