Search code examples
javascriptdeezer

Delete deezer playlist using javascript


The way I'm trying to perform this action is like this:

var postPlaylistAjax = $.ajax({
    type: 'delete',
    url: 'http://api.deezer.com/user/me/playlists?request_method=delete&
        access_token='+
        encodeURIComponent(deezerAccessToken)+'&playlist_id=' +
        encodeURIComponent(playlistId) + '&output=jsonp',
    dataType: 'jsonp',
    success: function() {
        alert('Deleted');
    },
    error: ajaxError,
});

(When I try it in web the result is true but it doesn't delete the playlist).

Since the API description for deleting a playlist is the following

request_method = delete

https://api.deezer.com/playlist/{playlist_id}

I'm getting trouble to execute it in javascript


Solution

  • solved it:

      function deleteDeezerPlaylist(playlistId) {
                    var postPlaylistAjax = $.ajax({
                        type: 'post',
                        url: 'http://api.deezer.com/playlist/'+encodeURIComponent(playlistId)+'?request_method=DELETE&access_token='+encodeURIComponent(deezerAccessToken)+'&output=jsonp',
                        dataType: 'jsonp',
                        error: ajaxError,
                    });
                    return postPlaylistAjax.then(function (response) {
                        return response.id;
                    });
                }