[GH-ISSUE #771] Error 400 when trying to add a track to a playlist. #469

Closed
opened 2026-02-27 23:22:49 +03:00 by kerem · 2 comments
Owner

Originally created by @MarcoMorandin on GitHub (Jan 14, 2022).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/771

I am trying to add tracks into a my own playlist. When I execute the code I get this error:
HTTP Error for POST to https://api.spotify.com/v1/playlists/(playlistID)/tracks with Params: {'position': None} returned 400 due to Invalid track uri: spotify:track:3
I guess it sends only the first character of the id of the song (in this case is 3).
Here is my code:

`
import spotipy
from spotipy.oauth2 import SpotifyOAuth
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id="(client_id)",
client_secret="(client_secret)",
redirect_uri="http://localhost:8080",
scope="user-library-read playlist-modify-public"))

t = '(trackID)'
print(sp.playlist_add_items('(playlistID)', t))
`

Have you got some hint?
Thanks in advice.

Originally created by @MarcoMorandin on GitHub (Jan 14, 2022). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/771 I am trying to add tracks into a my own playlist. When I execute the code I get this error: `HTTP Error for POST to https://api.spotify.com/v1/playlists/(playlistID)/tracks with Params: {'position': None} returned 400 due to Invalid track uri: spotify:track:3` I guess it sends only the first character of the id of the song (in this case is 3). Here is my code: ` import spotipy from spotipy.oauth2 import SpotifyOAuth sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id="(client_id)", client_secret="(client_secret)", redirect_uri="http://localhost:8080", scope="user-library-read playlist-modify-public")) t = '(trackID)' print(sp.playlist_add_items('(playlistID)', t)) ` Have you got some hint? Thanks in advice.
kerem 2026-02-27 23:22:49 +03:00
Author
Owner

@stephanebruckert commented on GitHub (Jan 15, 2022):

You need to pass a list to playlist_add_items, so playlist_add_items(["spotify:track:3xxxxxx"])

<!-- gh-comment-id:1013695580 --> @stephanebruckert commented on GitHub (Jan 15, 2022): You need to pass a list to `playlist_add_items`, so `playlist_add_items(["spotify:track:3xxxxxx"])`
Author
Owner

@stephanebruckert commented on GitHub (Jan 15, 2022):

TODO: since this issue comes back a lot, let's allow passing a single spotify URI

<!-- gh-comment-id:1013695731 --> @stephanebruckert commented on GitHub (Jan 15, 2022): TODO: since this issue comes back a lot, let's allow passing a single spotify URI
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#469
No description provided.