title: How to get access token for an API by using POST method in JavaScript?
body: <p>The API  I want to get credentials for uses OAuth2.
  The documentation for the API has this listed:</p>
  <pre><code>Request access token:
  
  POST: auth/access_token
  
  Url Parms:
  grant_type    : &quot;client_credentials&quot;
  client_id     :  Client id
  client_secret :  Client secret
  </code></pre>
  <p>What I figured from this is that I need to send a JSON object as a string so I tried this in JavaScript.</p>
  <pre><code>var xhr = new XMLHttpRequest();
      xhr.open(&quot;POST&quot;,&quot;url for the api&quot;,false);
      
      var obj = {
         
         &quot;POST&quot;: &quot;auth/access_token&quot;,
         &quot;Url Parms&quot;: [   
            {
               &quot;grant_type&quot;:'\&quot;client_credentials\&quot;',
               &quot;client_id&quot;: &quot;My Client id&quot;,
               &quot;client_secret&quot;: &quot;My Client secret&quot;
            }
         ]
      };
      
      var clientcred = JSON.stringify(obj);
      xhr.send(obj);
  </code></pre>
  <p>All this gave me was a JSON which said I made an error.</p>
  <pre><code>{&quot;error&quot;:&quot;invalid_request&quot;,&quot;error_description&quot;:&quot;The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the \&quot;grant_type\&quot; parameter.&quot;}
  </code></pre>
  <p>The code actually doesn't even work because of 'same-origin policy'. I used an extension to get around that. But I am so done. I can't figure it out. Do I need to learn something like php? How do I get my access token.</p>
  <p>Edit:</p>
  <blockquote>
  <p>It might need the parameters in the URL, so POST auth/access_token?grant_type=client_credentials&amp;client_id=id‌​&amp;client_secret=clien‌​t_secret or possibly POST auth/access_token/client_credentials/id/client_secret – Sara Tibbetts 8 hours ago</p>
  </blockquote>
  <p>This did it. I woke up and the first thing I tried and it worked. Thank you so much @Sara Tibbetts and everyone else who tried to help me.</p>
  <p>Edit 2:</p>
  <blockquote>
  <p>The extension was a poor workaround, since then I have learned about Cross Origin Resource Sharing. I should've made my API call from the server rather than doing it client side, which is actually secure as well.</p>
  </blockquote>