Sonarr API suddenly stopped working

Sonarr version (exact version):
Mono version (if Sonarr is not running on Windows):
OS: Windows 7
Debug logs:

20-8-22 00:04:59.7|Trace|Http|Req: 529 [POST] /api/command?apikey=(removed)
20-8-22 00:04:59.7|Trace|Http|Res: 529 [POST] /api/command?apikey=(removed) 303.SeeOther (0 ms)
20-8-22 00:04:59.7|Debug|Api|[POST] /api/command?apikey=(removed) 303.SeeOther (0 ms)
20-8-22 00:04:59.7|Trace|Http|Req: 530 [GET] /api/command?apikey=(removed)
20-8-22 00:04:59.7|Trace|CommandQueueManager|Getting started commands
20-8-22 00:04:59.7|Trace|Http|Res: 530 [GET] /api/command?apikey=(removed) 200.OK (15 ms)
20-8-22 00:04:59.7|Debug|Api|[GET] /api/command?apikey=(removed) 200.OK (15 ms)

Description of issue:


I’m hoping someone can help me with an issue I’m having. I have a post-processing script that NZBGet runs when it finishes downloading a TV show. It does a variety of things, including cleaning up unwanted files, calling Handbrake to re-encode the show, and finally, it’s SUPPOSED to call Sonarr’s API to have Sonarr import the show (which then causes Sonarr to update Plex). For months (if not years), this was working absolutely beautifully, but for some reason it no longer works. The script itself works fine - it does the cleanup and re-encoding, and does attempt a call to Sonarr’s API. The problem is that the API isn’t doing anything. It’s supposed to add the episode to Sonarr’s database as well as move the file to the configured folder. It seems to be giving me a 303 See Other error.

The relevant section of the script is:

$url = $SonarrURL + “:” + $SonarrPort + “sonarr/api/command”
$json = @{“name”=“DownloadedEpisodesScan”;“path”="$FinalJobFullPath"} | ConvertTo-Json
Write-Host “Publishing update to: [$url]”
Write-Host $json
Invoke-RestMethod -Uri $url -Method Post -Body $json -Headers @{“X-Api-Key”="$SonarrAPIKey"}

When all that is put together, the URL is “http://media_server:8989/sonarr/api/command”. I have also tried it with just “http://media_server:8989/api/command” - it’s this second one that has been in place and working for many months.

The JSON it creates is something like:

“name”: “DownloadedEpisodesScan”,
“path”: “C:\ProgramData\NZBGet\complete\Thundercats.S01E02.The.Unholy.Alliance.DVDRip.XviD-DIMENSION”

No matter what I do, I cannot get it to understand that there’s a finished file sitting there for it to process. I have not changed the script in months, aside from today when I was trying to debug this issue. I haven’t changed the system in months. Sonarr said it was last updated March 13, which was the most recent version. I did try re-installing Sonarr overtop of the current install, and then having it do an update. That didn’t seem to help. I have rebooted the system twice, as well as just restarting Sonarr separately. Nothing I’ve done has helped.

Does anyone have any ideas?


Another strange thing is that when I added a new TV series tonight, it didn’t create the series folder. I thought that might have something to do with it, so I created the folder manually, and double checked that it matched what Sonarr had set as the series folder. That didn’t help. I tried adding another series, and it didn’t create that folder either. I didn’t see anything in the logs about WHY it didn’t create it, only a few mentions of the fact that the series folder didn’t exist. I thought maybe there was a permissions issue in Windows, but then again, Sonarr is able to read the manually-created series folder and rename files in it, so it does seem to have write access.

Are you using a URL Base in Sonarr? If so it needs to be part of the URL when you make requests to Sonarr’s API or they will be redirected and result in a GET request instead of a POST.

20-8-22 00:04:59.7|Trace|Http|Res: 529 [POST] /api/command?apikey=(removed) 303.SeeOther (0 ms) is the relevant portion.

Yeah, I had read a different thread somewhere on here that suggests the URL base, which is why I had tried the URL with and without “/sonarr”. Mine is set to “/media_server”, so as far as I know, the URL should be “http://media_server:8989/api/command”. That’s the one that has been working for months, up until yesterday. The only thing I can think of that happened out of the ordinary recently is that I accidentally kicked the plug out of the wall, and the computer shut down. I don’t see how that would cause this sort of issue, though.

I created another small script that lets me just run the API call for testing purposes:

$u = "http://media_server:8989/api/command"

$j = @{"name"="DownloadedEpisodesScan";"path"="C:\ProgramData\NZBGet\complete\ThunderCats.S02E01.Mumm-Ra.Lives.1.DVDRip.x264-[gd]-Chamele0n"} | ConvertTo-Json

#Invoke-WebRequest -Uri $u -Method post -Body $j

Invoke-RestMethod -Uri $u -Method Post -Body $j -Headers @{"X-Api-Key"="<snip>"}

This is a random episode I downloaded for testing purposes. The series folder exists, as does the path spelled out in the script. When I ran it, Powershell received this output:

