I'm trying to send a request like in the documentation, but it returns me a response: Invalid parameters - Your request is missing a required parameter
async function unlove_track(track_name,artist) {
let body = {
track: track_name,
artist: artist,
api_key: 'api_key',
api_sig: 'api_sig',
sk: 'sk',
method: 'track.unlove'
}
let response = await fetch(`http://ws.audioscrobbler.com/2.0/`, {
method: 'POST',
body: JSON.stringify(body),
headers: {'User-Agent': '--------'}
});
response.json().then(res => {console.log(res)})
}
The documentation doesn't make explicit mention of it, but if you look at the API clients they link to (e.g. this PHP one) you can see that the request body is expected to be formatted as
application/x-www-form-urlencodedand not the JSON you are using.Use URLSearchParams to generate your data in that format.
Don't forget to include the
Content-Typerequest header.