How to fetch complete artist discography data with ISRC codes using Spotify Web API

Need Help Getting ISRC Data from Spotify API

Hey everyone! I’m trying to build something that pulls all the music data for a specific artist from Spotify’s API. I want to get everything like album info, song details, and most importantly the ISRC numbers for each track.

I managed to write some code that gets basic stuff like album names, song titles, how long each track is, and Spotify URLs. But I can’t figure out how to also grab the ISRC codes. When I test a single song request manually, I can see the ISRC in the response, but my automated script doesn’t pick it up.

What I’m trying to collect:

  • Album info (title, release date, type)
  • Song info (name, length, track position)
  • ISRC codes when they exist
  • Any other useful metadata

Has anyone done something like this before? I’d really appreciate any tips on how to modify my approach to include ISRC data.

import requests
import json
import os
import pandas as pd

# API credentials
auth_token = 'your_token_here'

# Spotify endpoints
api_base = "https://api.spotify.com/v1/artists/1A2B3C4D5E6F7G8H9I0J/albums"
request_headers = {
    "Authorization": f"Bearer {auth_token}"
}

# Get all albums for artist
def fetch_artist_albums(musician_id):
    album_list = []
    endpoint = api_base.format(musician_id)
    
    while endpoint:
        api_response = requests.get(endpoint, headers=request_headers)
        response_data = api_response.json()
        
        album_list.extend(response_data.get('items', []))
        endpoint = response_data.get('next')
    
    return album_list

# Get all songs from an album
def fetch_album_songs(release_id):
    song_list = []
    endpoint = f"https://api.spotify.com/v1/albums/{release_id}/tracks"
    
    while endpoint:
        api_response = requests.get(endpoint, headers=request_headers)
        response_data = api_response.json()
        
        song_list.extend(response_data.get('items', []))
        endpoint = response_data.get('next')
    
    return song_list

# Main execution
musician_id = "1A2B3C4D5E6F7G8H9I0J"
album_collection = fetch_artist_albums(musician_id)

# Process all songs
complete_tracklist = []
for release in album_collection:
    release_tracks = fetch_album_songs(release['id'])
    for song in release_tracks:
        song['release'] = release
    complete_tracklist.extend(release_tracks)

# Structure final output
final_output = []
for release in album_collection:
    release_info = {
        "release": release,
        "songs": []
    }
    for song in complete_tracklist:
        if song['release']['id'] == release['id']:
            release_info['songs'].append(song)
    
    final_output.append(release_info)

# Save to desktop
desktop_file = os.path.join(os.path.expanduser("~"), "Desktop", "artist_data.json")

with open(desktop_file, 'w', encoding='utf-8') as file:
    json.dump(final_output, file, ensure_ascii=False, indent=4)

print(f"Data saved to: {desktop_file}")

The code runs fine and creates the files, but I’m missing the ISRC information. Any ideas on what I might be doing wrong?

Been wrestling with this exact issue for months on a similar project. The problem is you’re grabbing track IDs from the albums endpoint but never actually fetching the full track objects where ISRC lives. What worked for me was a two-stage approach: collect all track IDs like you’re doing, then batch them and hit the tracks endpoint. But here’s what nobody mentions - Spotify’s ISRC data is inconsistent across markets. I found way better coverage by cycling through multiple market parameters (US, GB, DE) for the same tracks. Sometimes a track missing ISRC in one market will have it in another. Also watch out for compilation albums and features - those tracks often belong to different artists and might have different ISRC availability. Your current code should handle this fine, but the data inconsistency can be frustrating when you’re expecting complete coverage.

Spotify’s albums endpoint only gives you simplified track objects - no external identifiers included. You’re getting previews, not the full data. For ISRC codes, you need complete track objects using individual track IDs.

Here’s the catch: that means separate API calls for each track, which gets expensive quick. Hit the same wall building something similar last year.

Don’t call tracks one by one. Use the tracks endpoint with multiple IDs instead: https://api.spotify.com/v1/tracks?ids=track_id1,track_id2,track_id3. You can batch up to 50 track IDs per request - cuts your API calls way down.

Heads up though - not every track has ISRC codes. Older releases and some indie stuff won’t have them. Make sure your code handles missing or empty external_ids. Also throw in exponential backoff for rate limiting since you’ll be hammering their API way more than before.

Yeah, hit this same problem. You’re missing the market parameter - add ?market=US to your requests for better ISRC availability. Also try additional_types=track when fetching albums, Spotify sometimes gives more complete data that way. Your code’s doing double work though - you’re looping twice when you could build everything in one pass.

Your code’s hitting the albums endpoint, but that doesn’t return ISRC codes. You need to call the tracks endpoint individually for each song to get the external_ids field with the ISRC.

Add this function:

def get_track_details(track_id):
    endpoint = f"https://api.spotify.com/v1/tracks/{track_id}"
    response = requests.get(endpoint, headers=request_headers)
    return response.json()

Then update your loop to call this for each track and pull the ISRC from track_details['external_ids']['isrc']. Heads up - this’ll blow up your API calls since you need one request per track instead of per album. Not every track has an ISRC either, so handle missing fields. I’ve scraped similar data and rate limiting becomes a pain with this method. Throw in some delays between requests.