0

I have a script below which export on a daily basis a sheet in CSV. This script was working very well until yesterday. I have now an error. Could you help me to understand why it is happening now?

function saveAsCSV() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var ssname = ss.getName();
var sheet = ss.getSheetByName("xxxx_sales_daily");
var folder = DriveApp.getFolderById("xxxxxxx");
var curDate = Utilities.formatDate(new Date(), "GMT-4", "ddMMyyyy");
var fileName = "XX_" + curDate + ".csv";
var url = "https://docs.google.com/spreadsheets/d/" + ss.getId() + "/export? 
exportFormat=csv&format=scsv";  
var token = ScriptApp.getOAuthToken();
var response = UrlFetchApp.fetch(url + sheet.getSheetId(), {
headers: {
  'Authorization': 'Bearer ' +  token
}
});
var csvData = Utilities.parseCsv(response.getBlob().getDataAsString());
var outputData = csvData.map(r => r.join("|")).join("\n");
folder.createFile(fileName, outputData, MimeType.PLAIN_TEXT);
}

The detail of the error says that it is coming from this line :

var response = UrlFetchApp.fetch(url + sheet.getSheetId(), {

Does Google change anything? Best regards J

Jean
  • 83
  • 3
  • 10
  • 1
    It is a new bug reported recently in particular for csv files. Put a start in the [issue tracker](https://issuetracker.google.com/issues/175141974) and see this [post](https://stackoverflow.com/questions/65233801/unexpected-error-on-urlfetchapp-fetch-in-google-apps-script-using-basic-authenti) which is a duplicate of your question. – Marios Dec 11 '20 at 17:37
  • 1
    Does this answer your question? [Unexpected error on UrlFetchApp.fetch in Google Apps Script using basic authentication](https://stackoverflow.com/questions/65233801/unexpected-error-on-urlfetchapp-fetch-in-google-apps-script-using-basic-authenti) – Iamblichus Dec 14 '20 at 09:48
  • yes thank you. i noticed that it is working now, from this morning – Jean Dec 15 '20 at 10:50

0 Answers0