name                : CheckForFinishedDownload
body                : @{sendUpdatesToClient=False; updateScheduledTask=True; completionMessage=Completed; name=CheckForFinishedDownload; lastExecutionTime=2020-08-22T18:16:17.3306538Z; 
priority            : low
status              : started
queued              : 2020-08-22T18:17:41.0304411Z
started             : 2020-08-22T18:17:41.0554426Z
trigger             : scheduled
state               : started
manual              : False
startedOn           : 2020-08-22T18:17:41.0304411Z
stateChangeTime     : 2020-08-22T18:17:41.0554426Z
sendUpdatesToClient : False
updateScheduledTask : True
lastExecutionTime   : 2020-08-22T18:16:17.3306538Z
id                  : 1797092

To me, that looks like a response from Sonarr, not an error from PowerShell. If that’s correct, this tells me that Sonarr is receiving the command - it’s just not doing anything with it.

I am still getting the 303 See Other error, which I understand means that it’s trying to direct me somewhere that doesn’t exist. The problem is that I can’t find any hint about where it’s trying to direct me, so I don’t even know where to look.

I’ve made a bit of progress here. I installed Sonarr v3.0.3.911 (it was probably time to update anyway). This didn’t fix the issue, but it looks like there’s been some additions to the logging that give me a hint:

20-8-24 14:18:45.4|Warn|ImportApprovedEpisodes|Couldn't import episode C:\ProgramData\NZBGet\complete\ThunderCats.S02E02.Mumm-Ra.Lives.2.DVDRip.x264-[gd]-Chamele0n\6a6cd12a13ad4e4fa709bd5012722ceb.mp4

[v3.0.3.911] System.UnauthorizedAccessException: Access to the path is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.__Error.WinIOError()
   at System.IO.File.InternalMove(String sourceFileName, String destFileName, Boolean checkHost)
   at NzbDrone.Common.Disk.DiskProviderBase.MoveFileInternal(String source, String destination) in M:\BuildAgent\work\63739567f01dbcc2\src\NzbDrone.Common\Disk\DiskProviderBase.cs:line 267
   at NzbDrone.Common.Disk.DiskProviderBase.MoveFile(String source, String destination, Boolean overwrite) in M:\BuildAgent\work\63739567f01dbcc2\src\NzbDrone.Common\Disk\DiskProviderBase.cs:line 254
   at NzbDrone.Common.Disk.DiskTransferService.TryMoveFileVerified(String sourcePath, String targetPath, Int64 originalSize) in M:\BuildAgent\work\63739567f01dbcc2\src\NzbDrone.Common\Disk\DiskTransferService.cs:line 431
   at NzbDrone.Common.Disk.DiskTransferService.TransferFile(String sourcePath, String targetPath, TransferMode mode, Boolean overwrite) in M:\BuildAgent\work\63739567f01dbcc2\src\NzbDrone.Common\Disk\DiskTransferService.cs:line 311
   at NzbDrone.Core.MediaFiles.EpisodeFileMovingService.TransferFile(EpisodeFile episodeFile, Series series, List`1 episodes, String destinationFilePath, TransferMode mode) in M:\BuildAgent\work\63739567f01dbcc2\src\NzbDrone.Core\MediaFiles\EpisodeFileMovingService.cs:line 116
   at NzbDrone.Core.MediaFiles.EpisodeFileMovingService.MoveEpisodeFile(EpisodeFile episodeFile, LocalEpisode localEpisode) in M:\BuildAgent\work\63739567f01dbcc2\src\NzbDrone.Core\MediaFiles\EpisodeFileMovingService.cs:line 77
   at NzbDrone.Core.MediaFiles.UpgradeMediaFileService.UpgradeEpisodeFile(EpisodeFile episodeFile, LocalEpisode localEpisode, Boolean copyOnly) in M:\BuildAgent\work\63739567f01dbcc2\src\NzbDrone.Core\MediaFiles\UpgradeMediaFileService.cs:line 77
   at NzbDrone.Core.MediaFiles.EpisodeImport.ImportApprovedEpisodes.Import(List`1 decisions, Boolean newDownload, DownloadClientItem downloadClientItem, ImportMode importMode) in M:\BuildAgent\work\63739567f01dbcc2\src\NzbDrone.Core\MediaFiles\EpisodeImport\ImportApprovedEpisodes.cs:line 111

20-8-24 14:18:45.4|Debug|DownloadedEpisodesCommandService|Failed to import

So basically, it looks like for some reason Sonarr doesn’t have access to the folder it’s trying to import to. Does anyone know what permissions it needs? I assume that since Sonarr is running as a service, it’s running under the SYSTEM user, which is set to Full Control. The other option would be that it’s running under the user it’s logged in as, which is part of the Administrators group, which also has full control. So if it already has full control, how can it not have access?

Wrt to “which user does it run as”: either it runs as a service or it doesn’t.
If it does: check the service (open services.msc for example) and confirm the user it’s running as.
If it doesn’t, sonarr runs as the currently logged-in user and is started by e.g. linking the executable in the Startup folder.

Can sonarrr access the source path as well?

What is the full location on the D:\ drive where it should put the file? Check the subfolders in case something funky happened with permissions inheritance.

No, it runs as Local Service, which gives it far less permissions by default.