Manual import of episodes using script

Sonarr version (exact version): 4.0.0.748
Mono version (if Sonarr is not running on Windows):
OS: Windows 10
Debug logs:
Description of issue: the manual import script I was using with version 3 is not working with version 4

The v3 powershell script uses this:
$URL = ‘http://localhost:8989/api/command
$JSON = ‘{“name”: “DownloadedEpisodesScan”, “path”: "’ + $path.replace(’\’,’\\’) + ‘", “importMode”: “Move”}’
Invoke-RestMethod -Uri $URL -Method Post -Body $JSON -Headers @{“X-Api-Key” = $apikey}

$path is the full path to a folder containing a TV episode file

I changed the URL to http://localhost:8989/api/v3/command
but I get this error:

Invoke-RestMethod : The remote server returned an error: (415) Unsupported Media Type.

I guess the API has changed but I’m not getting enough info from the API wiki page to figure out what needs to be changed.

The endpoint changed with V4. Here is an example of the manual scan trigger for a series that I got working…

curl -X POST http://192.168.1.50:8989/api/v3/command --header "X-Api-Key:XXXXXXXXXXX" -H 'Content-Type: application/json' -d '{"name":"RescanSeries","seriesId":'$serid'}'

I think it had some issues with white space in the JSON section when I was working on it so try removing whitespace in yours and see what happens. Been a few weeks since I worked on it so I don’t exactly remember.

EDIT : I forgot that I also had to declare the Content-Type as JSON to get it to work. Try adapting the example above as it is working with the “command” API endpoint.

Edit 2 : I think the issue is with the Content-Type. This is the Powershell Documentation for the Method you are using.

-ContentType

Default value is None
Accepts pipeline input False
Specifies the content type of the web request.

If this parameter is omitted and the request method is POST, Invoke-RestMethod sets the content type to application/x-www-form-urlencoded. Otherwise, the content type is not specified in the call.

adding -contentType ‘application/json’ to the Invoke-RestMethod command did the trick

I did not have to change the DownloadedEpisodesScan command

Thanks for the help.

The documentation is not good in this area so I ended up using tcpdump to capture and decode the packets on Linux and looked at the HTML coming off a browser to see the refresh series trigger coming into Sonarr. That is where I spotted the content-type as part of the API request.

The examples do include Content-Type: application/json - Sonarr API Docs.

Now that I go back and look at it I see it is there (now that I know what I am looking for) but to be honest, the way that it is documented I didn’t know what I was looking at. Probably more of a me problem but a simple curl example would be most useful or show us the request that was sent and not just the response in the HTML tool. Transitioning to requiring content-type declaration could have also been pointed out with an asterisk even so it is more obvious.

Click Try it out, change the json to whatever or leave as is, click Execute, get curl example.

Oh great… thanks! I had no idea that’s how that page worked. Much easier than the hoops I jumped through.

It still would be nice if the need for the contentType declaration was explicitly specified.

I have another script that does calendar gets where I was able to figure out that I needed to add includeSeries true to my command because includeSeries was listed in the calendar parameters.

I seem to remember that the old wiki (version 2?) included documentation for all the commands available through the command API. I don’t see any of that in the current API docs.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.