Sonarr/Sonarr · error · BadRequestException

seriesIds must be positive integers

Error message

seriesIds must be positive integers

What it means

Returned as HTTP 400 (BadRequestException) by GET /api/v5/rename/bulk when the seriesIds list contains any value less than or equal to zero. This guard runs after the empty-list check, so it only fires when the list is non-empty but includes a non-positive (invalid) id.

Source

Thrown at src/Sonarr.Api.V5/Episodes/RenameEpisodeController.cs:43

        {
            return TypedResults.Ok(_renameEpisodeFileService.GetRenamePreviews(seriesId, seasonNumber.Value).ToResource());
        }

        return TypedResults.Ok(_renameEpisodeFileService.GetRenamePreviews(seriesId).ToResource());
    }

    [HttpGet("bulk")]
    [Produces("application/json")]
    public Results<Ok<List<RenameEpisodeResource>>, BadRequest> GetEpisodes([FromQuery] List<int> seriesIds)
    {
        if (seriesIds is { Count: 0 })
        {
            throw new BadRequestException("seriesIds must be provided");
        }

        if (seriesIds.Any(seriesId => seriesId <= 0))
        {
            throw new BadRequestException("seriesIds must be positive integers");
        }

        return TypedResults.Ok(_renameEpisodeFileService.GetRenamePreviews(seriesIds).ToResource());
    }
}

View on GitHub (pinned to da2284d7ea)

Solutions

  1. Filter the seriesIds list to only positive integers before sending the request
  2. Investigate the source of the 0/-1 value and fix the upstream selection logic
  3. Add a client-side assertion that all ids are > 0

Example fix

// before
var qs = "?seriesIds=" + string.Join(",", rawSeriesIds);

// after — strip invalid ids
var validIds = rawSeriesIds.Where(id => id > 0).ToList();
if (!validIds.Any()) return;
var qs = "?seriesIds=" + string.Join(",", validIds);
Defensive patterns

Strategy: validation

Validate before calling

if (seriesIds.Any(id => id <= 0))
    throw new ArgumentException("All seriesIds must be positive integers");
// or filter them out: var safe = seriesIds.Where(id => id > 0).ToList();

Type guard

static bool AllPositive(IEnumerable<int> ids) => ids.All(id => id > 0);

Prevention

When it happens

Trigger: GET /api/v5/rename/bulk?seriesIds=5,0 or ?seriesIds=-1,2 — any list where at least one id is <= 0.

Common situations: A default/uninitialized sentinel value (0 or -1) leaks into the id list. A UI multi-select includes a placeholder row. A script fails to filter out invalid ids from upstream data.

Related errors


AI-assisted analysis of Sonarr/Sonarr@da2284d7ea (2026-08-13). Data as JSON: /api/errors/b621ab5ea58e46d2. Report an issue: GitHub.