2 years ago

#62330

test-img

Richard Hearn

How to get CSV file from URL with basic Auth using App Script?

I want to know if I'm missing something. I am using google's sample code from their Documentation:

  var username = "myUserName";
  var password = "myPsw";
  var url = "http://myurl.com/ReportServer?/ExternalData/SCCOfficeHuddleCount&rs:Format=CSV";
  
  var authHeader = 'Basic ' + Utilities.base64Encode(username + ':' + password);
  var options = {
    headers: {Authorization: authHeader}
  }

  var response = UrlFetchApp.fetch(url, options);

but still getting 401 - unauthorized. I don't know if I'm missing something.

I already validate that the URL is working. If I paste this URL below in the browser directly

http://user:psw@myurl.com/ReportServer?/ExternalData/SCCOfficeHuddleCount&rs:Format=CSV

I get the CSV file. So how can I do this using AppScript?

google-apps-script

google-sheets

basic-authentication

http-status-code-401

urlfetch

0 Answers

Your Answer

Accepted video resources