title: Can not insert multiple videos into a playlist - YouTube API v3
body: <p>I am trying to add multiple videos to a playlist, but only one video is added to the playlist. I can successful create a playlist and insert a video to the playlist, but can not insert multiple videos to the playlist.</p>
  
  <p>Below is a simple way that I am doing this. The function addTheseVideosToPlaylist() is specifically where I am failing. createPlaylist() and addToPlaylist() are also shown.</p>
  
  <p>There is a global playlistId to keep track of created playlist.</p>
  
  <pre><code>var playlistId
  </code></pre>
  
  <p>I create a playlist like this:</p>
  
  <pre><code>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)
          }
      });
  }
  </code></pre>
  
  <p>I add a video to the created playlist given a valid video id like below:</p>
  
  <pre><code>function addToPlaylist(id, startPos, endPos) {
      console.log("In addToPlaylist with " + id  +
                  "sending to playlist : " + playlistId);
  
      var details = {
          videoId: id,
          kind: 'youtube#video'
      }
  
      var request = gapi.client.youtube.playlistItems.insert({
          part: 'snippet',
          resource: {
              snippet: {
                  playlistId: playlistId,
                  resourceId: details
              }
          }
      }).execute();
  }
  </code></pre>
  
  <p>The two above functions are fairly standard and work fine. However I have problems when adding multiple videos to a playlist like below in addTheseVideosToPlaylist(). I have an array of valid video ids and for each id, I will add it to the created playlist. The problem is that not all of the videos are added to the playlist, only one video is added.</p>
  
  <pre><code>function addTheseVideosToPlaylist() {
      var links = [
          "wtLJPvx7-ys",
          "K3meJyiYWFw",
          "3TtVsy98ces"
      ]
      for(i = 0; i &lt; links.length; i++)
          addToPlaylist(links[i]);
  }
  </code></pre>
  
  <p>All in all, I am successful in creating a playlist and adding a video to the playlist, but when I try to insert multiple videos to a playlist by adding each link in an array, the playlist only contains one video.</p>
  
  <p>How can I resolve this problem?</p>