title: Unhandled rejection error: StatusCodeError: 401 (Unauthorized: Access is denied due to invalid credentials)
body: <p>This page shows JSON inside plain empty html/body tags. For example:</p>
  
  <pre><code>&lt;html&gt;
    &lt;body&gt;
      **JSON DATA ***
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I can access that page fine doing it normally within a browser. But, when I send a request it says that my credentials are invalid (The response error is pretty much in the title).
  And here is the code</p>
  
  <pre><code>import dotenv = require('dotenv');
  dotenv.config({ path: '../logins.env' });
  import rp = require('request-promise');
  const jsonUrl = `http://availability.emodal.com/ImportAvailability/GetContainerInfoList?sgrdModel=%7B%22searchtext%22:%22%22,%22page%22:1,%22pageSize%22:280,%22sortBy%22:%221%22,%22sortDirection%22:%22asc%22,%22sortColumns%22:%22%22%7D`;
  
  const authOpts = {
    uri: jsonUrl,
    auth: {
      user: process.env.EMODAL_id,
      pass: process.env.EMODAL_pw,
      sendImmediately: false
    },
    method: 'get'
  }
  
  rp(authOpts)
  .then(resp =&gt; {
    console.log(resp);
  }).catch(err =&gt; { throw Error(err)});
  </code></pre>
  
  <p>I tried changing everything around. Like adding headers, or putting json: true, or changing sendImmediately to true. Nothing works. What am I not understanding or what am I doing wrong?</p>
  
  <p>Here is an image showing the error in terminal:
  <a href="https://i.stack.imgur.com/5dJON.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5dJON.png" alt="enter image description here"></a></p>
  
  <p>Thank you</p>