Skip to content

Instantly share code, notes, and snippets.

@leemartin
Last active December 8, 2018 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leemartin/7d032685636165d517ec0f21da6163ca to your computer and use it in GitHub Desktop.
Save leemartin/7d032685636165d517ec0f21da6163ca to your computer and use it in GitHub Desktop.
Create Spotify Playlist with Artwork
// initialize axios instance
let spotify = axios.create({
baseURL: 'https://api.spotify.com',
headers: {
'Authorization': `Bearer ${token}`
}
})
// get user id for playlist creation
spotify.get('/v1/me').then(res => {
let userId = res.data.id
// create playlist
spotify.post(`/v1/users/${res.data.id}/playlists`, {
name: "Chris Cornell at City Park on Oct 28, 2011"
}).then(res => {
let playlistId = res.data.id
// add tracks to playlist
spotify.post(`/v1/playlists/${playlistId}/tracks?uris=${ids}`).then(res => {
// add artwork to playlist
spotify.put(`/v1/playlists/${playlistId}/images`, canvas.toDataURL('image/jpeg').replace('data:image/jpeg;base64,', ''), {
headers: {
'Content-Type': 'image/jpeg'
},
})
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment