Just Tech Me At
Imagine building your own Spotify playlists with just a few lines of code! By combining the power of JSON with Spotify's API, you can move beyond manual clicks and unlock a smarter, faster way to organize your music.
Before touching the Spotify API, you’ll need the right tools installed:
You need Spotify track URIs before you can upload them to a playlist. Options:
URIs look like this: spotify:track:4iV5W9uYEdYUVa79Axb7Rh.
Organize your URIs into a CSV or Excel sheet. For example:
track_uri
spotify:track:4iV5W9uYEdYUVa79Axb7Rh
spotify:track:1301WleyT98MSxVHPZCA6M
Later, your script can read this file and push all tracks at once.
Send a POST request to /v1/users/{user_id}/playlists. Example:
import requests, json
user_id = "your_user_id"
access_token = "your_access_token"
url = f"https://api.spotify.com/v1/users/{user_id}/playlists"
headers = {"Authorization": f"Bearer {access_token}", "Content-Type": "application/json"}
payload = {"name": "My Python Playlist","description": "Created with Python","public": False}
resp = requests.post(url, headers=headers, data=json.dumps(payload))
print(resp.json())
With your playlist ID and spreadsheet of URIs, send them in batches of 100.
playlist_id = "your_playlist_id"
track_uris = ["spotify:track:4iV5W9uYEdYUVa79Axb7Rh","spotify:track:1301WleyT98MSxVHPZCA6M"]
url = f"https://api.spotify.com/v1/playlists/{playlist_id}/tracks"
headers = {"Authorization": f"Bearer {access_token}", "Content-Type": "application/json"}
payload = {"uris": track_uris}
resp = requests.post(url, headers=headers, data=json.dumps(payload))
print(resp.json())
Note: Spotify lets you upload max 100 URIs per request. Loop over your CSV in chunks.
Here's a single script that creates a playlist and uploads URIs from your spreadsheet:
import requests, json, csv
ACCESS_TOKEN = "your_access_token"
USER_ID = "your_user_id"
# Load URIs from CSV
with open("tracks.csv") as f:
reader = csv.DictReader(f)
track_uris = [row["track_uri"] for row in reader]
headers = {"Authorization": f"Bearer {ACCESS_TOKEN}","Content-Type": "application/json"}
# Create playlist
create_url = f"https://api.spotify.com/v1/users/{USER_ID}/playlists"
create_payload = {"name": "Python Playlist","description": "Imported from CSV","public": False}
playlist_id = requests.post(create_url, headers=headers, data=json.dumps(create_payload)).json()["id"]
# Add tracks in chunks of 100
add_url = f"https://api.spotify.com/v1/playlists/{playlist_id}/tracks"
for i in range(0, len(track_uris), 100):
chunk = {"uris": track_uris[i:i+100]}
requests.post(add_url, headers=headers, data=json.dumps(chunk))
print("Playlist created and tracks uploaded!")
Spotify lets you request your account data (including listening history):
This is the "bulk history log" method you mentioned - useful for extracting long-term listening history.
If you're comfortable with APIs, you can pull history directly:
GET /v1/me/player/recently-played
(requires an access token).
Once you see how JSON can automate your Spotify experience, you'll realize it's only the beginning. Explore other cool ways to use JSON-from managing data to powering apps-and let your creativity take the lead.