Reputation: 2136
I'm attempting to use the Discogs API to fetch some titles via Node.js and the node-fetch
package. I've attached an example below. I suspect that I'm not setting up authorization right. I know that for some actions I need to do a full Oauth login flow, but should not be necessary for simply searching titles.
Also, I've set up the same call in Postman where I am succesfully able to make the call. I've attached a link to a screenshot below for reference.
Any idea what I'm doing wrong here?
const fetch = require('node-fetch');
const config = require('./config.json');
const search = (query, type = 'q') => {
fetch(`${config.apiUrl}/database/search/?${type}=${query}`,
{
method: "GET",
headers: {
"Authorization": "Discogs key=MY_API_KEY, secret=MY_API_SECRET"
}
}
)
.catch(err => console.error(err))
.then(res => console.log(res));
}
search('nirvana');
Upvotes: 2
Views: 703
Reputation: 2136
Discovered that I had forgotten to set the content-type header. Setting "Content-Type": "application/json"
resolved the problem.
Upvotes: 2
Reputation: 1279
You have a slash in your url from your code search/?...
try with this :
fetch(`${config.apiUrl}/database/search?${type}=${query}`
Upvotes: 1