From 4071f6d650baaa232896aba88888b13d27e88459 Mon Sep 17 00:00:00 2001 From: Josh Patra Date: Wed, 4 Feb 2026 23:40:13 -0500 Subject: [PATCH] Fix authentication issue in UpdateSpotifyPlaylistCounts - Added UserId parameter to playlist items request to avoid 401 Unauthorized - Fixed JsonElement casting issue that was causing InvalidCastException - This should resolve both the authentication error and the track count update Now Spotify playlists should show correct track counts without authentication errors. --- allstarr/Controllers/JellyfinController.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/allstarr/Controllers/JellyfinController.cs b/allstarr/Controllers/JellyfinController.cs index 4b8c7f1..4b540c1 100644 --- a/allstarr/Controllers/JellyfinController.cs +++ b/allstarr/Controllers/JellyfinController.cs @@ -2812,14 +2812,24 @@ public class JellyfinController : ControllerBase } // Only fetch from Jellyfin if we didn't get count from file cache - if (!itemDict.ContainsKey("ChildCount") || (int)itemDict["ChildCount"]! == 0) + if (!itemDict.ContainsKey("ChildCount") || + (itemDict["ChildCount"] is JsonElement childCountElement && childCountElement.GetInt32() == 0) || + (itemDict["ChildCount"] is int childCountInt && childCountInt == 0)) { // Get local tracks count from Jellyfin var localTracksCount = 0; try { + // Include UserId parameter to avoid 401 Unauthorized + var userId = _settings.UserId; + var playlistItemsUrl = $"Playlists/{playlistId}/Items"; + if (!string.IsNullOrEmpty(userId)) + { + playlistItemsUrl += $"?UserId={userId}"; + } + var (localTracksResponse, _) = await _proxyService.GetJsonAsync( - $"Playlists/{playlistId}/Items", + playlistItemsUrl, null, Request.Headers);