Skip to content

Commit 1f6fa39

Browse files
adamgriegerJMPerez
authored andcommitted
Update createPlaylist to use the new endpoint route. Fixes #124. (#125)
1 parent 120e85a commit 1f6fa39

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

__test__/spotify-web-api.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,11 +468,11 @@ describe('Basic tests', function() {
468468
var callback = sinon.spy();
469469
var api = new SpotifyWebApi();
470470
api.setAccessToken('<example_access_token>');
471-
api.createPlaylist({ name: 'A name for the playlist' }, callback);
471+
api.createPlaylist('a_user', { name: 'A name for the playlist' }, callback);
472472
that.requests[0].respond(200, { 'Content-Type': 'application/json' }, JSON.stringify(fixtures.user_new_playlist));
473473
expect(callback.calledWith(null, fixtures.user_new_playlist)).toBeTruthy();
474474
expect(that.requests.length).toBe(1);
475-
expect(that.requests[0].url).toBe('https://api.spotify.com/v1/me/playlists');
475+
expect(that.requests[0].url).toBe('https://api.spotify.com/v1/users/a_user/playlists');
476476
});
477477

478478
it("should update a playlist's details", function() {

src/spotify-web-api.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,14 +732,16 @@ var SpotifyWebApi = (function() {
732732
* See [Create a Playlist](https://developer.spotify.com/web-api/create-playlist/) on
733733
* the Spotify Developer site for more information about the endpoint.
734734
*
735+
* @param {string} userId The id of the user. If you know the Spotify URI it is easy
736+
* to find the id (e.g. spotify:user:<here_is_the_id>)
735737
* @param {Object} options A JSON object with options that can be passed
736738
* @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first
737739
* one is the error object (null if no error), and the second is the value if the request succeeded.
738740
* @return {Object} Null if a callback is provided, a `Promise` object otherwise
739741
*/
740-
Constr.prototype.createPlaylist = function(options, callback) {
742+
Constr.prototype.createPlaylist = function(userId, options, callback) {
741743
var requestData = {
742-
url: _baseUri + '/me/playlists',
744+
url: _baseUri + '/users/' + encodeURIComponent(userId) + '/playlists',
743745
type: 'POST',
744746
postData: options
745747
};

src/typings/spotify-web-api.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,14 @@ declare namespace SpotifyWebApi {
415415
* See [Create a Playlist](https://developer.spotify.com/web-api/create-playlist/) on
416416
* the Spotify Developer site for more information about the endpoint.
417417
*
418+
* @param {string} userId The id of the user. If you know the Spotify URI it is easy
419+
* to find the id (e.g. spotify:user:<here_is_the_id>)
418420
* @param {Object} options A JSON object with options that can be passed
419421
* @param {function(Object,Object)} callback An optional callback that receives 2 parameters. The first
420422
* one is the error object (null if no error), and the second is the value if the request succeeded.
421423
* @return {Object} Null if a callback is provided, a `Promise` object otherwise
422424
*/
423-
createPlaylist(options?: Object, callback?: ResultsCallback<SpotifyApi.CreatePlaylistResponse>) : Promise<SpotifyApi.CreatePlaylistResponse>;
425+
createPlaylist(userId: string, options?: Object, callback?: ResultsCallback<SpotifyApi.CreatePlaylistResponse>) : Promise<SpotifyApi.CreatePlaylistResponse>;
424426

425427
/**
426428
* Change a playlist's name and public/private state

0 commit comments

Comments
 (0)