Automated Spotify Playlist Queueing and Sorting by Popularity - n8n Workflow

Use this powerful n8n workflow to automate Spotify playlist management. Fetch tracks, sort them by popularity using a custom n8n node, and queue them for perfect playback order.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Spotify power users who want dynamically sorted playlists.
Users looking for advanced examples of how to combine Spotify actions with custom JavaScript logic in n8n.
n8n automation specialists interested in custom data manipulation within an n8n workflow.
Anyone needing robust n8n templates for music management.

Overview

This solution provides a sophisticated way to manage your Spotify listening experience. Many users struggle with playlist organization, especially when trying to create dynamic listening queues based on track popularity. This particular n8n workflow solves this by fetching all user playlists and allowing you to select one to process. The unique value is provided by a custom n8n node that pulls essential track details, including the popularity score, and then sorts the entire list of songs from least popular to most popular. Finally, the sorted list is fed into a loop that adds each track to your current Spotify queue. This level of control demonstrates the flexibility available when building complex n8n automation systems, offering more than standard n8n templates.

How it Works

This robust n8n workflow begins with a simple manual n8n trigger, initiating the process when executed.


  1. Start: The When clicking ‘Execute workflow’ n8n trigger fires the automation.

  2. Get Playlists: The first Spotify n8n node fetches all available playlists associated with the connected user account.

  3. Clean Data: The Clean & Deduplicate Code n8n node processes the playlist list, extracting relevant identifiers (like URI and name) and removing duplicates, preparing the data for the next step.

  4. Select Playlist Tracks: A subsequent Spotify n8n node retrieves all tracks contained within the selected playlist.

  5. Sort by Popularity: The critical Playlist reorganizer Code n8n node extracts specific track metadata, removes duplicates based on track ID, and then sorts the remaining tracks based on their popularity score (lowest score first). This custom n8n node is the engine of the sorting logic.

  6. Queue Tracks: The Loop Over Items n8n node splits the reorganized list into individual items, iterating over the sorted tracks one by one.

  7. Final Action: For each item, the final Spotify n8n node (Add a song to a queue) uses the track ID to add the song to the currently active Spotify queue, showcasing an effective use of the Spotify n8n node.

Installation Guide

To use this powerful n8n workflow, follow these steps:


  1. Import: Copy the provided JSON code and import it directly into your n8n instance via the Workflows section (New -> Import from JSON).

  2. Credentials: You must configure the necessary credentials for the Spotify n8n node:

Click on any Spotify n8n node (e.g., Get a user's playlists).
Set up a new OAuth2 credential for Spotify. Ensure the credential grants the required scopes to read user playlists (playlist-read-private) and modify the playback queue (user-modify-playback-state).

  1. Setup Trigger: The n8n workflow uses a manual n8n trigger (When clicking ‘Execute workflow’). It is ready to run immediately after credential setup.

  2. Execution: Ensure you have an active Spotify session (a device playing music or active) to allow the queueing action to work correctly. Click 'Execute Workflow' or activate the n8n workflow and run it once.

Node Details

When clicking ‘Execute workflow’ (Manual Trigger n8n node): Serves as the initial n8n trigger to manually start the automation process.
Get a user's playlists (Spotify n8n node): Fetches all user playlists. Configuration uses returnAll: true to ensure no playlists are missed.
Clean & Deduplicate (Code n8n node): Cleans the input data, extracting essential playlist fields (name, uri) and deduplicating entries using custom JavaScript code. This enhances the reliability of the n8n workflow.
Get a playlist's tracks by URI or ID (Spotify n8n node): Dynamically retrieves all tracks from the playlist identified in the previous step.
Playlist reorganizer (Code n8n node): The core logic. This custom n8n node processes track items, extracts popularity data, handles deduplication, and sorts the entire track list based on popularity (ascending order).
Loop Over Items (Split In Batches n8n node): Iterates over the reorganized list of tracks, ensuring each song is processed sequentially.


  • Add a song to a queue (Spotify n8n node): The final action, using the track ID derived from the sorted list (=spotify:track:{{ $json.id }}) to add the song to the Spotify queue.

Related n8n Workflows

Free

Nodes: 5 Nodes
Updated: December 26 2025
View all
Created by

Former data engineer, now full-time automation creator. I design systems that create, talk, and think

Featured*