daihovey
daihovey

Reputation: 3575

Spotify API Add to playlist

Is it possible to manipulate (add to) a Spotify playlist via server side functionality?

The web API seems limited to search (https://developer.spotify.com/technologies/web-api/) and the JavaScript API Reference which has the function seems limited to actually building an app inside Spotify itself...

Upvotes: 2

Views: 1278

Answers (2)

Hugues
Hugues

Reputation: 164

Yes you can , but you need an authorization process involving the user which is quite painful.

You'll need to use the right API.

Source: https://developer.spotify.com/web-api/console/playlists/

For example for adding a track, you'll need this end-point

https://api.spotify.com/v1/users/{user_id}/playlists/{playlist_id}/tracks

This codes works on AppleScript, just to prove the concept:

set userID to "XXXXX"
-- your userID can be retrieved with https://developer.spotify.com/web-api/console/get-current-user/#complete

set SelectedPlaylistID to "YYYY"
-- your target playlist can be retrieved with https://developer.spotify.com/web-api/console/get-playlists/#complete

set BearerID to "ZZZZ"
-- ZZZZ can be retrieved manually on page https://developer.spotify.com/web-api/console/post-playlist-tracks/ 

tell application "Spotify"
    set currentSpotifyID to id of current track as string
end tell
set currentlyPlayingTrack to trim_line(currentSpotifyID, "spotify:track:", 0)


set theURL to "'https://api.spotify.com/v1/users/" & userID & "/playlists/" & SelectedPlaylistID & "/tracks?uris=spotify%3Atrack%3A" & currentlyPlayingTrack & "' -H 'Accept: application/json' -H 'Authorization: Bearer " & BearerID & "'"
-- obtenu de https://developer.spotify.com/web-api/console/post-playlist-tracks/#complete

set theCommand to "curl -X POST " & theURL

do shell script theCommand

BUT there is a big caveat : you'll need to refresh the BearerID every hour.

Which is where the authorization process is needed, and where it becomes complicated if you want to bypass the refreshing limit.

Upvotes: 1

iKenndac
iKenndac

Reputation: 18776

Unfortunately, this isn't possible at this time without building a Spotify application either inside the client using the JS API or a standalone app using libSpotify.

Upvotes: 0

Related Questions