src/spotify-web-api.js
function(userId, playlistName, options, callback) {
    // In case someone is using a version where options parameter did not exist.
    var actualCallback;
    if (typeof options === 'function' && !callback) {
      actualCallback = options;
    } else {
      actualCallback = callback;
    }

    var actualOptions = { name: playlistName };
    if (typeof options === 'object') {
      Object.keys(options).forEach(function(key) {
        actualOptions[key] = options[key];
      });
    }

    return WebApiRequest.builder(this.getAccessToken())
      .withPath('/v1/users/' + encodeURIComponent(userId) + '/playlists')
      .withHeaders({ 'Content-Type': 'application/json' })
      .withBodyParameters(actualOptions)
      .build()
      .execute(HttpManager.post, actualCallback);
  }
function(userId, playlistName, options, callback) {
    // In case someone is using a version where options parameter did not exist.
    var actualCallback;
    if (typeof options === 'function' && !callback) {
      actualCallback = options;
    } else {
      actualCallback = callback;
    }

    var actualOptions = { name: playlistName };
    if (typeof options === 'object') {
      Object.keys(options).forEach(function(key) {
        actualOptions[key] = options[key];
      });
    }

    return WebApiRequest.builder(this.getAccessToken())
      .withPath('/v1/users/' + encodeURIComponent(userId) + '/playlists')
      .withHeaders({ 'Content-Type': 'application/json' })
      .withBodyParameters(actualOptions)
      .build()
      .execute(HttpManager.post, actualCallback);
  }
function ( userId , playlistName , options , callback ) { // In case someone is using a version where options parameter did not exist. var actualCallback ; if ( typeof options === 'function' && ! callback ) { actualCallback = options ; } else { actualCallback = callback ; } var actualOptions = { name : playlistName } ; if ( typeof options === 'object' ) { Object . keys ( options ) . forEach ( function ( key ) { actualOptions [ key ] = options [ key ] ; } ) ; } return WebApiRequest . builder ( this . getAccessToken ( ) ) . withPath ( '/v1/users/' + encodeURIComponent ( userId ) + '/playlists' ) . withHeaders ( { 'Content-Type' : 'application/json' } ) . withBodyParameters ( actualOptions ) . build ( ) . execute ( HttpManager . post , actualCallback ) ; }
Create a playlist.
@param {string} userId The playlist's owner's user ID.
@param {string} playlistName The name of the playlist.
@param {Object} [options] The possible options, currently only public.
@param {requestCallback} [callback] Optional callback method to be called instead of the promise.
@example createPlaylist('thelinmichael', 'My cool playlist!', { public : false }).then(...)
@returns {Promise|undefined} A promise that if successful, resolves to an object containing information about the
created playlist. If rejected, it contains an error object. Not returned if a callback is given.
Create a playlist .