title: How to send bearer token and x-www-form-urlencoded data using Node Request
body: <p>I want to replicate this Postman call using the node module <a href="https://www.npmjs.com/package/request" rel="nofollow noreferrer">request</a>. See screenshots. </p>
  
  <p><a href="https://i.stack.imgur.com/0WMqQ.png" rel="nofollow noreferrer">Screenshot</a></p>
  
  <p><a href="https://i.stack.imgur.com/5GRT1.png" rel="nofollow noreferrer">Screenshot2</a></p>
  
  <p>As shown in screenshot, in my request, I need to pass a <code>bearer token</code> as well as <code>x-www-form-urlencoded</code> values. I tried following the top 2 answers from this <a href="https://stackoverflow.com/questions/17121846/node-js-how-to-send-headers-with-form-data-using-request-module">SO post</a> but with no success. </p>
  
  <p>I have basically tried doing</p>
  
  <pre><code>let form = {
      "field1": value1,
      "filed2": value2
  };
  
  let headers = {
      'Content-Type' : 'application/x-www-form-urlencoded',
      'Authorization': 'Bearer ' + token
  }
  
  request.post({ url: "https://myapp.net/myendpoint", form: form, headers: headers }, function(err, res, success){
      console.log(success);
  });
  </code></pre>
  
  <p>and also</p>
  
  <pre><code>let form = {
      "field1": value1,
      "field2": value2
  };
  
  var formData = querystring.stringify(form);
  
  let options = {
      uri: "https://myapp.net/myendpoint",
      method: 'POST',
      auth: {
          'bearer': token
      },
      headers: {
          'Content-Type' : 'application/x-www-form-urlencoded'
      },
      body: formData
  };
  
  
  request.post(options, function(err, res, success){
      console.log(success);
  });
  </code></pre>
  
  <p>Can someone please show the right way to do it?</p>
  
  <p><strong>EDIT</strong>:
  To clarify: the result of these requests is 400 status. I would get 400 on Postman as well if I was sending <code>form-data</code>, but if I send <code>x-www-form-urlencoded</code> then it would succeed in postman. I don't know how to do this in request.</p>