0

I have an Google Apps Script that runs scheduled to export a spreadsheet as PDF and send it by email. It worked well until some days ago, when it failed with the next error code at the moment of the URL request:

Error en la solicitud para el código devuelto 404 de https://docs.google.com/spreadsheets/d/SPREADSHEET_ID/export?exportFormat=pdf&format=pdf&size=letter&portrait=false&fitw=true&source=labnol&sheetnames=false&printtitle=false&pagenumbers=false&gridlines=false&fzr=false&gid=806009643. Truncated server response ....... etc

It worked pretty well some days ago. Actually, if you take the complete URL and open it in your brwoser, you download the PDF pretty well. But triying to recover it with URLFetchApp as in the code below it fails...

    var response = UrlFetchApp.fetch(url + url_ext + ss.getSheetByName("All Languages Charts II").getSheetId(), {
  headers: {
    'Authorization': 'Bearer ' +  token,
     }
  });

//convert the response to a blob
blob = response.getBlob();

Any hints, tips, or solutions?

Thanks!

Alex Snsk
  • 63
  • 1
  • 4
  • I cannot, as you suggest, download the PDF pretty well by copying+pasting the URL you supply. I see that the url reads `...spreadsheets/d/SPREADSHEET_ID/...`. Instead of reading `SPREADSHEET_ID`, you would want an actual file ID there. I'm guessing that the file was either deleted from your drive or your code was altered so that it wrote the string `SPREADSHEET_ID` instead of the actual file ID. – Eric Dauenhauer Dec 01 '15 at 18:49
  • I replaced the actual spreadsheet id for "SPREADSHEET_ID" beacuse it's a private file, and anyone would have permissions to download it. It was an example. – Alex Snsk Dec 02 '15 at 12:26

1 Answers1

0

I experienced the exact same problem. Look at this thread, it solved the issue: UrlFetch getting 404 error from spreadsheet URL

I just put this function in the same module/script file and I was prompted to authorize - then it worked.

function forAuth_() {
DriveApp.getFileById("Just for authorization"); //https://code.google.com/p/google-apps-script-issues/issues/detail?id=3579#c36
}
Community
  • 1
  • 1
Jazzpa
  • 1
  • 2