[Solved] API Command Help downloadedepisodesscan

Sonarr version (exact version) : 3.0.3.698
Mono version (if Sonarr is not running on Windows) :
OS : server 2019
Debug logs : can provide if needed
Description of issue : Having issues with downloadedepisodesscan and getting errors with PowerShell, just wondering what im doing wrong as I followed the wiki or am I blind and missed something?

Script:

$url = "http://localhost:8989/api/command"
$json = '{"name": "downloadedepisodesscan","path": "C:\Users\Administrator\Downloads\incoming" , "importMode":"Move"}' 

Write-Host "Publishing update $version ($branch) to: $url"
Invoke-RestMethod -Uri $url -Method Post -Body $json -Headers @{"X-Api-Key"="15abbfb5590643adb4ffcf9ae5dd44"}

Output:

PS C:\Users\Administrator> C:\Users\Administrator\Documents\Sonarr_Quick_Import.ps1
Publishing update  () to: http://localhost:8989/api/command
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At C:\Users\Administrator\Documents\Sonarr_Quick_Import.ps1:5 char:1
+ Invoke-RestMethod -Uri $url -Method Post -Body $json -Headers @{"X-Ap ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Logs:

API Error: BadRequest: Invalid request body. Bad JSON escape sequence: \U. Path 'path', line 1, position 47. (Json snippet 'sscan","path": "C:\U<--error-->sers\Administrator\D')

Edit #2:

Got it working when fixing the path-

$url = "http://localhost:8989/api/command"
$json = '{"name": "downloadedepisodesscan","path": "C:\\Users\\Administrator\\Downloads\\incoming","importMode":"Move"}' 

Write-Host "Publishing update $version ($branch) to: $url"
Invoke-RestMethod -Uri $url -Method Post -Body $json -Headers @{"X-Api-Key"="15abbfb5590643adb4ffcf9ae5dd44"}

Receive the below, but nothing happens-

PS C:\Users\Administrator> C:\Users\Administrator\Documents\Sonarr_Quick_Import.ps1
Publishing update  () to: http://localhost:8989/api/command


name                : DownloadedEpisodesScan
body                : @{path=C:\Users\Administrator\Downloads\incoming; importMode=move; sendUpdatesToClient=False; updateScheduledTask=True; completionMessage=Completed; requiresDiskAccess=False; isExclusive=False; 
                      name=DownloadedEpisodesScan; trigger=manual; suppressMessages=False}
priority            : normal
status              : queued
queued              : 2020-02-19T10:33:41.0738801Z
trigger             : manual
state               : queued
manual              : True
startedOn           : 2020-02-19T10:33:41.0738801Z
sendUpdatesToClient : False
updateScheduledTask : True
id                  : 41972

Debug -

20-2-19 21:40:56.1|Debug|Parser|Parsing string 'incoming'
20-2-19 21:40:56.1|Debug|Parser|Unable to parse incoming
20-2-19 21:40:56.1|Debug|DownloadedEpisodesImportService|Unknown Series incoming
20-2-19 21:40:56.1|Debug|DownloadedEpisodesCommandService|Failed to import

You need to tell Sonarr the file/folder in that folder to scan.

Specifically: A folder specified by the path variable is assumed to be a single download (job) and the folder name should be the release name.

Thanks Markus -In that ā€˜incomingā€™ folder there was a single file.

How does the ā€œQuick IMportā€ function work or is there another API that is called for that? That seems to pick everything up in a single folder and import as needed.

It works the same way and expects a ā€œjobā€ folder.

Sorry to ask a stupid question - but what do I need to change or add to the folder or api?

Path is a file or a folder, in this case youā€™d use the full path to the file you want Sonarr to process.

And if i had multiple files in a single folder?

If the folder is for a specific download (like a season pack or multi-episode pack), then that folder if itā€™s the ā€œincomingā€ folder then you would want to call it once for each file.

Ok makes sense, so I tried calling that folder with 2 episodes in it for the same show and season and get the same result as above, do I have to call the specific episode file?

Think Iā€™m getting confused, as the quick import looks at that same folder regardless of show and finds everything and does the import. Sorry.

Unless the folder is a folder named after the episode (or in someway parseable to a series and episodes) you should be calling the folder.

Quick import should behave the exact same way as it calls the same command.

Thanks Markus :slight_smile:

Iā€™ve tested it with what you mentioned, script from above runs, with the below output and debug and the incoming folder has 2 different files for different shows in it, as well as folders with the tv show name as the folderā€¦Iā€™ve either done something wrong or misunderstood what you meant by calling the folder. As soon as I do quick import on the same folder, it picks up all 4 files straight.

PS C:\Users\Administrator\Documents> C:\Users\Administrator\Documents\Sonarr_Quick_Import.ps1
Publishing update  () to: http://localhost:8989/api/command


name                : DownloadedEpisodesScan
body                : @{path=C:\Users\Administrator\Downloads\incoming; importMode=move; sendUpdatesToClient=False; updateScheduledTask=True; completionMessage=Completed; requiresDiskAccess=False; isExclusive=False; 
                      name=DownloadedEpisodesScan; trigger=manual; suppressMessages=False}
priority            : normal
status              : queued
queued              : 2020-02-20T09:06:14.2119296Z
trigger             : manual
state               : queued
manual              : True
startedOn           : 2020-02-20T09:06:14.2119296Z
sendUpdatesToClient : False
updateScheduledTask : True
id                  : 44184
20-2-19 21:40:48.8|Debug|Api|[GET] /api/v3/health: 200.OK (0 ms)
20-2-19 21:40:48.8|Debug|Api|[GET] /api/v3/health: 200.OK (0 ms)
20-2-19 21:40:56.1|Debug|Api|[POST] /api/command: 201.Created (0 ms)
20-2-19 21:40:56.1|Debug|Parser|Parsing string 'incoming'
20-2-19 21:40:56.1|Debug|Parser|Unable to parse incoming
20-2-19 21:40:56.1|Debug|DownloadedEpisodesImportService|Unknown Series incoming
20-2-19 21:40:56.1|Debug|DownloadedEpisodesCommandService|Failed to import

Only call the folder if itā€™s paresable, something like Series.Title.S01E01.HDTV-RlsGrp, but if itā€™s working for quick import which calls the exact same command through the exact same API then check how itā€™s calling the API and mimic it.

Sorry new to all this - how do I check how itā€™s calling folder?

Thanks for you patience and help!

Dev tools in your browser, looking at the network tab.

Thanks Markus! Appreciate all the help!

1 Like

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