From 63324def62454c8dea3967a34166081873e1dd20 Mon Sep 17 00:00:00 2001 From: Josh Patra Date: Tue, 3 Feb 2026 17:03:04 -0500 Subject: [PATCH] Fix Jellyfin BadRequest errors when fetching playlist items - Add UserId parameter to playlist items API call (required by Jellyfin) - Auto-fetch first user if no user ID configured - Simplify Fields parameter to only request Path - This fixes the 400 BadRequest errors when loading Jellyfin playlists tab --- allstarr/Controllers/AdminController.cs | 31 ++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/allstarr/Controllers/AdminController.cs b/allstarr/Controllers/AdminController.cs index 16a2147..f4344c6 100644 --- a/allstarr/Controllers/AdminController.cs +++ b/allstarr/Controllers/AdminController.cs @@ -826,7 +826,36 @@ public class AdminController : ControllerBase { try { - var url = $"{_jellyfinSettings.Url}/Playlists/{playlistId}/Items?Fields=ProviderIds,Path,MediaSources"; + // Jellyfin requires a UserId to fetch playlist items + // We'll use the first available user if not specified + var userId = _jellyfinSettings.UserId; + + // If no user configured, try to get the first user + if (string.IsNullOrEmpty(userId)) + { + var usersResponse = await _jellyfinHttpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get, $"{_jellyfinSettings.Url}/Users") + { + Headers = { { "X-Emby-Authorization", GetJellyfinAuthHeader() } } + }); + + if (usersResponse.IsSuccessStatusCode) + { + var usersJson = await usersResponse.Content.ReadAsStringAsync(); + using var usersDoc = JsonDocument.Parse(usersJson); + if (usersDoc.RootElement.GetArrayLength() > 0) + { + userId = usersDoc.RootElement[0].GetProperty("Id").GetString(); + } + } + } + + if (string.IsNullOrEmpty(userId)) + { + _logger.LogWarning("No user ID available to fetch playlist items for {PlaylistId}", playlistId); + return (0, 0, 0); + } + + var url = $"{_jellyfinSettings.Url}/Playlists/{playlistId}/Items?UserId={userId}&Fields=Path"; var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Add("X-Emby-Authorization", GetJellyfinAuthHeader());