title: How to set basic authorization from environment variable in postman?
body: <p>I want to set basic Authorization in Postman using environment variable. Because I have different authorization username and password for the different API calls.</p>
  
  <p>I set my postman according to below:</p>
  
  <p>In Authorization Tab: I've selected No Auth <br>
  In Header Tab: Key=<code>Authorization</code> Value= <code>Basic{{MyAuthorization}}</code> <br>
  In Body Tab:</p>
  
  <pre><code>{
      "UserName": "{{UserName}}",
      "ServiceUrl": "{{ServiceUrl}}"
  }
  
  //which set it from the envitonment variable
  </code></pre>
  
  <p>In Pre-request Tab:</p>
  
  <pre><code>// Require the crypto-js module
  var CryptoJS = require("crypto-js");
  
  // Parse the `username` and `password` environment variables
  let credsParsed = CryptoJS.enc.Utf8.parse(`${pm.environment.get('admin')}:${pm.environment.get('admin')}`);
  
  // Base64 encoded the parsed value
  let credsEncoded = CryptoJS.enc.Base64.stringify(credsParsed);
  
  // Set the valuse as an environment variable and use in the request
  pm.environment.set('MyAuthorization', credsEncoded);
  console.log(credsEncoded);
  </code></pre>
  
  <p>In Test Tab:</p>
  
  <pre><code>var jsonData = JSON.parse(responseBody);
  postman.setEnvironmentVariable("LoginInfoID", jsonData.First.LoginInfoID);
  </code></pre>
  
  <p>Then I've sent the request and got unauthorized. </p>
  
  <p>After that, I've set auth type to basic auth with username and password 
  it's working  fine and I got what I wanted from the response.</p>