Page 1 of 1

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

Posted: January 10th, 2023, 8:09 pm
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)

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

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

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

Posted: January 11th, 2023, 10:19 pm
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) :-\

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

Posted: January 11th, 2023, 10:33 pm
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

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

Posted: January 12th, 2023, 3:09 pm
by safihre
Great 👍