title: How to get around a 401 unauthorized error?
body: <p>I'd like to output some values from <a href="https://asunnot.oikotie.fi/myytavat-asunnot?conditionType%5B%5D=1&amp;conditionType%5B%5D=2&amp;locations=%5B%5B1669,4,%22Lauttasaari,%20Helsinki%22%5D,%5B14714,5,%2200340,%20Helsinki%22%5D%5D&amp;lotOwnershipType%5B%5D=1&amp;price%5Bmax%5D=600000&amp;price%5Bmin%5D=150000&amp;size%5Bmin%5D=35&amp;roomCount%5B%5D=3&amp;cardType=100" rel="noreferrer">this site</a>. With the browser inspector I located the <a href="https://asunnot.oikotie.fi/api/cards?cardType=100&amp;conditionType%5B%5D=1&amp;conditionType%5B%5D=2&amp;limit=24&amp;locations=%5B%5B1669,4,%22Lauttasaari,%20Helsinki%22%5D,%5B14714,5,%2200340,%20Helsinki%22%5D%5D&amp;lotOwnershipType%5B%5D=1&amp;offset=0&amp;price%5Bmax%5D=600000&amp;price%5Bmin%5D=150000&amp;roomCount%5B%5D=3&amp;size%5Bmin%5D=35&amp;sortBy=published_sort_desc" rel="noreferrer">URL</a> to the JSON that has that information that I want. Once with the JSON, I can extract the values just fine.</p>
  
  <p>The issue is that the URL to the JSON only works for a limited amount of time. If I try to access it later (via browser or via script's UrlFetch), I get a:</p>
  
  <pre><code>{
  "status": 401,
  "response": "unauthorized"
  }
  </code></pre>
  
  <p>Since I would like to check on the target JSON periodically, I would like to find a way to authorize the request. Any ideas? </p>
  
  <p>Thanks!</p>
  
  <p>PS: This is what I've tried so far (google apps script):</p>
  
  <pre><code>function getUserAndJSON(){
    var url = 'https://asunnot.oikotie.fi/api/cards?cardType=100&amp;conditionType%5B%5D=1&amp;conditionType%5B%5D=2&amp;limit=24&amp;locations=%5B%5B1669,4,%22Lauttasaari,%20Helsinki%22%5D,%5B14714,5,%2200340,%20Helsinki%22%5D%5D&amp;lotOwnershipType%5B%5D=1&amp;offset=0&amp;price%5Bmax%5D=600000&amp;price%5Bmin%5D=150000&amp;roomCount%5B%5D=3&amp;size%5Bmin%5D=35&amp;sortBy=published_sort_desc';
  
    var opt = {
      "method": "GET", 
      "muteHttpExceptions": true,
      "escaping":false,
      "headers":JSON.parse(user)
    }
    var str = UrlFetchApp.fetch(url,opt).getContentText();
    Logger.log(str); //error 401
  }
  </code></pre>