title: Spotify API bad request on api/token authorization Error: 400
body: <p>I am trying to authorize spotify api requests using Client Credentials Flow on the Spotify API Docs page. Here is my code in javascript ES6 format using the fetch API</p>
  
  <pre><code>    const response = await fetch('https://accounts.spotify.com/api/token', {
      mode: 'no-cors',
      method: 'POST',
      headers: {
        'Authorization': 'Basic Yzg4OWYzMjM5MjI0NGM4MGIyMzIyOTI5ODQ2ZjZmZWQ6MmUzZTM2YTMzMTM5NDM1Mzk3NzM4ZDMxMTg4MzM0Mjc=',
        'Content-type': 'application/x-www-form-urlencoded'
        },
      body: 'grant_type=client_credentials'
  });
  </code></pre>
  
  <p>The console is saying it is a bad request and doesn't return any JSON.</p>
  
  <p>Another thing that really confuses me is that when I send the request using POSTMAN with those headers and that body, it returns exactly what I want (It works) I don't see how this is different from what I'm doing...? Could anyone please help?</p>
  
  <p>Also here is the code from postman in Javascript Jquery Ajax if this helpls:</p>
  
  <pre><code>var settings = {
    "async": true,
    "crossDomain": true,
    "url": "https://accounts.spotify.com/api/token",
    "method": "POST",
    "headers": {
      "Authorization": "Basic Yzg4OWYzMjM5MjI0NGM4MGIyMzIyOTI5ODQ2ZjZmZWQ6MmUzZTM2YTMzMTM5NDM1Mzk3NzM4ZDMxMTg4MzM0Mjc=",
      "Content-Type": "application/x-www-form-urlencoded",
      "Cache-Control": "no-cache",
      "Postman-Token": "2f93918d-2e8e-4fb0-a168-7e153dd83912"
    },
    "data": {
      "grant_type": "client_credentials"
    }
  }  
  
  $.ajax(settings).done(function (response) {
    console.log(response);
  });
  </code></pre>
  
  <p>This is what the request looks like in DevTools
  <a href="https://i.stack.imgur.com/B2IKJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B2IKJ.png" alt="enter image description here"></a></p>