I want to access the Spotify web API using the "Client Credentials Flow" as mentioned here. I tried to access it using some tutorial mention here, but couldn't follow it because it uses the request library in node which has now been deprecated so, I tried using axios in it's place and keep getting the Status Code 415 error in the browser console. I'm trying to create a side project using this API for practice because I'm a beginner. I've done this using NodeJS and the normal browser console(i have used the code for browser console here) and i had axios and express libraries installed(while using node).
const client_id = '**redacted**';
const client_secret = '**redacted**';
const res = axios.post('https://accounts.spotify.com/api/token', {
headers: {
'Authorization': 'Basic ' + btoa(`${client_id}` + ':' + `${client_secret}`),
},
form: {
grant_type: 'client_credentials'
}
});
console.log(res)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AXIOS DOC</title>
</head>
<body>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="script2.js"></script>
</body>
</html>