Clay Schnars
Clay Schnars

Reputation: 91

Spotify API Error Code 400 - No Search Query

I am trying to use the Spotify API search function to recieve album data. This my request:

request.post(authOptions, function(error, response, body) {
if (!error && response.statusCode === 200) {

// use the access token to access the Spotify Web API
var token = body.access_token;
var options = {
    url: 'https://api.spotify.com/v1/search',
    data: {
      q: 'currents',
      type: 'album',
    },
    headers: {
      'Authorization': 'Bearer ' + token
    },
    json: true
  };

request.get(options, function(error, response, body) {
  console.log(body);
  });
}
});

However, when this code executes I continually get an Error Code 400 - "no search query" response. Can anyone help spot why this my query options are not being properly read?

Thanks.

Upvotes: 1

Views: 1471

Answers (1)

Clay Schnars
Clay Schnars

Reputation: 91

Solved: The request library requires a querystring object called qs in the options object. Changing "data" to "qs" fixed it.

Upvotes: 3

Related Questions