How to Back-Fill Historical Spotify Data
This guide will walk you through the process of importing your extended Spotify listening history into the Smart Playlist Builder. By following these steps, you can back-fill your database with older play data, ensuring your analytics and playlists reflect your complete listening journey.
1. Request Extended History from Spotify
- Log in to your Spotify account on the Spotify website.
- Navigate to the Privacy Settings or Data Download section.
- Request a download of your extended listening history data in JSON format.
- Wait for Spotify to prepare and send you the data files via email or download link.
2. Import JSON Files into Google Sheets
- Create a new Google Sheet.
- Install and open the JSON import add-on.
- Use the add-on to import all Spotify JSON history files.
- Important: Do NOT select “merge data from all files together.” Import each file so that all rows append into a single sheet.
- Add a filter to the header row and filter the column named
spotify_episode_uri
(if present) to exclude blanks, then delete all visible rows.
- This column looks like:
spotify:episode:6MQeLMh23l9D0piX6CUmaVm
. These are podcasts. After deleting them, only music tracks should remain.
- Delete all columns except the following (renaming is not required):
ts
master_metadata_track_name
master_metadata_album_artist_name
master_metadata_album_album_name
spotify_track_uri
- Find & Replace to extract the Spotify Track ID:
- Find:
spotify:track:
- Replace with: (leave blank)
- This converts values like
spotify:track:4j0dhzx1BiPKCkMPxyj9eO
→ 4j0dhzx1BiPKCkMPxyj9eO
.
- Remove duplicates so you only import clean rows:
- Select the entire table (all remaining columns).
- Go to Data → Data cleanup → Remove duplicates.
- Tick My data has header row.
- Click Deselect all, then select only
ts
and spotify_track_uri
.
- Run Remove duplicates.
- Download the sheet as a CSV file (File → Download → Comma-separated values).
3. Import the Cleaned CSV into the Database
You will import into the existing spotify_play_history
table. Map your CSV columns to the DB columns as follows:
CSV Column | DB Column |
ts | played_at |
master_metadata_track_name | track_name |
master_metadata_album_artist_name | artist_name |
master_metadata_album_album_name | album_name |
spotify_track_uri (now just the ID) | track_id |
Tip (TablePlus on macOS): Right‑click the table → Import → From CSV, map columns as above, and run. Other tools have similar CSV import flows.
4. Run the Backlog Action to Enrich Missing Fields
- Open GitHub and go to the repository’s Actions tab.
- Find the workflow named zzzzzz_999999_Backfill Spotify Play History (manual dispatch).
- Run the workflow. This job fills in missing fields in
spotify_play_history
(e.g., artist_id
, album_id
, album_type
, and duration_ms
) in small batches.
- Note: It may take a while depending on volume and API rate‑limits. You can re‑run as needed; it is idempotent.
Heads‑up: If you run playlist builds before backfill completes, any rows with blank fields will be skipped by the build logic.