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);
I was unable to find user3586062's source links (they may have been deleted), but taking Bruce Mcpherson's approach, your code would look like this:
var options = {};
options.headers = {"Authorization": "Basic " + Utilities.base64Encode(username + ":" + password)};
UrlFetchApp.fetch("TARGET URL GOES HERE", options);