I had a Google Apps Script code bound to a Google Spreadsheet that created a PDF file from one of its sheets using the urlfetchapp.fetch(url, options) function. Yesterday, without editing the code, it suddenly stopped working, showing the error "urlfetchapp.fetch are not permitted".
I checked other spreadsheet bound code I made for other Spreadsheet and it is not working anymore either, same error.
For context, I am using Google Workspace for my company, and dealing with sensitive data. But it was working just fine up until yesterday.
function CrearPDFysubirloalDrive(){
var Ss = SpreadsheetApp.getActiveSpreadsheet();
var Sheet= Ss.getSheetByName("Name")
var Longitud = Sheet.getLastRow();
var range = Sheet.getRange(1,1,Longitud,10);
var docId ="Planning";
var docId1Semana = Sheet.getRange('F5').getValue();
var docIdRevision = Sheet.getRange('C7').getValue();
var pdfname= docId+ " W"+docId1Semana+"-Rev "+docIdRevision;
//This is not important to the question
var tempst= Sheet.copyTo(Ss).setName(pdfname);
tempst.insertColumns(1);
tempst.setRowHeight(1,30)
tempst.setColumnWidth(1, 20);
tempst.setColumnWidth(12, 30);
tempst.deleteColumns(13,tempst.getMaxColumns()-12)
//tempst.deleteRows(Longitud+2, (tempst.getMaxRows()- (Longitud+2)))
tempst.getRange("A4:A5").setBackground("white");
var drawing = tempst.getDrawings();
for (let i=0; i<drawing.length;i++){
drawing[i].remove();
}
SpreadsheetApp.flush();
//THIS PART IS GIVING THE ERROR
var url = 'https://docs.google.com/spreadsheets/d/{ID}/export?'.replace('{ID}', Ss.getId());
var exportOptions = 'exportFormat=pdf&format=pdf' + // export as pdf / csv / xls / xlsx
'&size=letter' + // paper size legal / letter / A4
'&portrait=true' + // orientation, false for landscape
'&fitw=true&source=labnol' + // fit to page width, false for actual size
'&sheetnames=false&printtitle=false' + // hide optional headers and footers
'&pagenumbers=false&gridlines=false' + // hide page numbers and gridlines
'&fzr=false' + // do not repeat row headers (frozen rows) on each page
'&top_margin=0.40' + //All four margins must be set!
'&bottom_margin=0.00' + //All four margins must be set!
'&left_margin=0.40' + //All four margins must be set!
'&right_margin=0.40' + //All four margins must be set!
'&gridlines=false' + //true/false
'&gid=' + tempst.getSheetId(); // the sheet's Id
var token = ScriptApp.getOAuthToken();
var blob = UrlFetchApp.fetch(url + exportOptions, {
headers: {
Authorization: 'Bearer '+token
}
}).getBlob().setName(tempst.getName()+".pdf");
var pdfFile = DriveApp.createFile(blob);
var FolderDestino= DriveApp.getFolderById(<FOLDERID>);
FolderDestino.createFile(blob.setName(pdfname))
I am not an expert at coding by any means, but I suspect it is related to the Oauth token. Either that or the function has been deprecated.
EXACT ERROR CODE: Exception: UrlFetch calls to https://docs.google.com/spreadsheets/d/*******/export?exportFormat=pdf&format=pdf&size=letter&portrait=true&fitw=true&source=labnol&sheetnames=false&printtitle=false&pagenumbers=false&gridlines=false&fzr=false&top_margin=0.40&bottom_margin=0.00&left_margin=0.40&right_margin=0.40&gridlines=false&gid=2141838874 are not permitted.
Any help? Thank you in advance