Issue
I am trying to delete a song from a Spotify playlist using the Spotify API and it doesn't seem to be working. Below is a snippet of my code:
headers = {'Accept': 'application/json',
'Authorization' :'Bearer '+access,
'Content-Type': 'application/json'}
params={"tracks":
{"uri":
["spotify:track:2goLsvvODILDzeeiT4dAoR"]
}
}
remove=requests.delete("https://api.spotify.com/v1/playlists/55J330mslu8XwOUXef77Qw/tracks",headers=headers,params=params)
I get a 404 error with print(remove.json())
giving {'error': {'status': 400, 'message': 'Missing tracks'}}
and print(remove.url)
giveshttps://api.spotify.com/v1/playlists/55J330mslu8XwOUXef77Qw/tracks?tracks=uri
which seems to be incomplete for some reason.
The delete endpoint seems to be working from their online test console but they use curl and they had to escape the quotes in the params
array. I tried escaping the quotes in python and I get an error:
SyntaxError: unexpected character after line continuation character.
Below is an example that works but its from the Spotify examples that work with curl
curl -X "DELETE" "https://api.spotify.com/v1/playlists//tracks" --data "{\"tracks\":[{\"uri\":\"spotify:track:2DB2zVP1LVu6jjyrvqD44z\",\"positions\":[0]},{\"uri\":\"spotify:track:5ejwTEOCsaDEjvhZTcU6lg\",\"positions\":[1]}]}" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer BQDqsVD6LMUcgDXfe8F0gupyYlqjRbIqjuJKfzfoUBL5DvA22YS2tp0-ksyFmI0YDCHgc0WZN664vNc5ZwMjm3xvJV--BiTnwn7Oki6IDIRXeWjQsIK8iNkd8PASuY4zBUxk37F2aZv29_Kg23cvNmCi5aABb5gVO2OjpjQhGwMr16Clie4qymoYoXH7PB9J3-ShZ8DzWG1y5r0GETwgi9Jj0q3A3B7KY3Xw6VnERIfQSXRw8SdkpdSpSMfPKBt4utCPXIOt2198Kw"
Any way to get this working?
Solution
Just got this working. For anyone having trouble translation curl to python code there's this conversion website https://curl.trillworks.com
My code ended up as follows and everything works now:
params='{"tracks":[{"uri":"spotify:track:1snNAXmmPXCn0dkF9DaPWw"}]}'
remove=requests.delete("https://api.spotify.com/v1/playlists/55J330mslu8XwOUXef77Qw/tracks",headers=headers,data=params)
Answered By - West Answer Checked By - Mildred Charles (WPSolving Admin)