diff --git a/allstarr/Services/Spotify/SpotifyTrackMatchingService.cs b/allstarr/Services/Spotify/SpotifyTrackMatchingService.cs index d44c992..542d239 100644 --- a/allstarr/Services/Spotify/SpotifyTrackMatchingService.cs +++ b/allstarr/Services/Spotify/SpotifyTrackMatchingService.cs @@ -3,6 +3,7 @@ using allstarr.Models.Settings; using allstarr.Models.Spotify; using allstarr.Services.Common; using allstarr.Services.Jellyfin; +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Options; using System.Text.Json; @@ -701,8 +702,15 @@ public class SpotifyTrackMatchingService : BackgroundService return; } + // Create authentication headers for background service call + var headers = new HeaderDictionary(); + if (!string.IsNullOrEmpty(jellyfinSettings.ApiKey)) + { + headers["X-Emby-Authorization"] = $"MediaBrowser Token=\"{jellyfinSettings.ApiKey}\""; + } + var playlistItemsUrl = $"Playlists/{jellyfinPlaylistId}/Items?UserId={userId}&Fields=MediaSources"; - var (existingTracksResponse, statusCode) = await proxyService.GetJsonAsync(playlistItemsUrl, null, null); + var (existingTracksResponse, statusCode) = await proxyService.GetJsonAsync(playlistItemsUrl, null, headers); if (statusCode != 200 || existingTracksResponse == null) {