title: How to create SAS token in Postman to use with Service bus?
body: <p>Base on this Microsoft documentation:
  <a href="https://docs.microsoft.com/en-us/rest/api/eventhub/generate-sas-token" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/rest/api/eventhub/generate-sas-token</a></p>
  <p>the code for nodejs is:</p>
  <pre><code>function createSharedAccessToken(uri, saName, saKey) { 
  if (!uri || !saName || !saKey) { 
          throw &quot;Missing required parameter&quot;; 
      } 
  var encoded = encodeURIComponent(uri); 
  var now = new Date(); 
  var week = 60*60*24*7;
  var ttl = Math.round(now.getTime() / 1000) + week;
  var signature = encoded + '\n' + ttl; 
  var signatureUTF8 = utf8.encode(signature); 
  var hash = crypto.createHmac('sha256', saKey).update(signatureUTF8).digest('base64'); 
  return 'SharedAccessSignature sr=' + encoded + '&amp;sig=' +  
      encodeURIComponent(hash) + '&amp;se=' + ttl + '&amp;skn=' + saName; 
   }
  </code></pre>
  <p>And I was trying it on Postman, in case anyone need help with it.  This is the code that works for me under the Pre-request Script using Postman</p>
  <pre><code>var namespace = pm.collectionVariables.get(&quot;serviceNamespace&quot;);
  var uri = &quot;https://&quot; + namespace + &quot;.servicebus.windows.net/adfTest/messages&quot;;
  var saName = pm.collectionVariables.get(&quot;SharedAccessKeyName&quot;);
  var saKey = pm.collectionVariables.get(&quot;SharedAccessKeySend&quot;);
  
  var sasToken = createSharedAccessToken(uri, saName, saKey);
  
  console.log(sasToken);
  pm.collectionVariables.set(&quot;SasToken&quot;, sasToken);
  
  function createSharedAccessToken(uri, saName, saKey) { 
      if (!uri || !saName || !saKey) { 
              throw &quot;Missing required parameter&quot;; 
          } 
      var encoded = encodeURIComponent(uri).toLowerCase(); 
      var now = new Date(); 
      var week = 60*60*24*7;
      var ttl = Math.round(now.getTime() / 1000) + week;
      var signature = encoded + '\n' + ttl;     
      var hash = CryptoJS.HmacSHA256(signature, saKey);
      var hashInBase64 = CryptoJS.enc.Base64.stringify(hash);
      return 'SharedAccessSignature sr=' + encoded + '&amp;sig=' +  
          encodeURIComponent(hashInBase64) + '&amp;se=' + ttl + '&amp;skn=' + saName; 
  }
  </code></pre>