thelinmichael / spotify-web-api-node

A Node.js wrapper for Spotify's Web API.
http://thelinmichael.github.io/spotify-web-api-node/
MIT License
3.11k stars 497 forks source link

Query params aren’t sent properly #85

Closed timseverien closed 8 years ago

timseverien commented 8 years ago
spotifyApi.getPlaylist(user, playlist, {
  offset: 5,
  limit: 10,
}).then((data) => console.log(data.body.tracks.next));

Current behaviour:

The above code logs the URL:

https://api.spotify.com/v1/users/{user}/playlists/{playlist}/tracks?offset=10&limit=10

Expected behaviour:

It should log following URL, confirmed via the Spotify Web API Console.

https://api.spotify.com/v1/users/{user}/playlists/{playlist}/tracks?offset=15&limit=10

Suggestion

Interestingly, the offset in the next URL appears to work. The offset parameter, however, seems to be ignored. I tried to find the issue myself, but no luck thus far.

My guess is that the offset parameter is accidentally omitted when an URL is generated.

JMPerez commented 8 years ago

@timseverien Thanks for a very well written bug report!

In your "Test code", I assume you are calling spotifyApi.getPlaylistTracks() and not spotifyApi.getPlaylist().

I have tried with a small example, same environment as yours, and I'm not able to reproduce the issue:

var spotifyApi = new SpotifyWebApi({
  clientId : '<something>',
  clientSecret : '<something>'
});

spotifyApi.clientCredentialsGrant()
  .then(function(data) {
    spotifyApi.setAccessToken(data.body['access_token']);
    return spotifyApi.getPlaylistTracks('jmperezperez', '6pasABEDetvB8I2vh9avye', {
      offset: 5,
      limit: 10
    });
  }).then(function(data) {
    console.log(data.body);
  }).catch(function(err) {
    console.log('Unfortunately, something has gone wrong.', err.message);
  });

When run, this is the output it generates:

{ href: 'https://api.spotify.com/v1/users/jmperezperez/playlists/6pasABEDetvB8I2vh9avye/tracks?offset=5&limit=10',
  items:
   [ { added_at: '2016-08-15T14:49:51Z',
       added_by: [Object],
       is_local: false,
       track: [Object] },
      ...
     { added_at: '2016-08-15T14:49:51Z',
       added_by: [Object],
       is_local: false,
       track: [Object] } ],
  limit: 10,
  next: 'https://api.spotify.com/v1/users/jmperezperez/playlists/6pasABEDetvB8I2vh9avye/tracks?offset=15&limit=10',
  offset: 5,
  previous: 'https://api.spotify.com/v1/users/jmperezperez/playlists/6pasABEDetvB8I2vh9avye/tracks?offset=0&limit=5',
  total: 25 }

The href, next and previous are correct. Would you mind double checking or providing a simple code snippet that we can run to try to find out what is happening?

JMPerez commented 8 years ago

I'm closing this issue for now since it doesn't seem to be a bug. Feel free to reopen it.