Rohan
Rohan

Reputation: 1352

Unable to delete a youtube playlist using youtube api v3

I am trying to delete a playlist that I have created but keep receiving a 404 error.
I have a global var playlistId to remember the playlistId that I have created.

var playlistId

I create the playlist like so :

function createPlaylist() {
  var request = gapi.client.youtube.playlists.insert({
    part: 'snippet,status',
    resource: {
      snippet: {
        title: 'hard coded title',
        description: 'Hard Coded Description'
      },
      status: {
        privacyStatus: 'private'
      }
    }
  });

  request.execute(function(response) {
    var result = response.result;
    if (result) {
      playlistId = result.id;
      console.log("created playlist " + playlistId)
    } 
  });
}

Then I delete a playlist like so :

function deletePlaylist() {
  var request = gapi.client.youtube.playlistItems.delete({
    id: playlistId
  }).execute();
}

404 Error that I receive is :

{
 "error": {
  "errors": [
   {
    "domain": "youtube.playlistItem",
    "reason": "playlistItemNotFound",
    "message": "Playlist item not found.",
    "locationType": "parameter",
    "location": "id"
   }
  ],
  "code": 404,
  "message": "Playlist item not found."
 }
}

I am giving the playlistId of the PlayList that I have created yet the playlist can not be deleted. Can anyone give some guidance?

Upvotes: 1

Views: 401

Answers (1)

topynate
topynate

Reputation: 377

deletePlaylist appears to be attempting to delete a PlaylistItem (i.e. a video) rather than a Playlist itself. Could you try replacing playlistItems with playlists?

Upvotes: 2

Related Questions