How to use UrlFetchApp with credentials? Google Scripts

This question has been answered on another else where.
Here is the summary:

Bruce Mcpherson

basic authentication looks like this...
    var options = {};
    options.headers = {"Authorization": "Basic " + Utilities.base64Encode(username + ":" + password)};

Lenny Cunningham

//Added Basic Authorization//////////////////////////////////////////////////////////////////////////////////////////

  var USERNAME = PropertiesService.getScriptProperties().getProperty('username');
  var PASSWORD = PropertiesService.getScriptProperties().getProperty('password');

  var url = PropertiesService.getScriptProperties().getProperty('url');//////////////////////////Forwarded

Ports to WebRelay

  var headers = {
    "Authorization" : "Basic " + Utilities.base64Encode(USERNAME + ':' + PASSWORD)
  };

  var params = {
    "method":"GET",
    "headers":headers
  };

var reponse = UrlFetchApp.fetch(url, params);

Leave a Comment